diff mbox series

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

Message ID 20230826151144.24858-3-anton@khirnov.net
State Accepted
Commit ed5caaaf221bda5b4efbe8a3631d0a3438b0d32c
Headers show
Series [FFmpeg-devel,01/18] fftools/ffmpeg: stop explicitly closing output streams on input EOF | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Aug. 26, 2023, 3:11 p.m. UTC
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 mbox series

Patch

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;