]> granicus.if.org Git - libvpx/commitdiff
ivfdec: support y4m output from raw input
authorJohn Koleszar <jkoleszar@google.com>
Wed, 20 Oct 2010 14:49:12 +0000 (10:49 -0400)
committerJohn Koleszar <jkoleszar@google.com>
Tue, 26 Oct 2010 02:02:33 +0000 (22:02 -0400)
The width and height needed to write the Y4M header can be found by
probing the stream with vpx_codec_peek_stream_info(). This also
has the consequence of supporting multiple codecs from raw files
with automatic detections, should we add additional codecs in the
future.

Change-Id: I7522a8f4c7577b6ed9876d744c59cd86d30c6049

ivfdec.c

index d7ab4171b0aae068c26045551c2a5b17a44b9e31..c2822904f2b11d79d2e222baf40c64bf318cdc82 100644 (file)
--- a/ivfdec.c
+++ b/ivfdec.c
@@ -398,6 +398,41 @@ unsigned int file_is_ivf(FILE *infile,
 }
 
 
+unsigned int file_is_raw(FILE *infile,
+                         unsigned int *fourcc,
+                         unsigned int *width,
+                         unsigned int *height,
+                         unsigned int *fps_den,
+                         unsigned int *fps_num)
+{
+    unsigned char buf[32];
+    int is_raw = 0;
+    vpx_codec_stream_info_t si;
+
+    if (fread(buf, 1, 32, infile) == 32)
+    {
+        int i;
+
+        if(mem_get_le32(buf) < 256 * 1024 * 1024)
+            for (i = 0; i < sizeof(ifaces) / sizeof(ifaces[0]); i++)
+                if(!vpx_codec_peek_stream_info(ifaces[i].iface,
+                                               buf + 4, 32 - 4, &si))
+                {
+                    is_raw = 1;
+                    *fourcc = ifaces[i].fourcc;
+                    *width = si.w;
+                    *height = si.h;
+                    *fps_num = 30;
+                    *fps_den = 1;
+                    break;
+                }
+    }
+
+    rewind(infile);
+    return is_raw;
+}
+
+
 static int
 nestegg_read_cb(void *buffer, size_t length, void *userdata)
 {
@@ -686,53 +721,50 @@ int main(int argc, const char **argv_)
     if(file_is_ivf(infile, &fourcc, &width, &height, &fps_den,
                    &fps_num))
         input.kind = IVF_FILE;
-    else if(file_is_webm(&input, &fourcc, &width, &height, &fps_den,                                 &fps_num))
+    else if(file_is_webm(&input, &fourcc, &width, &height, &fps_den, &fps_num))
         input.kind = WEBM_FILE;
-    else
+    else if(file_is_raw(infile, &fourcc, &width, &height, &fps_den, &fps_num))
         input.kind = RAW_FILE;
+    else
+    {
+        fprintf(stderr, "Unrecognized input file type.\n");
+        return EXIT_FAILURE;
+    }
 
-    if (input.kind != RAW_FILE)
+    if (use_y4m)
     {
-        if (use_y4m)
+        char buffer[128];
+        if (!fn2)
         {
-            char buffer[128];
-            if (!fn2)
-            {
-                fprintf(stderr, "YUV4MPEG2 output only supported with -o.\n");
-                return EXIT_FAILURE;
-            }
+            fprintf(stderr, "YUV4MPEG2 output only supported with -o.\n");
+            return EXIT_FAILURE;
+        }
 
-            if(input.kind == WEBM_FILE)
-                webm_guess_framerate(&input, &fps_den, &fps_num);
+        if(input.kind == WEBM_FILE)
+            webm_guess_framerate(&input, &fps_den, &fps_num);
 
-            /*Note: We can't output an aspect ratio here because IVF doesn't
-               store one, and neither does VP8.
-              That will have to wait until these tools support WebM natively.*/
-            sprintf(buffer, "YUV4MPEG2 C%s W%u H%u F%u:%u I%c\n",
-                    "420jpeg", width, height, fps_num, fps_den, 'p');
-            out_put(out, (unsigned char *)buffer, strlen(buffer), do_md5);
-        }
+        /*Note: We can't output an aspect ratio here because IVF doesn't
+           store one, and neither does VP8.
+          That will have to wait until these tools support WebM natively.*/
+        sprintf(buffer, "YUV4MPEG2 C%s W%u H%u F%u:%u I%c\n",
+                "420jpeg", width, height, fps_num, fps_den, 'p');
+        out_put(out, (unsigned char *)buffer, strlen(buffer), do_md5);
+    }
 
-        /* Try to determine the codec from the fourcc. */
-        for (i = 0; i < sizeof(ifaces) / sizeof(ifaces[0]); i++)
-            if ((fourcc & ifaces[i].fourcc_mask) == ifaces[i].fourcc)
-            {
-                vpx_codec_iface_t  *ivf_iface = ifaces[i].iface;
+    /* Try to determine the codec from the fourcc. */
+    for (i = 0; i < sizeof(ifaces) / sizeof(ifaces[0]); i++)
+        if ((fourcc & ifaces[i].fourcc_mask) == ifaces[i].fourcc)
+        {
+            vpx_codec_iface_t  *ivf_iface = ifaces[i].iface;
 
-                if (iface && iface != ivf_iface)
-                    fprintf(stderr, "Notice -- IVF header indicates codec: %s\n",
-                            ifaces[i].name);
-                else
-                    iface = ivf_iface;
+            if (iface && iface != ivf_iface)
+                fprintf(stderr, "Notice -- IVF header indicates codec: %s\n",
+                        ifaces[i].name);
+            else
+                iface = ivf_iface;
 
-                break;
-            }
-    }
-    else if(use_y4m)
-    {
-        fprintf(stderr, "YUV4MPEG2 output not supported from raw input.\n");
-        return EXIT_FAILURE;
-    }
+            break;
+        }
 
     if (vpx_codec_dec_init(&decoder, iface ? iface :  ifaces[0].iface, &cfg,
                            postproc ? VPX_CODEC_USE_POSTPROC : 0))