diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-08-31 15:02:00 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-09-05 20:33:09 +0200 |
commit | 7bacef580f81ab7a98401b9b05441115df36d86b (patch) | |
tree | b07a91b4048ab63357c7f88b05f3c8ee0d5fd61d | |
parent | c0279e67f18ab7bb4e071c08a231dd7d7821b278 (diff) | |
download | ffmpeg-7bacef580f81ab7a98401b9b05441115df36d86b.tar.gz |
avformat/matroskaenc: Only write DiscardPadding if nonzero
It is possible for the trailing padding to be zero, namely
e.g. if the AV_PKT_DATA_SKIP_SAMPLES side data is used
for leading padding. Matroska supports this (use a negative
DiscardPadding), but players do not; at least Firefox refuses
to play such a file. So for now only write DiscardPadding
if it is trailing padding and nonzero.
The fate-matroska-ogg-opus-remux was affected by this.
(I wish CodecDelay would not exist and DiscardPadding would
be used to instead trim the codec delay away (with the Block
timestamp corresponding to the time at which the actually
output audio is output).)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r-- | libavformat/matroskaenc.c | 12 | ||||
-rw-r--r-- | tests/ref/fate/matroska-ogg-opus-remux | 10 |
2 files changed, 12 insertions, 10 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 1256bdfe36..de6c993e6a 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2591,7 +2591,6 @@ static int mkv_write_block(void *logctx, MatroskaMuxContext *mkv, uint8_t *side_data; size_t side_data_size; uint64_t additional_id; - int64_t discard_padding = 0; unsigned track_number = track->track_num; EBML_WRITER(9); @@ -2619,10 +2618,13 @@ static int mkv_write_block(void *logctx, MatroskaMuxContext *mkv, AV_PKT_DATA_SKIP_SAMPLES, &side_data_size); if (side_data && side_data_size >= 10) { - discard_padding = av_rescale_q(AV_RL32(side_data + 4), - (AVRational){1, par->sample_rate}, - (AVRational){1, 1000000000}); - ebml_writer_add_sint(&writer, MATROSKA_ID_DISCARDPADDING, discard_padding); + int64_t discard_padding = AV_RL32(side_data + 4); + if (discard_padding) { + discard_padding = av_rescale_q(discard_padding, + (AVRational){1, par->sample_rate}, + (AVRational){1, 1000000000}); + ebml_writer_add_sint(&writer, MATROSKA_ID_DISCARDPADDING, discard_padding); + } } side_data = av_packet_get_side_data(pkt, diff --git a/tests/ref/fate/matroska-ogg-opus-remux b/tests/ref/fate/matroska-ogg-opus-remux index b69c29df8e..1fa776ef01 100644 --- a/tests/ref/fate/matroska-ogg-opus-remux +++ b/tests/ref/fate/matroska-ogg-opus-remux @@ -1,5 +1,5 @@ -605e8e89efb3028e261dd10255c7f59a *tests/data/fate/matroska-ogg-opus-remux.matroska -10207 tests/data/fate/matroska-ogg-opus-remux.matroska +a3f98769fe55bc5234cf75fb1949749a *tests/data/fate/matroska-ogg-opus-remux.matroska +10200 tests/data/fate/matroska-ogg-opus-remux.matroska #extradata 0: 19, 0x399c0471 #tb 0: 1/1000 #media_type 0: audio @@ -57,7 +57,7 @@ dts_time=-0.007000 duration=20 duration_time=0.020000 size=402 -pos=543 +pos=540 flags=K_ [/PACKET] [PACKET] @@ -70,7 +70,7 @@ dts_time=0.013000 duration=20 duration_time=0.020000 size=216 -pos=956 +pos=949 flags=K_ [/PACKET] [PACKET] @@ -83,7 +83,7 @@ dts_time=0.033000 duration=20 duration_time=0.020000 size=215 -pos=1179 +pos=1172 flags=K_ [/PACKET] [STREAM] |