From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 1B45A44C2B for ; Sun, 14 May 2023 19:50:14 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D4BA668BF25; Sun, 14 May 2023 22:50:11 +0300 (EEST) Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5438768BE0B for ; Sun, 14 May 2023 22:50:05 +0300 (EEST) Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-6ab1a20aa12so4406746a34.1 for ; Sun, 14 May 2023 12:50:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684093803; x=1686685803; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=2r/Ni4CjWg8r+hPpIyGdKXs80npQO7r0WvmircsQi0Y=; b=F1niHttvh4w7iKnbz6x8li76vnYHBeYA68iCVA3rUtnDnONeFjuDcalMagwFlOWjje lPy4Alu5iZ4PzGZZHcBVjSevXcKr8pAppmotE8qRGPqySDLzPR7yfTzHqhJYX/oYYVYv bUTv4i9+g/7hdWzBQPn2QIIoOV/8Jk1c5PSh+sQlzXbF/n+3UWDk60dQ0dheNzT7h4vo 5nuA9e38WKLX4pM8x4BZlLnnIDHe8xQnAfO3lW0lSg32ph72vg/13xNlU1JPM+5K0ty4 PDcFfzpql49p8wDCw50SDqPUSMEW2aiaPkpNt2s2dkrWRv5ypLLHIWK5Pz7nXqCkgcOM Smvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684093803; x=1686685803; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2r/Ni4CjWg8r+hPpIyGdKXs80npQO7r0WvmircsQi0Y=; b=EwtRFpGGl4FvrQveopCca8RgylGNVFfZqbpkGRA6eA0pcArQ8SUKtzPWlFPKWWaO9W ZDf91YHm1N4UGcAo3lz4CHbjKxs4ImHBQSl9NJLOv9dVFIDYcoTZTyRwptf4BWs/1slU JPy0dGePyABPBEBV4RI1HDYnGBhruHV4ssc2p8aUp0SiQ65ENE5eiL9KNt6QhgLJ2cS7 LzJSxbPzbohXSZf/Wc7WFc8tWnzLVnAeq2pN+cTYjwvhp26HmLn4C6NttKb/F2D4mYoO bT4cPq0nhQjxzPD0HzraeB5pPfNcF0/8V3+Uypseo2Z/4EVZ7QJkkyIii5gkgh6NPgCt 0TrA== X-Gm-Message-State: AC+VfDyYfxHIHs+HOyfTk1DtueOjFmX7XJEGJZrtU7eIcGE1Qq/wahbq F7p46CymRHneuuuT0ImGfjr/5VNJsY4= X-Google-Smtp-Source: ACHHUZ48I93HzzIKsu6di2DC/ufOLoS9pJhELOY3sS8Enxc3FAiDMS+FKEvwjbdhM7H0oRieXvrOXQ== X-Received: by 2002:a9d:7c96:0:b0:6ab:119:2b96 with SMTP id q22-20020a9d7c96000000b006ab01192b96mr10392322otn.31.1684093803211; Sun, 14 May 2023 12:50:03 -0700 (PDT) Received: from [192.168.0.12] (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id z26-20020a05683020da00b006ab305429e7sm4791051otq.0.2023.05.14.12.50.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 May 2023 12:50:02 -0700 (PDT) Message-ID: Date: Sun, 14 May 2023 16:50:06 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 To: ffmpeg-devel@ffmpeg.org References: <20230514193900.10254-1-anton@khirnov.net> Content-Language: en-US From: James Almer In-Reply-To: <20230514193900.10254-1-anton@khirnov.net> Subject: Re: [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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 5/14/2023 4:39 PM, Anton Khirnov wrote: > * 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 takes int64_t as input, so you could just cast 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) { You could pass all uint32_t values as they are and check the return value of av_reduce(). If it's 0 (non exact result) then don't set avctx->framerate (or set it to { 0, 1 }, whatever is cleaner). There could be samples with bitstream values > INT_MAX where the reduced AVRational is still within INT_MAX for num and den. > + 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; _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".