From patchwork Fri Nov 16 17:19:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Borsboom X-Patchwork-Id: 11044 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4F1C144D52D for ; Fri, 16 Nov 2018 19:19:26 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D07CC689E7A; Fri, 16 Nov 2018 19:19:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from kyoto.xs4all.nl (kyoto.xs4all.nl [83.161.153.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3727F689832 for ; Fri, 16 Nov 2018 19:19:20 +0200 (EET) Received: from [IPv6:2001:980:9507:0:8e70:5aff:fec6:83fc] ([IPv6:2001:980:9507:0:8e70:5aff:fec6:83fc]) (authenticated bits=0) by kyoto.xs4all.nl (8.14.7/8.14.7) with ESMTP id wAGHJJYL012320 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Fri, 16 Nov 2018 18:19:19 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=carpalis.nl; s=default; t=1542388759; bh=uAgBDHunixgtR+mAHj52M36eLX724a84pjaKn7Fw1L4=; h=To:References:Subject:From:Date:In-Reply-To; b=hACGuysMqc+jf8IGaW4jetKTd68PvTNzU2IygH4xTNFr53dUEQTIpsWPpomKbVEsL lN4BSFFQB+zuT+2FWvrEscOdg7hdT1XpVuwbAsIHDGMiQNjFovHoj3Pveyync1ugfT g4iqYOBuBKT3hO+mh79Uf94SLqJGXJGU7ICT96RkIGByAwTK202vesbhtsJC7UIy7w sXf0Egd5EsYw2gCE+7sG8h8Z1DJ2cg6mOFriLkxCbyhELlWjp0ngw7+oYqlRig3V08 Axmgfbw++RjLJglkY42MAh6rdaKaLate+fvhS6HCJhFzZy/q+SurlD78SShAchUaTk WJJu1gFc4jR7Q== To: ffmpeg-devel@ffmpeg.org References: From: Jerome Borsboom Message-ID: <0fba3803-3d7f-ef7b-66d2-903dba227298@carpalis.nl> Date: Fri, 16 Nov 2018 18:19:19 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: Content-Language: nl Subject: [FFmpeg-devel] [PATCH v2] avcodec/vc1: correct aspect ratio calculation X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" According to VC-1 spec: * Display size defaults to max coded size when not explicitly set in sequence header * Aspect ratio in the sequence header refers to the display size elements. Therefore, the aspect ratio for the coded samples (SAR) needs to take into account the scaling from coded size to display size, and the aspect ratio of the display size elements. Signed-off-by: Jerome Borsboom --- libavcodec/vc1.c | 42 +++++++++++++++++++++++++----------------- libavcodec/vc1.h | 2 ++ tests/ref/fate/vc1-ism | 2 +- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c index 3581d87b57..51ad665f4b 100644 --- a/libavcodec/vc1.c +++ b/libavcodec/vc1.c @@ -442,30 +442,28 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) } v->s.max_b_frames = v->s.avctx->max_b_frames = 7; if (get_bits1(gb)) { //Display Info - decoding is not affected by it - int w, h, ar = 0; + int ar = 0; av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n"); - w = get_bits(gb, 14) + 1; - h = get_bits(gb, 14) + 1; - av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h); + v->disp_horiz_size = get_bits(gb, 14) + 1; + v->disp_vert_size = get_bits(gb, 14) + 1; + av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", + v->disp_horiz_size, v->disp_vert_size); if (get_bits1(gb)) ar = get_bits(gb, 4); if (ar && ar < 14) { - v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar]; + v->aspect_ratio = ff_vc1_pixel_aspect[ar]; } else if (ar == 15) { - w = get_bits(gb, 8) + 1; - h = get_bits(gb, 8) + 1; - v->s.avctx->sample_aspect_ratio = (AVRational){w, h}; + v->aspect_ratio.num = get_bits(gb, 8) + 1; + v->aspect_ratio.den = get_bits(gb, 8) + 1; + av_reduce(&v->aspect_ratio.num, &v->aspect_ratio.den, + v->aspect_ratio.num, v->aspect_ratio.den, + 256); } else { - av_reduce(&v->s.avctx->sample_aspect_ratio.num, - &v->s.avctx->sample_aspect_ratio.den, - v->s.avctx->height * w, - v->s.avctx->width * h, - 1 << 30); + v->aspect_ratio = (AVRational){1, 1}; } - ff_set_sar(v->s.avctx, v->s.avctx->sample_aspect_ratio); - av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n", - v->s.avctx->sample_aspect_ratio.num, - v->s.avctx->sample_aspect_ratio.den); + av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect ratio: %i:%i\n", + v->aspect_ratio.num, + v->aspect_ratio.den); if (get_bits1(gb)) { //framerate stuff if (get_bits1(gb)) { @@ -490,6 +488,10 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) v->transfer_char = get_bits(gb, 8); v->matrix_coef = get_bits(gb, 8); } + } else { + v->disp_horiz_size = v->max_coded_width; + v->disp_vert_size = v->max_coded_height; + v->aspect_ratio = (AVRational){1, 1}; } v->hrd_param_flag = get_bits1(gb); @@ -544,6 +546,12 @@ int ff_vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContex av_log(avctx, AV_LOG_ERROR, "Failed to set dimensions %d %d\n", w, h); return ret; } + av_reduce(&avctx->sample_aspect_ratio.num, + &avctx->sample_aspect_ratio.den, + v->disp_horiz_size * v->aspect_ratio.num * h, + v->disp_vert_size * v->aspect_ratio.den * w, + 1 << 30); + ff_set_sar(avctx, avctx->sample_aspect_ratio); if (v->extended_mv) v->extended_dmv = get_bits1(gb); diff --git a/libavcodec/vc1.h b/libavcodec/vc1.h index 69f6ca9e4d..7674b0f9a1 100644 --- a/libavcodec/vc1.h +++ b/libavcodec/vc1.h @@ -209,6 +209,8 @@ typedef struct VC1Context{ int hrd_param_flag; ///< Presence of Hypothetical Reference ///< Decoder parameters int psf; ///< Progressive Segmented Frame + int disp_horiz_size, disp_vert_size; + AVRational aspect_ratio; //@} /** Sequence header data for all Profiles diff --git a/tests/ref/fate/vc1-ism b/tests/ref/fate/vc1-ism index 1bd6c643d9..4f460f6754 100644 --- a/tests/ref/fate/vc1-ism +++ b/tests/ref/fate/vc1-ism @@ -2,7 +2,7 @@ #media_type 0: video #codec_id 0: rawvideo #dimensions 0: 240x104 -#sar 0: 156/156 +#sar 0: 13/30 0, 0, 0, 1, 37440, 0xd1bc5235 0, 2, 2, 1, 37440, 0x158e6167 0, 3, 3, 1, 37440, 0x0faa4481