[FFmpeg-devel] [PATCH] lavf/matroska: Adding support for Opus CodecDelay

Vignesh Venkatasubramanian vigneshv at google.com
Thu Aug 29 21:27:52 CEST 2013


In order to represent the codec delay accurately in Matroska, a
new element CodecDelay has been introduced. It contains the
overall delay added by the codec in nanoseconds. This patch adds
support for muxing CodecDelay value in the container.
Matroska spec for CodecDelay element can be found here:
http://matroska.org/technical/specs/index.html#CodecDelay

Signed-off-by: Vignesh Venkatasubramanian <vigneshv at google.com>
---
 libavformat/matroska.h    | 1 +
 libavformat/matroskaenc.c | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/libavformat/matroska.h b/libavformat/matroska.h
index 7cf423c..2c72d3e 100644
--- a/libavformat/matroska.h
+++ b/libavformat/matroska.h
@@ -91,6 +91,7 @@
 #define MATROSKA_ID_CODECINFOURL 0x3B4040
 #define MATROSKA_ID_CODECDOWNLOADURL 0x26B240
 #define MATROSKA_ID_CODECDECODEALL 0xAA
+#define MATROSKA_ID_CODECDELAY 0x56AA
 #define MATROSKA_ID_SEEKPREROLL 0x56BB
 #define MATROSKA_ID_TRACKNAME  0x536E
 #define MATROSKA_ID_TRACKLANGUAGE 0x22B59C
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 92df6cb..70e793b 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -649,6 +649,11 @@ static int mkv_write_tracks(AVFormatContext *s)
 
         if (codec->codec_id == AV_CODEC_ID_OPUS) {
             put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL);
+            uint64_t codec_delay =av_rescale_q(codec->delay,
+                                               (AVRational){1, codec->sample_rate},
+                                               (AVRational){1, 1000000000});
+            put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codec_delay);
+
         }
 
         if (mkv->mode == MODE_WEBM && !(codec->codec_id == AV_CODEC_ID_VP8 ||
-- 
1.8.4



More information about the ffmpeg-devel mailing list