From patchwork Mon May 15 08:22:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41613 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1437690pzb; Mon, 15 May 2023 01:22:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ADaR8PKpdCspFC+9U3EKJuCiLU8rJFDm88CB8rmL099JehG+0u4MLpMUxUSvj1vsECVwB X-Received: by 2002:a17:907:971b:b0:966:7a0a:28c1 with SMTP id jg27-20020a170907971b00b009667a0a28c1mr24293968ejc.35.1684138951760; Mon, 15 May 2023 01:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684138951; cv=none; d=google.com; s=arc-20160816; b=YKjMtWgC3erh3TB1AebkVSHj0lIpj7KzgY9nwn/eW7BKwLkZx26kc1/FMepTM1awFH Veko9E5133nNMtzpftmcJHihA1tMlQWIRHJqaFISMoKg225Z7kd0Z3gQwGul+lv7DhL8 pHpGGogPMP3KnGSqqWjRyLK9ptErszsu+TukqjdNypqP3ckWwp8XAppdY89Nw1ybYa0f kEgpkf/paBAgQLl6BprVstyHJXoO0l20V5jkEnggwRznGDjTBsHx8jfNR9C7mBEJI8o4 oIjnF5rARMGGIAU8ZFL++WsmHBrKrO8iM3JuDbpiP/0cECskBaoPsoU0AY/upKA+UqNU 5KMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=u5xJuL+RU35f84mrMsE3Th0c7MnSyVsrfNFaneSP2do=; b=BFIUZadwubPuz5w7d6Jq7xSZCXGiBZF4lqDVGGWFqLsFl5Q3dqWQdqoTrEnTbmb+Ht rbmrWV2z2a1VTielVtzwc3qOFpS2ETslsRUWYPqRQiVW+Ie5e5t2NLIcJmXKLt5HHY3p e3ljWzAfUR72TyUO6OA3g5w0QIkaroPF4bLtu5YWH1GPhA6NyFUWM8eGQ0DzzbLrx5cl 8RaOTDltBx+EPCvRDamTFSbkajjh3j5KNri71fJGBDthgh7I7kyVii9XUhdKooCpyNwM v2f4uWDrUvWNNhICR2k7j7K66lV8jOuC19bZ2wIge8kc0HrzZh3fwSmzHbvaKXI0k7fK XruA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g19-20020a056402181300b0050e03650769si6976810edy.483.2023.05.15.01.22.31; Mon, 15 May 2023 01:22:31 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF3E468C02B; Mon, 15 May 2023 11:22:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C4E4368BE94 for ; Mon, 15 May 2023 11:22:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 822C82404EC for ; Mon, 15 May 2023 10:22:20 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id XnRaotsv4WSk for ; Mon, 15 May 2023 10:22:19 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 8C7CC240177 for ; Mon, 15 May 2023 10:22:19 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 4B62C3A031B for ; Mon, 15 May 2023 10:22:19 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 May 2023 10:22:17 +0200 Message-Id: <20230515082217.4409-1-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/av1*: fix exporting framerate X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: CA7hrTMFmV+0 * take num_ticks_per_picture_minus_1 into account, since that is a part of the framerate computation * stop exporting num_ticks_per_picture_minus_1 into AVCodecContext.ticks_per_frame, as that field is used for other purposes (in conjunction with repeat_pict, which is not used at all by av1) --- libavcodec/Makefile | 2 +- libavcodec/av1_parse.c | 14 ++++++++++++++ libavcodec/av1_parse.h | 3 +++ libavcodec/av1_parser.c | 11 ++++++----- libavcodec/av1dec.c | 14 +++++--------- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3cf4444b7e..9587e56493 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1143,7 +1143,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \ ac3_channel_layout_tab.o OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o -OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o +OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c index 59ea0bc6e7..136ad1a58f 100644 --- a/libavcodec/av1_parse.c +++ b/libavcodec/av1_parse.c @@ -108,3 +108,17 @@ void ff_av1_packet_uninit(AV1Packet *pkt) av_freep(&pkt->obus); pkt->obus_allocated = pkt->obus_allocated_size = 0; } + +AVRational ff_av1_framerate(int64_t ticks_per_frame, int64_t units_per_tick, + int64_t time_scale) +{ + AVRational fr; + + if (ticks_per_frame && units_per_tick && time_scale && + ticks_per_frame < INT64_MAX / units_per_tick && + av_reduce(&fr.den, &fr.num, units_per_tick * ticks_per_frame, + time_scale, INT_MAX)) + return fr; + + return (AVRational){ 0, 1 }; +} diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h index f4a5d2830e..1f3001d2a5 100644 --- a/libavcodec/av1_parse.h +++ b/libavcodec/av1_parse.h @@ -181,4 +181,7 @@ static inline int get_obu_bit_length(const uint8_t *buf, int size, int type) return size; } +AVRational ff_av1_framerate(int64_t ticks_per_frame, int64_t units_per_tick, + int64_t time_scale); + #endif /* AVCODEC_AV1_PARSE_H */ diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c index 14dae92fe9..2b79493bf8 100644 --- a/libavcodec/av1_parser.c +++ b/libavcodec/av1_parser.c @@ -21,6 +21,8 @@ */ #include "libavutil/avassert.h" + +#include "av1_parse.h" #include "cbs.h" #include "cbs_av1.h" #include "parser.h" @@ -162,11 +164,10 @@ static int av1_parser_parse(AVCodecParserContext *ctx, avctx->color_trc = (enum AVColorTransferCharacteristic) color->transfer_characteristics; avctx->color_range = color->color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; - if (seq->timing_info_present_flag) { - const AV1RawTimingInfo *timing = &seq->timing_info; - av_reduce(&avctx->framerate.den, &avctx->framerate.num, - timing->num_units_in_display_tick, timing->time_scale, INT_MAX); - } + if (seq->timing_info_present_flag) + avctx->framerate = ff_av1_framerate(1LL + seq->timing_info.num_ticks_per_picture_minus_1, + seq->timing_info.num_units_in_display_tick, + seq->timing_info.time_scale); end: ff_cbs_fragment_reset(td); diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index c90c9c1a69..d46ee48335 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -26,6 +26,7 @@ #include "libavutil/pixdesc.h" #include "libavutil/opt.h" #include "avcodec.h" +#include "av1_parse.h" #include "av1dec.h" #include "atsc_a53.h" #include "bytestream.h" @@ -709,15 +710,10 @@ static int set_context_with_sequence(AVCodecContext *avctx, } avctx->sample_aspect_ratio = (AVRational) { 1, 1 }; - if (seq->timing_info.num_units_in_display_tick && - seq->timing_info.time_scale) { - av_reduce(&avctx->framerate.den, &avctx->framerate.num, - seq->timing_info.num_units_in_display_tick, - seq->timing_info.time_scale, - INT_MAX); - if (seq->timing_info.equal_picture_interval) - avctx->ticks_per_frame = seq->timing_info.num_ticks_per_picture_minus_1 + 1; - } + if (seq->timing_info_present_flag) + avctx->framerate = ff_av1_framerate(1LL + seq->timing_info.num_ticks_per_picture_minus_1, + seq->timing_info.num_units_in_display_tick, + seq->timing_info.time_scale); return 0; }