From patchwork Sun May 14 19:39:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41604 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1129415pzb; Sun, 14 May 2023 12:39:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6j5CkpTc3kpzKTlC8R2GHgJxE0cGV4NOXajAQrU6tytmziU+11JBwH56RgYCW3T7lpjaGt X-Received: by 2002:aa7:dd42:0:b0:50c:804:20bb with SMTP id o2-20020aa7dd42000000b0050c080420bbmr28535221edw.16.1684093171981; Sun, 14 May 2023 12:39:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684093171; cv=none; d=google.com; s=arc-20160816; b=s/1//vd1xfOFREW8Cesjrkk5sihLRBuU2VLNKHaxypmNRB7kw2fvfcMTKudUJAO32b 1/iKjGos5uXhVDfc2CfbeIHL6YlAzCbXoy1KrdxC9Jwsrr9XSzFsiwCybHlHlMHhY2Vj qp13pRx5sQPvXYL1hI3cwPKYBqF+OKiHQ67zB9pCqgrYq2K+4hirmtrDzhFI/oVj5fi4 /JwbsoMgMDCcpS3hINMm6tGICA0eYjWY5JzvLCYWMTS+k8EuvEMdglt2/tpfNXqPc8sQ smLcJ/RQbFfuhkpQ35PfCrf7vYxRT3kZVlWKiBo15y/VNqw4cT/FU8jS5JKErvDmMbYH bT+w== 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=aE17t9PGGuaWnP1VYveasxykpQOMXUEANQloMbloEAE=; b=p5dlDe9eyu1KGcEcTPYPVeiss9eG6Udn8qYBSrIcuZVafD5L3ARLEr4+Ps6kBFqvfa +LekQPDi4smJomXs/Uyp9BE2NEwXrKALl7V5ob6rl/mv4tQFO8GsAuxJm60Vm+R2c8G5 /0jYWvboWF+z8HinJso7gZRr7Vy79mR+3uayCtwSyx+plMoVhaCwygQtkT8/e0j1ZmX7 qy7UH5Wb2XUdh2/AcLgSwKeivgG+rJm7+23DCdidKoj2HbkjIzXTPBsqh26BlCXuhtLO pEzMpYam0ikpfxeUuY4imau0IgV7kgMlJGZCamvvQ65kXjucVW6JDaG8+XgBcQ0GNC2F f4aA== 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 n13-20020a05640206cd00b0050d9de397efsi11115901edy.36.2023.05.14.12.39.31; Sun, 14 May 2023 12:39: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 8707268BF10; Sun, 14 May 2023 22:39:26 +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 E882B68B04A for ; Sun, 14 May 2023 22:39:19 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6CC502404EC for ; Sun, 14 May 2023 21:39:19 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id mQAG0i6unVim for ; Sun, 14 May 2023 21:39:18 +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 8464B240177 for ; Sun, 14 May 2023 21:39:18 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2EDA23A01C0 for ; Sun, 14 May 2023 21:39:12 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 14 May 2023 21:39:00 +0200 Message-Id: <20230514193900.10254-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: 7WdWfdDzbYaP * 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 | 13 +++++++++---- libavcodec/av1dec.c | 16 ++++++++-------- 5 files changed, 35 insertions(+), 13 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..26b70845f2 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(int ticks_per_frame, int units_per_tick, + int time_scale) +{ + AVRational fr = (AVRational){ 0, 1 }; + + if (ticks_per_frame && units_per_tick && time_scale && + ticks_per_frame < INT_MAX / units_per_tick) { + av_reduce(&fr.den, &fr.num, units_per_tick * ticks_per_frame, + time_scale, INT_MAX); + } + + return fr; +} diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h index f4a5d2830e..11f9c77de4 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(int ticks_per_frame, int units_per_tick, + int time_scale); + #endif /* AVCODEC_AV1_PARSE_H */ diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c index 14dae92fe9..0d81c29e63 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,10 +164,13 @@ 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 && + seq->timing_info.num_ticks_per_picture_minus_1 < INT_MAX - 1 && + seq->timing_info.num_units_in_display_tick < INT_MAX && + seq->timing_info.time_scale < INT_MAX) { + avctx->framerate = ff_av1_framerate(seq->timing_info.num_ticks_per_picture_minus_1 + 1, + seq->timing_info.num_units_in_display_tick, + seq->timing_info.time_scale); } end: diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index c90c9c1a69..dae1d8e8da 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,14 +710,13 @@ 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 && + seq->timing_info.num_ticks_per_picture_minus_1 < INT_MAX - 1 && + seq->timing_info.num_units_in_display_tick < INT_MAX && + seq->timing_info.time_scale < INT_MAX) { + avctx->framerate = ff_av1_framerate(seq->timing_info.num_ticks_per_picture_minus_1 + 1, + seq->timing_info.num_units_in_display_tick, + seq->timing_info.time_scale); } return 0;