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 | |
parent | 1c0210c7981b6a61043d9171f506b435ff5a1f5e (diff) | |
download | ffmpeg-a1aa37dd0b96710d4a17718198a3f56aea2040c1.tar.gz |
matroskaenc: write CodecDelay
-rw-r--r-- | libavformat/matroskaenc.c | 13 | ||||
-rw-r--r-- | tests/ref/lavf/mkv | 6 | ||||
-rw-r--r-- | tests/ref/seek/lavf-mkv | 44 |
3 files changed, 38 insertions, 25 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 diff --git a/tests/ref/lavf/mkv b/tests/ref/lavf/mkv index 2bf1543f74..048619f0d9 100644 --- a/tests/ref/lavf/mkv +++ b/tests/ref/lavf/mkv @@ -1,3 +1,3 @@ -7c21e1e6b4fe71f361564f8eebedf4e1 *./tests/data/lavf/lavf.mkv -320268 ./tests/data/lavf/lavf.mkv -./tests/data/lavf/lavf.mkv CRC=0x7d5d3cda +753261b6299d2ef36cfba70f6e6fa848 *./tests/data/lavf/lavf.mkv +320275 ./tests/data/lavf/lavf.mkv +./tests/data/lavf/lavf.mkv CRC=0xbe7d3cda diff --git a/tests/ref/seek/lavf-mkv b/tests/ref/seek/lavf-mkv index f57516563c..cbff3d98ea 100644 --- a/tests/ref/seek/lavf-mkv +++ b/tests/ref/seek/lavf-mkv @@ -1,53 +1,53 @@ -ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 518 size: 208 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 525 size: 208 ret: 0 st:-1 flags:0 ts:-1.000000 -ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 734 size: 27837 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 525 size: 208 ret: 0 st:-1 flags:1 ts: 1.894167 -ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292156 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292163 size: 27834 ret: 0 st: 0 flags:0 ts: 0.788000 -ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292156 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292163 size: 27834 ret: 0 st: 0 flags:1 ts:-0.317000 -ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 734 size: 27837 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 525 size: 208 ret: 0 st: 1 flags:0 ts: 2.577000 ret:-EOF ret: 0 st: 1 flags:1 ts: 1.471000 -ret: 0 st: 1 flags:1 dts: 0.993000 pts: 0.993000 pos: 319997 size: 209 +ret: 0 st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320004 size: 209 ret: 0 st:-1 flags:0 ts: 0.365002 -ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 146709 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 146716 size: 27925 ret: 0 st:-1 flags:1 ts:-0.740831 -ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 734 size: 27837 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 525 size: 208 ret: 0 st: 0 flags:0 ts: 2.153000 ret:-EOF ret: 0 st: 0 flags:1 ts: 1.048000 -ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292156 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292163 size: 27834 ret: 0 st: 1 flags:0 ts:-0.058000 -ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 518 size: 208 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 525 size: 208 ret: 0 st: 1 flags:1 ts: 2.836000 -ret: 0 st: 1 flags:1 dts: 0.993000 pts: 0.993000 pos: 319997 size: 209 +ret: 0 st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320004 size: 209 ret: 0 st:-1 flags:0 ts: 1.730004 ret:-EOF ret: 0 st:-1 flags:1 ts: 0.624171 -ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 146709 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 146716 size: 27925 ret: 0 st: 0 flags:0 ts:-0.482000 -ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 734 size: 27837 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 525 size: 208 ret: 0 st: 0 flags:1 ts: 2.413000 -ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292156 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292163 size: 27834 ret: 0 st: 1 flags:0 ts: 1.307000 ret:-EOF ret: 0 st: 1 flags:1 ts: 0.201000 -ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 518 size: 208 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 525 size: 208 ret: 0 st:-1 flags:0 ts:-0.904994 -ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 734 size: 27837 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 525 size: 208 ret: 0 st:-1 flags:1 ts: 1.989173 -ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292156 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292163 size: 27834 ret: 0 st: 0 flags:0 ts: 0.883000 -ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292156 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.971000 pts: 0.971000 pos: 292163 size: 27834 ret: 0 st: 0 flags:1 ts:-0.222000 -ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 734 size: 27837 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 525 size: 208 ret: 0 st: 1 flags:0 ts: 2.672000 ret:-EOF ret: 0 st: 1 flags:1 ts: 1.566000 -ret: 0 st: 1 flags:1 dts: 0.993000 pts: 0.993000 pos: 319997 size: 209 +ret: 0 st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320004 size: 209 ret: 0 st:-1 flags:0 ts: 0.460008 -ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 146709 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.491000 pts: 0.491000 pos: 146716 size: 27925 ret: 0 st:-1 flags:1 ts:-0.645825 -ret: 0 st: 0 flags:1 dts: 0.011000 pts: 0.011000 pos: 734 size: 27837 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 525 size: 208 |