From: Anton Khirnov
This will be useful in the following commit, after which the muxer
timebase is not always available when encoding.
This merges Libav commit 3e265ca. It was previously skipped.
There is a minor change with setting the mux_timebase field only after
the muxer's write_header function has been called, because it can
readjust the timebase.
Includes a minor merge fix by Mark Thompson, and
avconv: Move rescale to stream timebase before monotonisation
also by Mark Thompson .
Signed-off-by: wm4
---
ffmpeg.c | 39 ++-
ffmpeg.h | 2 ++
2 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/ffmpeg.c b/ffmpeg.c
index 913c18d92b..2876e43b32 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -713,10 +713,12 @@ static void write_packet(OutputFile *of, AVPacket *pkt,
OutputStream *ost)
if (pkt->duration > 0)
av_log(NULL, AV_LOG_WARNING, "Overriding packet duration by
frame rate, this should not happen\n");
pkt->duration = av_rescale_q(1, av_inv_q(ost->frame_rate),
- ost->st->time_base);
+ ost->mux_timebase);
}
}
+av_packet_rescale_ts(pkt, ost->mux_timebase, ost->st->time_base);
+
if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
if (pkt->dts != AV_NOPTS_VALUE &&
pkt->pts != AV_NOPTS_VALUE &&
@@ -907,13 +909,13 @@ static void do_audio_out(OutputFile *of, OutputStream
*ost,
update_benchmark("encode_audio %d.%d", ost->file_index, ost->index);
-av_packet_rescale_ts(, enc->time_base, ost->st->time_base);
+av_packet_rescale_ts(, enc->time_base, ost->mux_timebase);
if (debug_ts) {
av_log(NULL, AV_LOG_INFO, "encoder -> type:audio "
"pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
- av_ts2str(pkt.pts), av_ts2timestr(pkt.pts,
>st->time_base),
- av_ts2str(pkt.dts), av_ts2timestr(pkt.dts,
>st->time_base));
+ av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, >time_base),
+ av_ts2str(pkt.dts), av_ts2timestr(pkt.dts,
>time_base));
}
output_packet(of, , ost);
@@ -993,8 +995,8 @@ static void do_subtitle_out(OutputFile *of,
av_init_packet();
pkt.data = subtitle_out;
pkt.size = subtitle_out_size;
-pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base);
-pkt.duration = av_rescale_q(sub->end_display_time, (AVRational){ 1,
1000 }, ost->st->time_base);
+pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->mux_timebase);
+pkt.duration = av_rescale_q(sub->end_display_time, (AVRational){ 1,
1000 }, ost->mux_timebase);
if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) {
/* XXX: the pts correction is handled here. Maybe handling
it in the codec would be better */
@@ -1187,7 +1189,7 @@ static void do_video_out(OutputFile *of,
mux_par->field_order = AV_FIELD_PROGRESSIVE;
pkt.data = (uint8_t *)in_picture;
pkt.size = sizeof(AVPicture);
-pkt.pts= av_rescale_q(in_picture->pts, enc->time_base,
ost->st->time_base);
+pkt.pts= av_rescale_q(in_picture->pts, enc->time_base,
ost->mux_timebase);
pkt.flags |= AV_PKT_FLAG_KEY;
output_packet(of, , ost);
@@ -1283,13 +1285,13 @@ static void do_video_out(OutputFile *of,
if (pkt.pts == AV_NOPTS_VALUE && !(enc->codec->capabilities &
AV_CODEC_CAP_DELAY))
pkt.pts = ost->sync_opts;
-av_packet_rescale_ts(, enc->time_base, ost->st->time_base);
+av_packet_rescale_ts(, enc->time_base, ost->mux_timebase);
if (debug_ts) {
av_log(NULL, AV_LOG_INFO, "encoder -> type:video "
"pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
-av_ts2str(pkt.pts), av_ts2timestr(pkt.pts,
>st->time_base),
-av_ts2str(pkt.dts), av_ts2timestr(pkt.dts,
>st->time_base));
+av_ts2str(pkt.pts), av_ts2timestr(pkt.pts,
>mux_timebase),
+av_ts2str(pkt.dts), av_ts2timestr(pkt.dts,
>mux_timebase));
}
frame_size = pkt.size;
@@ -1862,8 +1864,8 @@ static void flush_encoders(void)
av_packet_unref();
continue;
}
-av_packet_rescale_ts(, enc->time_base, ost->st->time_base);
pkt_size = pkt.size;
+av_packet_rescale_ts(, enc->time_base, ost->mux_timebase);
output_packet(of, , ost);
if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO &&
vstats_filename) {
do_video_stats(ost, pkt_size);
@@ -1897,7 +1899,7 @@ static void