[x265] [PATCH] Add frame count support for y4m input (for vspipe)

Xinyue Lu maillist at 7086.in
Thu Jan 7 19:45:56 CET 2016


# HG changeset patch
# User Xinyue Lu <i at 7086.in>
# Date 1451968700 14400
#      Mon Jan 04 23:38:20 2016
# Parent  b3394ea738b5b061439b21f34d920438571acae9
Add frame count support for y4m input

diff -r b3394ea738b5 source/input/y4m.cpp
--- a/source/input/y4m.cpp Sun Oct 04 04:30:00 2015 -0400
+++ b/source/input/y4m.cpp Mon Jan 04 23:38:20 2016 -0500
@@ -40,6 +40,7 @@
 using namespace std;

 static const char header[] = "FRAME";
+static const char magic_xlength[] = "LENGTH=";

 Y4MInput::Y4MInput(InputFileInfo& info)
 {
@@ -56,6 +57,7 @@
     rateDenom = info.fpsDenom;
     depth = info.depth;
     framesize = 0;
+    frameCount = -1;

     ifs = NULL;
     if (!strcmp(info.filename, "-"))
@@ -105,7 +107,7 @@
     info.fpsDenom = rateDenom;
     info.csp = colorSpace;
     info.depth = depth;
-    info.frameCount = -1;
+    info.frameCount = frameCount;

     size_t estFrameSize = framesize + strlen(header) + 1; /* assume
basic FRAME\n headers */

@@ -174,6 +176,8 @@
     int csp = 0;
     int d = 0;

+    uint32_t match_length = 0;
+
     while (ifs->good())
     {
         // Skip Y4MPEG string
@@ -188,27 +192,12 @@
             {
             case 'W':
                 width = 0;
-                while (ifs->good())
-                {
-                    c = ifs->get();
-
-                    if (c == ' ' || c == '\n')
-                        break;
-                    else
-                        width = width * 10 + (c - '0');
-                }
+                c = readNumber(width);
                 break;

             case 'H':
                 height = 0;
-                while (ifs->good())
-                {
-                    c = ifs->get();
-                    if (c == ' ' || c == '\n')
-                        break;
-                    else
-                        height = height * 10 + (c - '0');
-                }
+                c = readNumber(height);
                 break;

             case 'F':
@@ -251,26 +240,9 @@
                 break;

             case 'A':
-                sarWidth = 0;
-                sarHeight = 0;
-                while (ifs->good())
-                {
-                    c = ifs->get();
-                    if (c == ':')
-                    {
-                        while (ifs->good())
-                        {
-                            c = ifs->get();
-                            if (c == ' ' || c == '\n')
-                                break;
-                            else
-                                sarHeight = sarHeight * 10 + (c - '0');
-                        }
-                        break;
-                    }
-                    else
-                        sarWidth = sarWidth * 10 + (c - '0');
-                }
+                sarWidth = sarHeight = 0;
+                c = readNumber(sarWidth);
+                c = readNumber(sarHeight);
                 break;

             case 'C':
@@ -305,6 +277,34 @@
                 colorSpace = (csp == 444) ? X265_CSP_I444 : (csp ==
422) ? X265_CSP_I422 : X265_CSP_I420;
                 break;

+            case 'X':
+                // XLENGTH=xxxxx
+                for (match_length = 0; match_length <
strlen(magic_xlength); match_length++)
+                {
+                    if ((c = ifs->get()) != magic_xlength[match_length])
+                        break;
+                }
+                if (match_length == strlen(magic_xlength))
+                {
+                    // Yes this is what we want
+                    c = readNumber(frameCount);
+                    if (frameCount <= 0)
+                        frameCount = -1;
+                }
+                else
+                {
+                    // Clean up rest of the string
+                    if (c == ' ' || c == '\n')
+                        break;
+                    while (ifs->good())
+                    {
+                        c = ifs->get();
+                        if (c == ' ' || c == '\n')
+                            break;
+                    }
+                }
+                break;
+
             default:
                 while (ifs->good())
                 {
@@ -431,3 +431,19 @@
         return false;
 }

+template <typename T>
+int Y4MInput::readNumber(T &out)
+{
+    int c = -1;
+    out = 0;
+    while (ifs->good())
+    {
+        c = ifs->get();
+
+        if (c >= '0' && c <= '9')
+            out = out * 10 + (c - '0');
+        else
+            break;
+    }
+    return c;
+}
diff -r b3394ea738b5 source/input/y4m.h
--- a/source/input/y4m.h Sun Oct 04 04:30:00 2015 -0400
+++ b/source/input/y4m.h Mon Jan 04 23:38:20 2016 -0500
@@ -55,6 +55,8 @@

     int colorSpace;

+    int frameCount;
+
     bool threadActive;

     ThreadSafeInteger readCount;
@@ -92,6 +94,9 @@
     int getWidth() const                          { return width; }

     int getHeight() const                         { return height; }
+
+    template <typename T>
+    int readNumber(T &out);
 };
 }


More information about the x265-devel mailing list