From patchwork Sun Jan 24 14:41:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 25147 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 548D144B754 for ; Sun, 24 Jan 2021 16:48:14 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 22B7768921B; Sun, 24 Jan 2021 16:48:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EAF9268041C for ; Sun, 24 Jan 2021 16:48:07 +0200 (EET) Received: by mail-qk1-f170.google.com with SMTP id a7so3264544qkb.13 for ; Sun, 24 Jan 2021 06:48:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=p22D/0cJALph1UoUNn20tbOWTO8Qrl03H4QMdZP3CLQ=; b=av5N6/BMWNguL3sFLFekXZlD1c3vuRvxikB/GCySBIK4zhkAUY7Mmt3X/yR9nWDD5P wvMPYyuZqEzUugr8Tl4kFPJuX9lqfF4hTLHY/gbb9K5QL94YiJolFC7h/mD03XX/HXBs Xm6xSpfoTIWl5MwTlEUu5V0HKJDNkTxz8KTyXtB5RzSlTqOmvbsQjcHp7u+t5y1Z9ArM lklvM7bHsAz8RnsOqD0KtoPGDguYEg+QxjeGjOaCmgRUpjX+2LovfEtXqd2UE7Ib7NEe MJtAorCDHHCaWAvf+U0CK09Kr012Pgj9mfjJsAEVCFsbaCgBTI7QNgz2ikJ4SHkdxYHq XzWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=p22D/0cJALph1UoUNn20tbOWTO8Qrl03H4QMdZP3CLQ=; b=ajob24jbQ9l3B2fX7bWh0w1AxiAoVv7ad+yQsTplPxtikwQ+xPZ0L+KgxdGE6WqkEp fA4zPL3bx42ffcJWwzSEMvFqi88cBZay2HfHeNF+nNcgQqhdhS6H1ro81ZvV4Wz0MNKy I1c2jcWHhzFVnr52Uj98eOI05ZLKIhqrSNDz1yCx8fbvEVO74icpAbavLjm1eeeZpn98 ca9Lz8twNKIhoRhwCdE3XWpFxcN7+zOVqmkxNS5K+RyzyJkzM/QNGizQz7ZMq8o0NfRc bLUwc3p4/pEIZy4VHka0mTIY5HvdkpvYlahPetUTCEpJthGBw9JIJw0v4FfQ4XF6TGdS eFkg== X-Gm-Message-State: AOAM5313yis7LZf0zKIoZ1PEiWaaaVJm1jP1uuWoOX+PfNWBVzyQ6O8s zeucuoWUxmEqxfcsG+yN5QV4CT2qHDbaRQ== X-Google-Smtp-Source: ABdhPJybqkxs/MTiddXaBppoRCdRnY1qS2IYT1+1GDoDB/D0TbtDPrKB+IHdrAV3JNr50DEmanN1vQ== X-Received: by 2002:aed:31c2:: with SMTP id 60mr209993qth.218.1611499338874; Sun, 24 Jan 2021 06:42:18 -0800 (PST) Received: from localhost.localdomain ([191.84.230.180]) by smtp.gmail.com with ESMTPSA id x74sm9889153qkb.55.2021.01.24.06.42.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Jan 2021 06:42:18 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 24 Jan 2021 11:41:13 -0300 Message-Id: <20210124144113.51841-1-jamrial@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/utils: always preserve container dimensions for all streams 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" If a decoder is used for probing it may change the dimensions reported by the demuxer, either by the lowres factor or because of assorted frames reporting different dimensions, and in a codec copy scenario, the last dimensions arbitrarily set by it could end up being propagated to the muxer. Signed-off-by: James Almer --- libavformat/utils.c | 10 ++++++---- tests/ref/fate/cbs-vp9-vp90-2-05-resize | 2 +- tests/ref/fate/redcode-demux | 2 +- tests/ref/fate/wtv-demux | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 6f100294a1..bfc8436fc9 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4105,6 +4105,7 @@ FF_ENABLE_DEPRECATION_WARNINGS st = ic->streams[i]; if (st->internal->avctx_inited) { + AVRational orig_sar = st->codecpar->sample_aspect_ratio; int orig_w = st->codecpar->width; int orig_h = st->codecpar->height; ret = avcodec_parameters_from_context(st->codecpar, st->internal->avctx); @@ -4113,13 +4114,14 @@ FF_ENABLE_DEPRECATION_WARNINGS ret = add_coded_side_data(st, st->internal->avctx); if (ret < 0) goto find_stream_info_err; -#if FF_API_LOWRES - // The decoder might reduce the video size by the lowres factor. - if (st->internal->avctx->lowres && orig_w) { + + // The decoder might change the video size. + if (orig_w && orig_h) { + if (st->codecpar->width != orig_w && st->codecpar->height != orig_h) + st->codecpar->sample_aspect_ratio = orig_sar; st->codecpar->width = orig_w; st->codecpar->height = orig_h; } -#endif } #if FF_API_LAVF_AVCTX diff --git a/tests/ref/fate/cbs-vp9-vp90-2-05-resize b/tests/ref/fate/cbs-vp9-vp90-2-05-resize index 8f036bba81..37a37ff1ea 100644 --- a/tests/ref/fate/cbs-vp9-vp90-2-05-resize +++ b/tests/ref/fate/cbs-vp9-vp90-2-05-resize @@ -1 +1 @@ -6838422ebb45df353a2bad62b9aff8e9 +1c39300b93fe110e1db30974e5d3479d diff --git a/tests/ref/fate/redcode-demux b/tests/ref/fate/redcode-demux index 45119ec71e..c6e0b6de5c 100644 --- a/tests/ref/fate/redcode-demux +++ b/tests/ref/fate/redcode-demux @@ -1,7 +1,7 @@ #tb 0: 1/240000 #media_type 0: video #codec_id 0: jpeg2000 -#dimensions 0: 2048x1152 +#dimensions 0: 4096x2304 #sar 0: 0/1 #tb 1: 1/240000 #media_type 1: audio diff --git a/tests/ref/fate/wtv-demux b/tests/ref/fate/wtv-demux index abe85a4ab6..388ba796d3 100644 --- a/tests/ref/fate/wtv-demux +++ b/tests/ref/fate/wtv-demux @@ -3,8 +3,8 @@ #tb 0: 1/10000000 #media_type 0: video #codec_id 0: mpeg2video -#dimensions 0: 720x576 -#sar 0: 64/45 +#dimensions 0: 704x480 +#sar 0: 0/1 #tb 1: 1/10000000 #media_type 1: audio #codec_id 1: mp2