Moving y4m encoding functions into separate files.
authorDmitry Kovalev <dkovalev@google.com>
Sat, 18 Jan 2014 01:02:37 +0000 (17:02 -0800)
committerDmitry Kovalev <dkovalev@google.com>
Sat, 18 Jan 2014 01:02:37 +0000 (17:02 -0800)
Change-Id: I03f614872167841515a74740d654c008b60104a4

examples.mk
vpxdec.c
y4menc.c [new file with mode: 0644]
y4menc.h [new file with mode: 0644]

index 66b719c..6befa50 100644 (file)
@@ -26,6 +26,7 @@ vpxdec.SRCS                 += args.c args.h
 vpxdec.SRCS                 += ivfdec.c ivfdec.h
 vpxdec.SRCS                 += tools_common.c tools_common.h
 vpxdec.SRCS                 += webmdec.c webmdec.h
+vpxdec.SRCS                 += y4menc.c y4menc.h
 vpxdec.SRCS                 += nestegg/halloc/halloc.h
 vpxdec.SRCS                 += nestegg/halloc/src/align.h
 vpxdec.SRCS                 += nestegg/halloc/src/halloc.c
index 731feed..c067609 100644 (file)
--- a/vpxdec.c
+++ b/vpxdec.c
@@ -33,6 +33,7 @@
 
 #include "./tools_common.h"
 #include "./webmdec.h"
+#include "./y4menc.h"
 
 static const char *exec_name;
 
@@ -691,31 +692,19 @@ int main_loop(int argc, const char **argv_) {
   }
 
   if (use_y4m && !noblit) {
-    char buffer[128];
-
     if (!single_file) {
       fprintf(stderr, "YUV4MPEG2 not supported with output patterns,"
               " try --i420 or --yv12.\n");
       return EXIT_FAILURE;
     }
 
-    if (vpx_input_ctx.file_type == FILE_TYPE_WEBM)
+    if (vpx_input_ctx.file_type == FILE_TYPE_WEBM) {
       if (webm_guess_framerate(input.webm_ctx, input.vpx_input_ctx)) {
         fprintf(stderr, "Failed to guess framerate -- error parsing "
                 "webm file?\n");
         return EXIT_FAILURE;
       }
-
-
-    /*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.*/
-    snprintf(buffer, sizeof(buffer), "YUV4MPEG2 W%u H%u F%u:%u I%c ",
-             vpx_input_ctx.width, vpx_input_ctx.height,
-             vpx_input_ctx.framerate.numerator,
-             vpx_input_ctx.framerate.denominator,
-             'p');
-    fwrite(buffer, 1, strlen(buffer), out);
+    }
   }
 
   /* Try to determine the codec from the fourcc. */
@@ -863,14 +852,8 @@ int main_loop(int argc, const char **argv_) {
 
     if (!noblit) {
       if (frame_out == 1 && img && use_y4m) {
-        /* Write out the color format to terminate the header line */
-        const char *color =
-            img->fmt == VPX_IMG_FMT_444A ? "C444alpha\n" :
-            img->fmt == VPX_IMG_FMT_I444 ? "C444\n" :
-            img->fmt == VPX_IMG_FMT_I422 ? "C422\n" :
-            "C420jpeg\n";
-
-        fwrite(color, 1, strlen(color), out);
+        y4m_write_file_header(out, vpx_input_ctx.width, vpx_input_ctx.height,
+                              &vpx_input_ctx.framerate, img->fmt);
       }
 
       if (img && do_scale) {
@@ -916,7 +899,7 @@ int main_loop(int argc, const char **argv_) {
           out = out_open(out_fn, do_md5);
         } else {
           if (use_y4m)
-            fwrite("FRAME\n", 1, 6, out);
+            y4m_write_frame_header(out);
         }
 
         if (do_md5)
diff --git a/y4menc.c b/y4menc.c
new file mode 100644 (file)
index 0000000..8321b43
--- /dev/null
+++ b/y4menc.c
@@ -0,0 +1,30 @@
+/*
+ *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "./y4menc.h"
+
+void y4m_write_file_header(FILE *file, int width, int height,
+                           const struct VpxRational *framerate,
+                           vpx_img_fmt_t fmt) {
+  const char *color = fmt == VPX_IMG_FMT_444A ? "C444alpha\n" :
+                      fmt == VPX_IMG_FMT_I444 ? "C444\n" :
+                      fmt == VPX_IMG_FMT_I422 ? "C422\n" :
+                      "C420jpeg\n";
+
+  // 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.*/
+  fprintf(file, "YUV4MPEG2 W%u H%u F%u:%u I%c %s", width, height,
+          framerate->numerator, framerate->denominator, 'p', color);
+}
+
+void y4m_write_frame_header(FILE *file) {
+  fprintf(file, "FRAME\n");
+}
diff --git a/y4menc.h b/y4menc.h
new file mode 100644 (file)
index 0000000..e5f7978
--- /dev/null
+++ b/y4menc.h
@@ -0,0 +1,27 @@
+/*
+ *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef Y4MENC_H_
+#define Y4MENC_H_
+
+#include <stdio.h>
+
+#include "./tools_common.h"
+
+#include "vpx/vpx_decoder.h"
+
+void y4m_write_file_header(FILE *file, int width, int height,
+                           const struct VpxRational *framerate,
+                           vpx_img_fmt_t fmt);
+
+void y4m_write_frame_header(FILE *file);
+
+
+#endif  // Y4MENC_H_