Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 05/13] lavc/av1*: fix exporting framerate
Date: Wed, 10 May 2023 08:52:34 -0300
Message-ID: <aefc137d-3a2d-265f-c842-c5a051900ec8@gmail.com> (raw)
In-Reply-To: <20230507133255.20881-5-anton@khirnov.net>

On 5/7/2023 10:32 AM, 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  | 15 +++++++++++++++
>   libavcodec/av1_parse.h  |  4 ++++
>   libavcodec/av1_parser.c |  9 ++++-----
>   libavcodec/av1dec.c     | 12 +++---------
>   5 files changed, 27 insertions(+), 15 deletions(-)
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index b0971ce833..8162bcf4fa 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..cf325e09b9 100644
> --- a/libavcodec/av1_parse.c
> +++ b/libavcodec/av1_parse.c
> @@ -24,6 +24,7 @@
>   
>   #include "av1.h"
>   #include "av1_parse.h"
> +#include "cbs_av1.h"
>   #include "bytestream.h"
>   
>   int ff_av1_extract_obu(AV1OBU *obu, const uint8_t *buf, int length, void *logctx)
> @@ -108,3 +109,17 @@ void ff_av1_packet_uninit(AV1Packet *pkt)
>       av_freep(&pkt->obus);
>       pkt->obus_allocated = pkt->obus_allocated_size = 0;
>   }
> +
> +AVRational ff_av1_framerate(const AV1RawTimingInfo *ti)

Could i ask you to instead pass num_units_in_display_tick, time_scale 
and num_ticks_per_picture as arguments to this function, instead of 
including cbs_av1 in av1_parse? I devised that module as a lightweight 
and reduced alternative to the full bitstream parser that's CBS, used by 
the extract_extradata bsf and even included by the av1 demuxer (for the 
couple inlined functions in the header).

It should also let you reuse it in libdav1d.c, afaict.

> +{
> +    const int ticks = ti->num_ticks_per_picture_minus_1 + 1;
> +    AVRational fr = (AVRational){ 0, 1 };
> +
> +    if (ti->num_units_in_display_tick && ti->time_scale &&
> +        ticks < INT_MAX / ti->num_units_in_display_tick) {
> +        av_reduce(&fr.den, &fr.num, ti->num_units_in_display_tick * ticks,
> +                  ti->time_scale, INT_MAX);
> +    }
> +
> +    return fr;
> +}
> diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
> index f4a5d2830e..60a6fd0ba2 100644
> --- a/libavcodec/av1_parse.h
> +++ b/libavcodec/av1_parse.h
> @@ -181,4 +181,8 @@ static inline int get_obu_bit_length(const uint8_t *buf, int size, int type)
>       return size;
>   }
>   
> +struct AV1RawTimingInfo;
> +
> +AVRational ff_av1_framerate(const struct AV1RawTimingInfo *ti);
> +
>   #endif /* AVCODEC_AV1_PARSE_H */
> diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
> index 14dae92fe9..978bbebe30 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,8 @@ 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(&seq->timing_info);
>   
>   end:
>       ff_cbs_fragment_reset(td);
> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> index c90c9c1a69..693673b436 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,8 @@ 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(&seq->timing_info);
>   
>       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".

  reply	other threads:[~2023-05-10 11:52 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: fix computing video frame duration from repeat_pict Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 03/13] lavc/codec_desc: add a property for codecs that support field coding Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate Anton Khirnov
2023-05-08 14:12   ` Michael Niedermayer
2023-05-09  8:37     ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2023-05-08 14:15   ` [FFmpeg-devel] [PATCH " Michael Niedermayer
2023-05-09  8:44     ` Anton Khirnov
2023-05-15 18:59       ` Michael Niedermayer
2023-05-15 20:44         ` Anton Khirnov
2023-05-16 17:41           ` Michael Niedermayer
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 05/13] lavc/av1*: fix exporting framerate Anton Khirnov
2023-05-10 11:52   ` James Almer [this message]
2023-05-14 19:39     ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2023-05-14 19:50       ` James Almer
2023-05-15  8:22         ` Anton Khirnov
2023-05-15 11:41           ` James Almer
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 06/13] lavc/libdav1d: " Anton Khirnov
2023-05-15  8:22   ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2023-05-15 11:47     ` James Almer
2023-05-15 12:22       ` Anton Khirnov
2023-05-15 12:41         ` James Almer
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 07/13] lavc/ratecontrol: use AVCodecContext.framerate when available Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 08/13] lavc/msmpeg4enc: " Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 09/13] libaomenc: " Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 10/13] lavc/libkvazaar, libopenh264enc: drop redundant checks Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 11/13] lavc/libvpxenc: send frame durations to the encoder Anton Khirnov
2023-05-09  1:18   ` James Zern
2023-05-09  9:09     ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2023-05-09 18:17       ` James Zern
2023-05-10  6:34         ` Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 12/13] lavc: deprecate AVCodecContext.ticks_per_frame Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: stop using deprecated ticks_per_frame Anton Khirnov
2023-05-07 16:59 ` [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Kieran Kunhya
2023-05-07 18:01   ` Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aefc137d-3a2d-265f-c842-c5a051900ec8@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git