From 97314892eda53ec983d682259e57c8725bf94c08 Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Tue, 23 Jul 2024 09:52:48 -0500 Subject: [PATCH] Populate avg_frame_rate --- av/av_stubs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/av/av_stubs.c b/av/av_stubs.c index 340d48a..3c0f4aa 100644 --- a/av/av_stubs.c +++ b/av/av_stubs.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "av_stubs.h" #include "avcodec_stubs.h" @@ -1739,6 +1740,7 @@ static void init_stream_encoder(AVBufferRef *device_ctx, AVBufferRef *frame_ctx, av_t *av, stream_t *stream, AVDictionary **options) { AVCodecContext *enc_ctx = stream->codec_context; + AVDictionaryEntry *framerate; int ret; // Some formats want stream headers to be separate. @@ -1773,6 +1775,11 @@ static void init_stream_encoder(AVBufferRef *device_ctx, AVBufferRef *frame_ctx, AVStream *avstream = av->format_context->streams[stream->index]; avstream->time_base = enc_ctx->time_base; + framerate = av_dict_get(*options, "r", NULL, 0); + + if (framerate) + av_parse_video_rate(&avstream->avg_frame_rate, framerate->value); + ret = avcodec_parameters_from_context(avstream->codecpar, enc_ctx); if (ret < 0) { @@ -1818,12 +1825,13 @@ CAMLprim value ocaml_av_initialize_stream_copy(value _av, value _stream_index, av_t *av = Av_val(_av); AVStream *avstream = av->format_context->streams[Int_val(_stream_index)]; + AVCodecParameters *params = CodecParameters_val(_params); - int err = - avcodec_parameters_copy(avstream->codecpar, CodecParameters_val(_params)); + int err = avcodec_parameters_copy(avstream->codecpar, params); if (err < 0) ocaml_avutil_raise_error(err); + avstream->avg_frame_rate = params->framerate; avstream->codecpar->codec_tag = 0; CAMLreturn(Val_unit);