diff options
author | Anton Khirnov <anton@khirnov.net> | 2014-04-29 12:26:38 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2014-05-01 08:03:51 +0200 |
commit | a1aa37dd0b96710d4a17718198a3f56aea2040c1 (patch) | |
tree | 7adc90439f65ddcb799f6229c56eeae5ea5be3d7 /libavformat | |
parent | 1c0210c7981b6a61043d9171f506b435ff5a1f5e (diff) | |
download | ffmpeg-a1aa37dd0b96710d4a17718198a3f56aea2040c1.tar.gz |
matroskaenc: write CodecDelay
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/matroskaenc.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index fad1ec41cc..d2e3ae4979 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -78,6 +78,7 @@ typedef struct { typedef struct { int write_dts; + int64_t ts_offset; } mkv_track; #define MODE_MATROSKAv2 0x01 @@ -600,6 +601,16 @@ static int mkv_write_tracks(AVFormatContext *s) if (!(st->disposition & AV_DISPOSITION_DEFAULT)) put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT)); + if (codec->codec_type == AVMEDIA_TYPE_AUDIO && codec->delay) { + mkv->tracks[i].ts_offset = av_rescale_q(codec->delay, + (AVRational){ 1, codec->sample_rate }, + st->time_base); + + put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, + av_rescale_q(codec->delay, (AVRational){ 1, codec->sample_rate }, + (AVRational){ 1, 1000000000 })); + } + // look for a codec ID string specific to mkv to use, // if none are found, use AVI codes for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) { @@ -1261,6 +1272,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt) av_log(s, AV_LOG_ERROR, "Can't write packet with unknown timestamp\n"); return AVERROR(EINVAL); } + ts += mkv->tracks[pkt->stream_index].ts_offset; if (!s->pb->seekable) { if (!mkv->dyn_bc) @@ -1312,6 +1324,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) cluster_time = pkt->dts - mkv->cluster_pts; else cluster_time = pkt->pts - mkv->cluster_pts; + cluster_time += mkv->tracks[pkt->stream_index].ts_offset; // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or // after 4k and on a keyframe |