aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2024-09-10 10:55:28 +0200
committerAnton Khirnov <anton@khirnov.net>2024-09-26 18:25:21 +0200
commit238f439992f7e77609c2dc7ab6230da756c460b8 (patch)
tree4ff7b811fd563bca9f039ff13ab212bccca567f4
parent1ebd521a4e503c1e4697273a984e6de2c5f8886d (diff)
downloadffmpeg-238f439992f7e77609c2dc7ab6230da756c460b8.tar.gz
fftools/ffmpeg_enc: do not set AVStream timebase directly
Instead, pass the encoder context to of_stream_init() and have the muxer take the timebase from there. Note that the muxer can currently access the codec context directly, but that will change in future commits. This is a step towards decoupling encoders from muxers.
-rw-r--r--fftools/ffmpeg.h3
-rw-r--r--fftools/ffmpeg_enc.c6
-rw-r--r--fftools/ffmpeg_mux.c9
-rw-r--r--fftools/ffmpeg_mux_init.c2
4 files changed, 12 insertions, 8 deletions
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 122372440f..98080213fd 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -871,7 +871,8 @@ int enc_loopback(Encoder *enc);
*
* Open the muxer once all the streams have been initialized.
*/
-int of_stream_init(OutputFile *of, OutputStream *ost);
+int of_stream_init(OutputFile *of, OutputStream *ost,
+ const AVCodecContext *enc_ctx);
int of_write_trailer(OutputFile *of);
int of_open(const OptionsContext *o, const char *filename, Scheduler *sch);
void of_free(OutputFile **pof);
diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index c11ec218d7..ba79f6a3fc 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -367,11 +367,7 @@ int enc_open(void *opaque, const AVFrame *frame)
return ret;
}
- // copy timebase while removing common factors
- if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0)
- ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1});
-
- ret = of_stream_init(of, ost);
+ ret = of_stream_init(of, ost, enc_ctx);
if (ret < 0)
return ret;
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 71ff9b45ab..71a771052f 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -608,12 +608,19 @@ static int bsf_init(MuxStream *ms)
return 0;
}
-int of_stream_init(OutputFile *of, OutputStream *ost)
+int of_stream_init(OutputFile *of, OutputStream *ost,
+ const AVCodecContext *enc_ctx)
{
Muxer *mux = mux_from_of(of);
MuxStream *ms = ms_from_ost(ost);
int ret;
+ if (enc_ctx) {
+ // use upstream time base unless it has been overridden previously
+ 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});
+ }
+
/* initialize bitstream filters for the output stream
* needs to be done here, because the codec id for streamcopy is not
* known until now */
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 1b75430e4e..b2351de177 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -3385,7 +3385,7 @@ int of_open(const OptionsContext *o, const char *filename, Scheduler *sch)
OutputStream *ost = of->streams[i];
if (!ost->enc) {
- err = of_stream_init(of, ost);
+ err = of_stream_init(of, ost, NULL);
if (err < 0)
return err;
}