[FFmpeg-cvslog] fftools/ffmpeg: convert timestamps inside the muxer

Anton Khirnov git at videolan.org
Mon Jun 5 17:31:15 EEST 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sun May 28 10:25:45 2023 +0200| [d7781cfb95b1a4732456e82deca7e59b9ac18714] | committer: Anton Khirnov

fftools/ffmpeg: convert timestamps inside the muxer

Packets submitted to the muxer now have their timebase attached to them,
so the muxer can do conversion to muxing timebase and avoid exposing it
to callers.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d7781cfb95b1a4732456e82deca7e59b9ac18714
---

 fftools/ffmpeg_enc.c | 17 ++---------------
 fftools/ffmpeg_mux.c |  6 ++++++
 2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 1b0410ae74..f6431b29d1 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -512,8 +512,8 @@ void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub)
         }
 
         av_shrink_packet(pkt, subtitle_out_size);
-        pkt->time_base = ost->mux_timebase;
-        pkt->pts  = av_rescale_q(sub->pts, AV_TIME_BASE_Q, pkt->time_base);
+        pkt->time_base = AV_TIME_BASE_Q;
+        pkt->pts       = sub->pts;
         pkt->duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, pkt->time_base);
         if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
             /* XXX: the pts correction is handled here. Maybe handling
@@ -735,19 +735,6 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
                    av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base));
         }
 
-        av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase);
-        pkt->time_base = ost->mux_timebase;
-
-        if (debug_ts) {
-            av_log(ost, AV_LOG_INFO, "encoder -> type:%s "
-                   "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s "
-                   "duration:%s duration_time:%s\n",
-                   type_desc,
-                   av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &enc->time_base),
-                   av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &enc->time_base),
-                   av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base));
-        }
-
         if ((ret = trigger_fix_sub_duration_heartbeat(ost, pkt)) < 0) {
             av_log(NULL, AV_LOG_ERROR,
                    "Subtitle heartbeat logic failed in %s! (%s)\n",
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 121796a55a..dc2d189ff0 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -334,6 +334,12 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
     if (!eof && 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 (!eof) {
+        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;



More information about the ffmpeg-cvslog mailing list