diff mbox series

[FFmpeg-devel,08/13] fftools/ffmpeg_enc: don't write frame rate/SAR to AVStream directly

Message ID 20240924071000.11428-8-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/13] doc/ffmpeg; improve wording in the description section | expand

Commit Message

Anton Khirnov Sept. 24, 2024, 7:09 a.m. UTC
Have the muxer code read them out of the encoder context in
of_stream_init() instead.

This is a step towards decoupling encoders from muxers.
---
 fftools/ffmpeg_enc.c | 3 +--
 fftools/ffmpeg_mux.c | 3 +++
 2 files changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1be0a37353..4b3efb8db1 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -206,7 +206,6 @@  int enc_open(void *opaque, const AVFrame *frame)
     if (ost->type == AVMEDIA_TYPE_AUDIO || ost->type == AVMEDIA_TYPE_VIDEO) {
         enc_ctx->time_base      = frame->time_base;
         enc_ctx->framerate      = fd->frame_rate_filter;
-        ost->st->avg_frame_rate = fd->frame_rate_filter;
     }
 
     switch (enc_ctx->codec_type) {
@@ -233,7 +232,7 @@  int enc_open(void *opaque, const AVFrame *frame)
                    frame->height > 0);
         enc_ctx->width  = frame->width;
         enc_ctx->height = frame->height;
-        enc_ctx->sample_aspect_ratio = ost->st->sample_aspect_ratio =
+        enc_ctx->sample_aspect_ratio =
             ost->frame_aspect_ratio.num ? // overridden by the -aspect cli option
             av_mul_q(ost->frame_aspect_ratio, (AVRational){ enc_ctx->height, enc_ctx->width }) :
             frame->sample_aspect_ratio;
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index ea0bbeed32..d38f1ec317 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -620,6 +620,9 @@  int of_stream_init(OutputFile *of, OutputStream *ost,
         if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0)
             ost->st->time_base = av_add_q(enc_ctx->time_base, (AVRational){0, 1});
 
+        ost->st->avg_frame_rate = enc_ctx->framerate;
+        ost->st->sample_aspect_ratio = enc_ctx->sample_aspect_ratio;
+
         ret = avcodec_parameters_from_context(ms->par_in, enc_ctx);
         if (ret < 0) {
             av_log(ost, AV_LOG_FATAL,