From: Frank Galligan Date: Mon, 1 Jun 2015 17:20:58 +0000 (-0700) Subject: vpxenc: Add support for pixel aspect ratio. X-Git-Tag: v1.5.0~599^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09acd267bc3ad6ece4bc350fde32b266949fd833;p=platform%2Fupstream%2Flibvpx.git 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 --- diff --git a/test/test-data.mk b/test/test-data.mk index 1055e12..dda1c18 100644 --- a/test/test-data.mk +++ b/test/test-data.mk @@ -12,6 +12,7 @@ LIBVPX_TEST_DATA-$(CONFIG_ENCODERS) += park_joy_90p_12_420.y4m 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 diff --git a/test/test-data.sha1 b/test/test-data.sha1 index 0bb4481..3590f4e 100644 --- a/test/test-data.sha1 +++ b/test/test-data.sha1 @@ -22,6 +22,7 @@ c934da6fb8cc54ee2a8c17c54cf6076dac37ead0 *park_joy_90p_10_440.yuv 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 diff --git a/test/tools_common.sh b/test/tools_common.sh index 0ae011e..60424ed 100755 --- a/test/tools_common.sh +++ b/test/tools_common.sh @@ -408,6 +408,8 @@ YUV_RAW_INPUT="${LIBVPX_TEST_DATA_PATH}/hantro_collage_w352h288.yuv" 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 @@ vlog "$(basename "${0%.*}") test configuration: 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. diff --git a/test/vpxenc.sh b/test/vpxenc.sh index 9674bdc..1faa145 100755 --- a/test/vpxenc.sh +++ b/test/vpxenc.sh @@ -23,6 +23,13 @@ vpxenc_verify_environment() { 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 @@ yuv_input_hantro_collage() { --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 @@ vpxenc_vp9_webm_lag10_frames20() { 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_tests="vpxenc_vp8_ivf 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}" diff --git a/tools_common.h b/tools_common.h index aa7f025..adccec8 100644 --- a/tools_common.h +++ b/tools_common.h @@ -89,6 +89,7 @@ struct VpxInputContext { 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; diff --git a/vpxenc.c b/vpxenc.c index be9b8b6..dbee37f 100644 --- a/vpxenc.c +++ b/vpxenc.c @@ -944,6 +944,10 @@ static void open_input_file(struct VpxInputContext *input) { 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 @@ static void open_input_file(struct VpxInputContext *input) { 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 show_stream_config(struct stream_state *stream, 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 @@ static void open_output_file(struct stream_state *stream, 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 @@ int main(int argc, const char **argv_) { } 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 diff --git a/webmenc.cc b/webmenc.cc index a0e542b..8212ee3 100644 --- a/webmenc.cc +++ b/webmenc.cc @@ -24,7 +24,8 @@ void write_webm_file_header(struct EbmlGlobal *glob, 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 @@ void write_webm_file_header(struct EbmlGlobal *glob, 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(((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); } diff --git a/webmenc.h b/webmenc.h index 0ac606b..c255d3d 100644 --- a/webmenc.h +++ b/webmenc.h @@ -42,7 +42,8 @@ void write_webm_file_header(struct EbmlGlobal *glob, 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,