summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-04-26 11:37:42 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-04-26 14:51:47 +0200
commit060f14f493104e049481f12e9dc21330801bd137 (patch)
tree836145bde0fba101c03dff666debac06f3f8d004 /libavformat
parent30579b7ef01382845a9af03b2dd5ac6689c139d4 (diff)
avformat/mux: change avoid_negative_ts code to support later addition of AVStreams
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/mux.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 1529eec468..1e183096a2 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -495,22 +495,26 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
*/
static int write_packet(AVFormatContext *s, AVPacket *pkt)
{
- int ret, did_split, i;
+ int ret, did_split;
if (s->avoid_negative_ts > 0) {
AVStream *st = s->streams[pkt->stream_index];
- if (pkt->dts != AV_NOPTS_VALUE) {
- if (!st->mux_ts_offset && pkt->dts < 0) {
- for (i = 0; i < s->nb_streams; i++) {
- s->streams[i]->mux_ts_offset =
- av_rescale_q_rnd(-pkt->dts,
- st->time_base,
- s->streams[i]->time_base,
- AV_ROUND_UP);
- }
- }
- pkt->dts += st->mux_ts_offset;
+
+ if (pkt->dts < 0 && pkt->dts != AV_NOPTS_VALUE && !s->offset) {
+ s->offset = -pkt->dts;
+ s->offset_timebase = st->time_base;
}
+
+ if (s->offset && !st->mux_ts_offset) {
+ st->mux_ts_offset =
+ av_rescale_q_rnd(s->offset,
+ s->offset_timebase,
+ st->time_base,
+ AV_ROUND_UP);
+ }
+
+ if (pkt->dts != AV_NOPTS_VALUE)
+ pkt->dts += st->mux_ts_offset;
if (pkt->pts != AV_NOPTS_VALUE)
pkt->pts += st->mux_ts_offset;
}