ref: 5ab63583db5d294f65e0b114b7f589af0daaeefb
parent: 36ddfa9d0054cc13aa30a5a60f395a363904ba95
author: Dmitry Kovalev <dkovalev@google.com>
date: Fri Jan 17 12:02:37 EST 2014
Moving y4m encoding functions into separate files. Change-Id: I03f614872167841515a74740d654c008b60104a4
--- a/examples.mk
+++ b/examples.mk
@@ -26,6 +26,7 @@
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
--- 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,8 +692,6 @@
}
if (use_y4m && !noblit) {
- char buffer[128];
-
if (!single_file) {
fprintf(stderr, "YUV4MPEG2 not supported with output patterns,"
" try --i420 or --yv12.\n");
@@ -699,23 +698,13 @@
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 @@
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 @@
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)
--- /dev/null
+++ b/y4menc.c
@@ -1,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");
+}
--- /dev/null
+++ b/y4menc.h
@@ -1,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_
--
⑨