summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2016-05-27 12:04:29 +0200
committerAnton Khirnov <anton@khirnov.net>2016-05-30 17:08:56 +0200
commitd6922bb17a75217a882215b82b0603e6b2cc7c01 (patch)
treee8ccb96a1e6f840e046a46d72d14e0be27832bc8
parentf9f1dab39f89db1c822aec9888c1dd5a14cf762f (diff)
avconv: do packet ts rescaling in write_packet()
This will be useful in the following commit, after which the muxer timebase is not always available when encoding.
-rw-r--r--avconv.c23
-rw-r--r--avconv.h2
2 files changed, 14 insertions, 11 deletions
diff --git a/avconv.c b/avconv.c
index 1335ef30ec..019ec18821 100644
--- a/avconv.c
+++ b/avconv.c
@@ -306,7 +306,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
if (ost->frame_rate.num) {
pkt->duration = av_rescale_q(1, av_inv_q(ost->frame_rate),
- ost->st->time_base);
+ ost->mux_timebase);
}
}
@@ -333,6 +333,8 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
ost->packets_written++;
pkt->stream_index = ost->index;
+ av_packet_rescale_ts(pkt, ost->mux_timebase, ost->st->time_base);
+
ret = av_interleaved_write_frame(s, pkt);
if (ret < 0) {
print_error("av_interleaved_write_frame()", ret);
@@ -425,7 +427,6 @@ static void do_audio_out(OutputFile *of, OutputStream *ost,
if (ret < 0)
goto error;
- av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base);
output_packet(of, &pkt, ost);
}
@@ -491,7 +492,7 @@ static void do_subtitle_out(OutputFile *of,
av_init_packet(&pkt);
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.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, 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 */
@@ -576,7 +577,6 @@ static void do_video_out(OutputFile *of,
if (ret < 0)
goto error;
- av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base);
output_packet(of, &pkt, ost);
*frame_size = pkt.size;
@@ -967,7 +967,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
vid = 1;
}
/* compute min output value */
- pts = (double)ost->last_mux_dts * av_q2d(ost->st->time_base);
+ pts = (double)ost->last_mux_dts * av_q2d(ost->mux_timebase);
if ((pts < ti1) && (pts > 0))
ti1 = pts;
}
@@ -1046,7 +1046,6 @@ static void flush_encoders(void)
stop_encoding = 1;
break;
}
- av_packet_rescale_ts(&pkt, enc->time_base, ost->st->time_base);
output_packet(of, &pkt, ost);
}
@@ -1078,7 +1077,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
OutputFile *of = output_files[ost->file_index];
InputFile *f = input_files [ist->file_index];
int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
- int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->st->time_base);
+ int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase);
AVPacket opkt;
av_init_packet(&opkt);
@@ -1108,17 +1107,17 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
ost->sync_opts++;
if (pkt->pts != AV_NOPTS_VALUE)
- opkt.pts = av_rescale_q(pkt->pts, ist->st->time_base, ost->st->time_base) - ost_tb_start_time;
+ opkt.pts = av_rescale_q(pkt->pts, ist->st->time_base, ost->mux_timebase) - ost_tb_start_time;
else
opkt.pts = AV_NOPTS_VALUE;
if (pkt->dts == AV_NOPTS_VALUE)
- opkt.dts = av_rescale_q(ist->last_dts, AV_TIME_BASE_Q, ost->st->time_base);
+ opkt.dts = av_rescale_q(ist->last_dts, AV_TIME_BASE_Q, ost->mux_timebase);
else
- opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->st->time_base);
+ opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->mux_timebase);
opkt.dts -= ost_tb_start_time;
- opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->st->time_base);
+ opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->mux_timebase);
opkt.flags = pkt->flags;
// FIXME remove the following 2 lines they shall be replaced by the bitstream filters
@@ -2099,6 +2098,8 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
if (ret < 0)
return ret;
+ ost->mux_timebase = ost->st->time_base;
+
ost->initialized = 1;
ret = check_init_output_file(output_files[ost->file_index], ost->file_index);
diff --git a/avconv.h b/avconv.h
index 163919723e..56a0282c16 100644
--- a/avconv.h
+++ b/avconv.h
@@ -353,6 +353,8 @@ typedef struct OutputStream {
int64_t first_pts;
/* dts of the last packet sent to the muxer */
int64_t last_mux_dts;
+ // the timebase of the packets sent to the muxer
+ AVRational mux_timebase;
int nb_bitstream_filters;
const AVBitStreamFilter **bitstream_filters;