[FFmpeg-cvslog] matroskaenc: factor ts_offset into block timecode computation

John Stebbins git at videolan.org
Mon Oct 2 21:43:01 EEST 2017


ffmpeg | branch: master | John Stebbins <stebbins at jetheaddev.com> | Wed Feb 15 15:22:40 2017 -0700| [5d3953a5dcfd5f71391b7f34908517eb6f7e5146] | committer: John Stebbins

matroskaenc: factor ts_offset into block timecode computation

ts_offset was added to cluster timecode, but then effectively subtracted
back off the block timecode

When setting initial_padding for an audio stream, the timestamps are
written incorrectly to the mkv file.  cluster timecode gets written
as pts0 + ts_offset which is correct, but then block timecode gets
written as pts - cluster timecode which expanded is
pts - (pts0 + ts_offset).  Adding cluster and block tc back together:
cluster + block = (pts0 + ts_offset) + (pts - (pts0 + ts_offset)) = pts
But the result should be pts + ts_offset since demux will subtract the
CodecDelay element from pts and set initial_padding to CodecDelay.
This patch gives the correct result.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5d3953a5dcfd5f71391b7f34908517eb6f7e5146
---

 libavformat/matroskaenc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index e951a0fb67..2fe6e0ed49 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1461,6 +1461,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb,
     uint8_t *data = NULL;
     int offset = 0, size = pkt->size;
     int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts;
+    ts += mkv->tracks[pkt->stream_index].ts_offset;
 
     av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, "
            "pts %" PRId64 ", dts %" PRId64 ", duration %" PRId64 ", flags %d\n",



More information about the ffmpeg-cvslog mailing list