diff mbox series

[FFmpeg-devel,3/8] avformat/matroskaenc: Only write DiscardPadding if nonzero

Message ID GV1P250MB0737C22CA51D9A60B85A85648F7B9@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 7bacef580f81ab7a98401b9b05441115df36d86b
Headers show
Series [FFmpeg-devel,1/8] fftools/ffprobe: Report initial and trailing padding | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 1, 2022, 9:23 p.m. UTC
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>
---
 libavformat/matroskaenc.c              | 12 +++++++-----
 tests/ref/fate/matroska-ogg-opus-remux | 10 +++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)
diff mbox series

Patch

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]