Browse code

Merge commit '9455a023be9f3915ccf5511a0b8fdb5b8897b2b6' into release/1.1

* commit '9455a023be9f3915ccf5511a0b8fdb5b8897b2b6':
matroskaenc: do not write negative timestamps

Conflicts:
tests/ref/lavf/mkv
tests/ref/seek/lavf-mkv

No change to fate as ffmpeg was not affected by these bugs

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2014/06/20 07:48:51
Showing 1 changed files
... ...
@@ -95,6 +95,8 @@ typedef struct MatroskaMuxContext {
95 95
     AVPacket        cur_audio_pkt;
96 96
 
97 97
     int have_attachments;
98
+
99
+    int64_t ts_offset;
98 100
 } MatroskaMuxContext;
99 101
 
100 102
 
... ...
@@ -1265,9 +1267,18 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
1265 1265
     AVIOContext *pb = s->pb->seekable ? s->pb : mkv->dyn_bc;
1266 1266
     AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
1267 1267
     int ret, keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY);
1268
-    int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts;
1268
+    int64_t ts;
1269 1269
     int cluster_size = avio_tell(pb) - (s->pb->seekable ? mkv->cluster_pos : 0);
1270 1270
 
1271
+    if (pkt->dts < 0 && !mkv->ts_offset)
1272
+        mkv->ts_offset = -pkt->dts;
1273
+
1274
+    pkt->dts += mkv->ts_offset;
1275
+    if (pkt->pts != AV_NOPTS_VALUE)
1276
+        pkt->pts += mkv->ts_offset;
1277
+
1278
+    ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts;
1279
+
1271 1280
     // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or
1272 1281
     // after 4k and on a keyframe
1273 1282
     if (mkv->cluster_pos != -1 &&