ref: 09acd267bc3ad6ece4bc350fde32b266949fd833
parent: 8710cceb45ad64a50287a555e8803df1df5e72ad
author: Frank Galligan <[email protected]>
date: Mon Jun 1 06:20:58 EDT 2015
vpxenc: Add support for pixel aspect ratio. WebM files will adjust the display width and height according to the input pixel aspect ratio. The default pixel aspect ratio is 1:1. BUG=https://code.google.com/p/webm/issues/detail?id=1005 Change-Id: I23e0a601b7259fa9513cb86110c41b8437769808
--- a/test/test-data.mk
+++ b/test/test-data.mk
@@ -12,6 +12,7 @@
LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_12_422.y4m
LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_12_444.y4m
LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_12_440.yuv
+LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_8_420_a10-1.y4m
LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_8_420.y4m
LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_8_422.y4m
LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_8_444.y4m
--- a/test/test-data.sha1
+++ b/test/test-data.sha1
@@ -22,6 +22,7 @@
c92825f1ea25c5c37855083a69faac6ac4641a9e *park_joy_90p_12_422.y4m
b592189b885b6cc85db55cc98512a197d73d3b34 *park_joy_90p_12_444.y4m
82c1bfcca368c2f22bad7d693d690d5499ecdd11 *park_joy_90p_12_440.yuv
+b9e1e90aece2be6e2c90d89e6ab2372d5f8c792d *park_joy_90p_8_420_a10-1.y4m
4e0eb61e76f0684188d9bc9f3ce61f6b6b77bb2c *park_joy_90p_8_420.y4m
7a193ff7dfeb96ba5f82b2afd7afa9e1fe83d947 *park_joy_90p_8_422.y4m
bdb7856e6bc93599bdda05c2e773a9f22b6c6d03 *park_joy_90p_8_444.y4m
--- a/test/tools_common.sh
+++ b/test/tools_common.sh
@@ -408,6 +408,8 @@
YUV_RAW_INPUT_WIDTH=352
YUV_RAW_INPUT_HEIGHT=288
+Y4M_NOSQ_PAR_INPUT="${LIBVPX_TEST_DATA_PATH}/park_joy_90p_8_420_a10-1.y4m"
+
# Setup a trap function to clean up after tests complete.
trap cleanup EXIT
@@ -429,6 +431,7 @@
VPX_TEST_VERBOSE_OUTPUT=${VPX_TEST_VERBOSE_OUTPUT}
YUV_RAW_INPUT=${YUV_RAW_INPUT}
YUV_RAW_INPUT_WIDTH=${YUV_RAW_INPUT_WIDTH}
- YUV_RAW_INPUT_HEIGHT=${YUV_RAW_INPUT_HEIGHT}"
+ YUV_RAW_INPUT_HEIGHT=${YUV_RAW_INPUT_HEIGHT}
+ Y4M_NOSQ_PAR_INPUT=${Y4M_NOSQ_PAR_INPUT}"
fi # End $VPX_TEST_TOOLS_COMMON_SH pseudo include guard.
--- a/test/vpxenc.sh
+++ b/test/vpxenc.sh
@@ -23,6 +23,13 @@
elog "The file ${YUV_RAW_INPUT##*/} must exist in LIBVPX_TEST_DATA_PATH."
return 1
fi
+ if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
+ if [ ! -e "${Y4M_NOSQ_PAR_INPUT}" ]; then
+ elog "The file ${Y4M_NOSQ_PAR_INPUT##*/} must exist in"
+ elog "LIBVPX_TEST_DATA_PATH."
+ return 1
+ fi
+ fi
if [ -z "$(vpx_tool_path vpxenc)" ]; then
elog "vpxenc not found. It must exist in LIBVPX_BIN_PATH or its parent."
return 1
@@ -49,6 +56,10 @@
--height="${YUV_RAW_INPUT_HEIGHT}""
}
+y4m_input_non_square_par() {
+ echo ""${Y4M_NOSQ_PAR_INPUT}""
+}
+
# Echo default vpxenc real time encoding params. $1 is the codec, which defaults
# to vp8 if unspecified.
vpxenc_rt_params() {
@@ -320,6 +331,23 @@
fi
}
+# TODO(fgalligan): Test that DisplayWidth is different than video width.
+vpxenc_vp9_webm_non_square_par() {
+ if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
+ [ "$(webm_io_available)" = "yes" ]; then
+ local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_non_square_par.webm"
+ vpxenc $(y4m_input_non_square_par) \
+ --codec=vp9 \
+ --limit="${TEST_FRAMES}" \
+ --output="${output}"
+
+ if [ ! -e "${output}" ]; then
+ elog "Output file does not exist."
+ return 1
+ fi
+ fi
+}
+
vpxenc_tests="vpxenc_vp8_ivf
vpxenc_vp8_webm
vpxenc_vp8_webm_rt
@@ -332,6 +360,7 @@
vpxenc_vp9_webm_2pass
vpxenc_vp9_ivf_lossless
vpxenc_vp9_ivf_minq0_maxq0
- vpxenc_vp9_webm_lag10_frames20"
+ vpxenc_vp9_webm_lag10_frames20
+ vpxenc_vp9_webm_non_square_par"
run_tests vpxenc_verify_environment "${vpxenc_tests}"
--- a/tools_common.h
+++ b/tools_common.h
@@ -89,6 +89,7 @@
enum VideoFileType file_type;
uint32_t width;
uint32_t height;
+ struct VpxRational pixel_aspect_ratio;
vpx_img_fmt_t fmt;
vpx_bit_depth_t bit_depth;
int only_i420;
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -944,6 +944,10 @@
rewind(input->file);
}
+ /* Default to 1:1 pixel aspect ratio. */
+ input->pixel_aspect_ratio.numerator = 1;
+ input->pixel_aspect_ratio.denominator = 1;
+
/* For RAW input sources, these bytes will applied on the first frame
* in read_frame().
*/
@@ -957,6 +961,8 @@
input->file_type = FILE_TYPE_Y4M;
input->width = input->y4m.pic_w;
input->height = input->y4m.pic_h;
+ input->pixel_aspect_ratio.numerator = input->y4m.par_n;
+ input->pixel_aspect_ratio.denominator = input->y4m.par_d;
input->framerate.numerator = input->y4m.fps_n;
input->framerate.denominator = input->y4m.fps_d;
input->fmt = input->y4m.vpx_fmt;
@@ -1390,7 +1396,8 @@
static void open_output_file(struct stream_state *stream,
- struct VpxEncoderConfig *global) {
+ struct VpxEncoderConfig *global,
+ const struct VpxRational *pixel_aspect_ratio) {
const char *fn = stream->config.out_fn;
const struct vpx_codec_enc_cfg *const cfg = &stream->config.cfg;
@@ -1411,7 +1418,8 @@
write_webm_file_header(&stream->ebml, cfg,
&global->framerate,
stream->config.stereo_fmt,
- global->codec->fourcc);
+ global->codec->fourcc,
+ pixel_aspect_ratio);
}
#endif
@@ -2044,7 +2052,8 @@
}
FOREACH_STREAM(setup_pass(stream, &global, pass));
- FOREACH_STREAM(open_output_file(stream, &global));
+ FOREACH_STREAM(open_output_file(stream, &global,
+ &input.pixel_aspect_ratio));
FOREACH_STREAM(initialize_encoder(stream, &global));
#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
--- a/webmenc.cc
+++ b/webmenc.cc
@@ -24,7 +24,8 @@
const vpx_codec_enc_cfg_t *cfg,
const struct vpx_rational *fps,
stereo_format_t stereo_fmt,
- unsigned int fourcc) {
+ unsigned int fourcc,
+ const struct VpxRational *par) {
mkvmuxer::MkvWriter *const writer = new mkvmuxer::MkvWriter(glob->stream);
mkvmuxer::Segment *const segment = new mkvmuxer::Segment();
segment->Init(writer);
@@ -49,6 +50,15 @@
segment->GetTrackByNumber(video_track_id));
video_track->SetStereoMode(stereo_fmt);
video_track->set_codec_id(fourcc == VP8_FOURCC ? "V_VP8" : "V_VP9");
+ if (par->numerator > 1 || par->denominator > 1) {
+ // TODO(fgalligan): Add support of DisplayUnit, Display Aspect Ratio type
+ // to WebM format.
+ const uint64_t display_width =
+ static_cast<uint64_t>(((cfg->g_w * par->numerator * 1.0) /
+ par->denominator) + .5);
+ video_track->set_display_width(display_width);
+ video_track->set_display_height(cfg->g_h);
+ }
if (glob->debug) {
video_track->set_uid(kDebugTrackUid);
}
--- a/webmenc.h
+++ b/webmenc.h
@@ -42,7 +42,8 @@
const vpx_codec_enc_cfg_t *cfg,
const struct vpx_rational *fps,
stereo_format_t stereo_fmt,
- unsigned int fourcc);
+ unsigned int fourcc,
+ const struct VpxRational *par);
void write_webm_block(struct EbmlGlobal *glob,
const vpx_codec_enc_cfg_t *cfg,