[FFmpeg-cvslog] matroskadec: read the CodecDelay element

Anton Khirnov git at videolan.org
Sun May 4 21:26:28 CEST 2014


ffmpeg | branch: release/2.2 | Anton Khirnov <anton at khirnov.net> | Tue Apr 29 12:03:13 2014 +0200| [82cebc0e0544dce507749dd9b1c2983f083de836] | committer: Reinhard Tartler

matroskadec: read the CodecDelay element

(cherry picked from commit eb3b5501e8b85bfea09d533314cb6920efc42639)
Signed-off-by: Reinhard Tartler <siretart at tauware.de>

Conflicts:
	libavformat/matroskadec.c

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

 libavformat/matroska.h    |    1 +
 libavformat/matroskadec.c |   10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavformat/matroska.h b/libavformat/matroska.h
index 0dbc724..667f92a 100644
--- a/libavformat/matroska.h
+++ b/libavformat/matroska.h
@@ -86,6 +86,7 @@
 #define MATROSKA_ID_CODECINFOURL 0x3B4040
 #define MATROSKA_ID_CODECDOWNLOADURL 0x26B240
 #define MATROSKA_ID_CODECDECODEALL 0xAA
+#define MATROSKA_ID_CODECDELAY 0x56AA
 #define MATROSKA_ID_TRACKNAME  0x536E
 #define MATROSKA_ID_TRACKLANGUAGE 0x22B59C
 #define MATROSKA_ID_TRACKFLAGENABLED 0xB9
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index bcd7d1a..8aae26c 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -44,6 +44,7 @@
 #include "libavutil/avstring.h"
 #include "libavutil/lzo.h"
 #include "libavutil/dict.h"
+#include "libavutil/mathematics.h"
 #if CONFIG_ZLIB
 #include <zlib.h>
 #endif
@@ -148,6 +149,7 @@ typedef struct {
     MatroskaTrackVideo video;
     MatroskaTrackAudio audio;
     EbmlList encodings;
+    uint64_t codec_delay;
 
     AVStream *stream;
     int64_t end_timecode;
@@ -348,6 +350,7 @@ static EbmlSyntax matroska_track[] = {
     { MATROSKA_ID_TRACKTYPE,            EBML_UINT, 0, offsetof(MatroskaTrack,type) },
     { MATROSKA_ID_CODECID,              EBML_STR,  0, offsetof(MatroskaTrack,codec_id) },
     { MATROSKA_ID_CODECPRIVATE,         EBML_BIN,  0, offsetof(MatroskaTrack,codec_priv) },
+    { MATROSKA_ID_CODECDELAY,           EBML_UINT, 0, offsetof(MatroskaTrack, codec_delay) },
     { MATROSKA_ID_TRACKLANGUAGE,        EBML_UTF8, 0, offsetof(MatroskaTrack,language), {.s="eng"} },
     { MATROSKA_ID_TRACKDEFAULTDURATION, EBML_UINT, 0, offsetof(MatroskaTrack,default_duration) },
     { MATROSKA_ID_TRACKTIMECODESCALE,   EBML_FLOAT,0, offsetof(MatroskaTrack,time_scale), {.f=1.0} },
@@ -1658,6 +1661,11 @@ static int matroska_read_header(AVFormatContext *s)
             track->time_scale = 1.0;
         avpriv_set_pts_info(st, 64, matroska->time_scale*track->time_scale, 1000*1000*1000); /* 64 bit pts in ns */
 
+        /* convert the delay from ns to the track timebase */
+        track->codec_delay = av_rescale_q(track->codec_delay,
+                                          (AVRational){ 1, 1000000000 },
+                                          st->time_base);
+
         st->codec->codec_id = codec_id;
         st->start_time = 0;
         if (strcmp(track->language, "und"))
@@ -2190,7 +2198,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
 
     if (cluster_time != (uint64_t)-1
         && (block_time >= 0 || cluster_time >= -block_time)) {
-        timecode = cluster_time + block_time;
+        timecode = cluster_time + block_time - track->codec_delay;
         if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE
             && timecode < track->end_timecode)
             is_keyframe = 0;  /* overlapping subtitles are not key frame */



More information about the ffmpeg-cvslog mailing list