From 5ab63583db5d294f65e0b114b7f589af0daaeefb Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Fri, 17 Jan 2014 17:02:37 -0800 Subject: [PATCH] Moving y4m encoding functions into separate files. Change-Id: I03f614872167841515a74740d654c008b60104a4 --- examples.mk | 1 + vpxdec.c | 29 ++++++----------------------- y4menc.c | 30 ++++++++++++++++++++++++++++++ y4menc.h | 27 +++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 y4menc.c create mode 100644 y4menc.h diff --git a/examples.mk b/examples.mk index 66b719ca0..6befa506f 100644 --- a/examples.mk +++ b/examples.mk @@ -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 diff --git a/vpxdec.c b/vpxdec.c index 731feedbb..c067609c4 100644 --- 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 index 000000000..8321b432e --- /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 index 000000000..e5f7978a7 --- /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 + +#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_