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.
This commit is contained in:
Anton Khirnov 2023-05-28 10:25:45 +02:00
parent cf121592c5
commit d7781cfb95
2 changed files with 8 additions and 15 deletions

View File

@ -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",

View File

@ -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;