[FFmpeg-devel] [PATCH 09/10] lavf/mux: propagate extradata changes before we call write_header to codecpar

Rodger Combs rodger.combs at gmail.com
Wed Mar 14 08:24:44 EET 2018


This includes extradata generated by an encoder post-init, or extradata
generated by automatically-added bsfs.

This fixes remuxing ADTS to non-seekable MKV, which had been broken in
f63c3516577d605e51cf16358cbdfa0bc97565d8, so the tests modified there
are restored.

This moves extradata writing in aac-autobsf-adtstoasc to write_header,
resulting in a smaller file since we don't write a padding void, so
that test reference is also updated.
---
 libavformat/mux.c                    | 14 ++++++++++++++
 tests/fate/avformat.mak              |  4 ++--
 tests/ref/fate/aac-autobsf-adtstoasc |  4 ++--
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 5fdc9275cc..611a3c0f15 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -892,6 +892,20 @@ static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
             return 0;
         }
     }
+
+    if (!s->internal->header_written) {
+        int side_size;
+        uint8_t *side = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size);
+        if (side && side_size > 0 && (side_size != st->codecpar->extradata_size ||
+                                      memcmp(side, st->codecpar->extradata, side_size))) {
+            av_freep(&st->codecpar->extradata);
+            if ((ret = ff_alloc_extradata(st->codecpar, side_size)) < 0)
+                return ret;
+            memcpy(st->codecpar->extradata, side, side_size);
+            st->codecpar->extradata_size = side_size;
+        }
+    }
+
     return 1;
 }
 
diff --git a/tests/fate/avformat.mak b/tests/fate/avformat.mak
index 346a4b4509..35a75c68c0 100644
--- a/tests/fate/avformat.mak
+++ b/tests/fate/avformat.mak
@@ -95,14 +95,14 @@ tests/data/mp4-to-ts.m3u8: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
 tests/data/adts-to-mkv.m3u8: TAG = GEN
 tests/data/adts-to-mkv.m3u8: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
 	$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
-        -i $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.m4a \
+        -i $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts \
         -f segment -segment_time 1 -map 0 -flags +bitexact -codec copy -segment_format_options live=1 \
         -segment_list $(TARGET_PATH)/$@ -y $(TARGET_PATH)/tests/data/adts-to-mkv-%03d.mkv -nostdin 2>/dev/null
 
 tests/data/adts-to-mkv-header.mkv: TAG = GEN
 tests/data/adts-to-mkv-header.mkv: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
 	$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
-        -i $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.m4a \
+        -i $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts \
         -f segment -segment_time 1 -map 0 -flags +bitexact -codec copy -segment_format_options live=1 \
         -segment_header_filename $(TARGET_PATH)/tests/data/adts-to-mkv-header.mkv \
         -y $(TARGET_PATH)/tests/data/adts-to-mkv-header-%03d.mkv -nostdin 2>/dev/null
diff --git a/tests/ref/fate/aac-autobsf-adtstoasc b/tests/ref/fate/aac-autobsf-adtstoasc
index 9ca8e7ed9e..d5dfbabe5f 100644
--- a/tests/ref/fate/aac-autobsf-adtstoasc
+++ b/tests/ref/fate/aac-autobsf-adtstoasc
@@ -1,5 +1,5 @@
-b0375ba00bcbd55023a176255b8d4ba2 *tests/data/fate/aac-autobsf-adtstoasc.matroska
-6728 tests/data/fate/aac-autobsf-adtstoasc.matroska
+1bd4a110db26231cade5344de302254e *tests/data/fate/aac-autobsf-adtstoasc.matroska
+6396 tests/data/fate/aac-autobsf-adtstoasc.matroska
 #extradata 0:        2, 0x0030001c
 #tb 0: 1/1000
 #media_type 0: audio
-- 
2.16.2



More information about the ffmpeg-devel mailing list