[FFmpeg-devel] [PATCH 03/18] fftools/ffmpeg_mux: use correct timebases for bitstream filtering

Anton Khirnov anton at khirnov.net
Sat Aug 26 18:11:29 EEST 2023


Bitstream filtering input timebase is not always necessarily equal to
OutputStream.mux_timebase. Also, set AVPacket.time_base correctly for
packets output by bitstream filters

Do not rescale at all in of_output_packet() when not doing bitstream
filtering, as it's unnecessary - write_packet() will rescale to the
actual muxer timebase.
---
 fftools/ffmpeg_mux.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 24cdf00469..ab9bb398c1 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -340,16 +340,13 @@ int of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
     if (pkt && pkt->dts != AV_NOPTS_VALUE)
         ost->last_mux_dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q);
 
-    /* rescale timestamps to the muxing timebase */
-    if (pkt) {
-        av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase);
-        pkt->time_base = ost->mux_timebase;
-    }
-
     /* apply the output bitstream filters */
     if (ms->bsf_ctx) {
         int bsf_eof = 0;
 
+        if (pkt)
+            av_packet_rescale_ts(pkt, pkt->time_base, ms->bsf_ctx->time_base_in);
+
         ret = av_bsf_send_packet(ms->bsf_ctx, pkt);
         if (ret < 0) {
             err_msg = "submitting a packet for bitstream filtering";
@@ -367,6 +364,9 @@ int of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
                 goto fail;
             }
 
+            if (!bsf_eof)
+                ms->bsf_pkt->time_base = ms->bsf_ctx->time_base_out;
+
             ret = submit_packet(mux, bsf_eof ? NULL : ms->bsf_pkt, ost);
             if (ret < 0)
                 goto mux_fail;
-- 
2.40.1



More information about the ffmpeg-devel mailing list