[FFmpeg-devel,10/10] lavf/movenc: handle AC3 and EAC3 data extraction in check_bitstream

Submitted by Rodger Combs on March 14, 2018, 6:24 a.m.

Details

Message ID 20180314062445.89909-10-rodger.combs@gmail.com
State New
Headers show

Commit Message

Rodger Combs March 14, 2018, 6:24 a.m.
This allows us to write AC3 and EAC3 data to the header even in non-seekable
output, like with segment.c (which I add tests for).
---
 libavformat/movenc.c                             | 64 +++++++++++++++++-------
 tests/fate/avformat.mak                          | 60 +++++++++++++++++++++-
 tests/ref/fate/segment-ac3-to-mp4-header-000     | 38 ++++++++++++++
 tests/ref/fate/segment-ac3-to-mp4-header-001     | 30 +++++++++++
 tests/ref/fate/segment-ac3-to-mp4-header-all     | 62 +++++++++++++++++++++++
 tests/ref/fate/segment-ac3-to-mp4-header-md5sum  |  1 +
 tests/ref/fate/segment-eac3-to-mp4-header-000    | 38 ++++++++++++++
 tests/ref/fate/segment-eac3-to-mp4-header-001    | 21 ++++++++
 tests/ref/fate/segment-eac3-to-mp4-header-all    | 53 ++++++++++++++++++++
 tests/ref/fate/segment-eac3-to-mp4-header-md5sum |  1 +
 10 files changed, 348 insertions(+), 20 deletions(-)
 create mode 100644 tests/ref/fate/segment-ac3-to-mp4-header-000
 create mode 100644 tests/ref/fate/segment-ac3-to-mp4-header-001
 create mode 100644 tests/ref/fate/segment-ac3-to-mp4-header-all
 create mode 100644 tests/ref/fate/segment-ac3-to-mp4-header-md5sum
 create mode 100644 tests/ref/fate/segment-eac3-to-mp4-header-000
 create mode 100644 tests/ref/fate/segment-eac3-to-mp4-header-001
 create mode 100644 tests/ref/fate/segment-eac3-to-mp4-header-all
 create mode 100644 tests/ref/fate/segment-eac3-to-mp4-header-md5sum

Patch hide | download patch | download mbox

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index b5ef09c4c7..1f15d244ed 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -368,11 +368,11 @@  struct eac3_info {
 };
 
 #if CONFIG_AC3_PARSER
-static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
+static int parse_eac3(MOVMuxContext *mov, const AVPacket *pkt, MOVTrack *track, int *num_blocks)
 {
     AC3HeaderInfo *hdr = NULL;
     struct eac3_info *info;
-    int num_blocks, ret;
+    int ret = 1;
 
     if (!track->eac3_priv && !(track->eac3_priv = av_mallocz(sizeof(*info))))
         return AVERROR(ENOMEM);
@@ -389,7 +389,8 @@  static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
     }
 
     info->data_rate = FFMAX(info->data_rate, hdr->bit_rate / 1000);
-    num_blocks = hdr->num_blocks;
+    if (num_blocks)
+        *num_blocks = hdr->num_blocks;
 
     if (!info->ec3_done) {
         /* AC-3 substream must be the first one */
@@ -415,7 +416,7 @@  static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
             } else if (hdr->substreamid < info->num_ind_sub ||
                        hdr->substreamid == 0 && info->substream[0].bsid) {
                 info->ec3_done = 1;
-                goto concatenate;
+                goto end;
             }
         }
 
@@ -465,44 +466,53 @@  static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
         }
     }
 
-concatenate:
+end:
+    av_free(hdr);
+
+    return ret;
+}
+
+static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
+{
+    int num_blocks;
+    struct eac3_info *info;
+    int ret = parse_eac3(mov, pkt, track, &num_blocks);
+    if (ret <= 0)
+        return ret;
+
+    info = track->eac3_priv;
+
     if (!info->num_blocks && num_blocks == 6) {
-        ret = pkt->size;
-        goto end;
+        return pkt->size;
     }
     else if (info->num_blocks + num_blocks > 6) {
-        ret = AVERROR_INVALIDDATA;
-        goto end;
+        return AVERROR_INVALIDDATA;
     }
 
     if (!info->num_blocks) {
         ret = av_packet_ref(&info->pkt, pkt);
         if (!ret)
             info->num_blocks = num_blocks;
-        goto end;
+        return ret;
     } else {
         if ((ret = av_grow_packet(&info->pkt, pkt->size)) < 0)
-            goto end;
+            return ret;
         memcpy(info->pkt.data + info->pkt.size - pkt->size, pkt->data, pkt->size);
         info->num_blocks += num_blocks;
         info->pkt.duration += pkt->duration;
         if ((ret = av_copy_packet_side_data(&info->pkt, pkt)) < 0)
-            goto end;
+            return ret;
         if (info->num_blocks != 6)
-            goto end;
+            return ret;
         av_packet_unref(pkt);
         ret = av_packet_ref(pkt, &info->pkt);
         if (ret < 0)
-            goto end;
+            return ret;
         av_packet_unref(&info->pkt);
         info->num_blocks = 0;
     }
-    ret = pkt->size;
-
-end:
-    av_free(hdr);
 
-    return ret;
+    return pkt->size;
 }
 #endif
 
@@ -6572,12 +6582,28 @@  static int mov_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
 {
     int ret = 1;
     AVStream *st = s->streams[pkt->stream_index];
+    MOVMuxContext *mov = s->priv_data;
+    MOVTrack *trk = &mov->tracks[pkt->stream_index];
 
     if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
         if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0)
             ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL);
     } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) {
         ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL);
+    } else if ((st->codecpar->codec_id == AV_CODEC_ID_DNXHD ||
+                st->codecpar->codec_id == AV_CODEC_ID_AC3) && !trk->vos_len) {
+        /* copy frame to create needed atoms */
+        trk->vos_len  = pkt->size;
+        trk->vos_data = av_malloc(pkt->size);
+        if (!trk->vos_data)
+            return AVERROR(ENOMEM);
+        memcpy(trk->vos_data, pkt->data, pkt->size);
+#if CONFIG_AC3_PARSER
+    } else if (st->codecpar->codec_id == AV_CODEC_ID_EAC3) {
+        ret = parse_eac3(mov, pkt, trk, NULL);
+        if (ret < 0)
+            ret = 0;
+#endif
     }
 
     return ret;
diff --git a/tests/fate/avformat.mak b/tests/fate/avformat.mak
index 35a75c68c0..a76fc5c368 100644
--- a/tests/fate/avformat.mak
+++ b/tests/fate/avformat.mak
@@ -111,6 +111,30 @@  tests/data/adts-to-mkv-header-%.mkv: tests/data/adts-to-mkv-header.mkv ;
 
 FATE_SEGMENT_PARTS += 000 001 002
 
+tests/data/ac3-to-mp4-header.mp4: TAG = GEN
+tests/data/ac3-to-mp4-header.mp4: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+	$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+        -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 \
+        -f segment -segment_time 1 -map 0 -flags +bitexact -codec copy \
+        -segment_header_filename $(TARGET_PATH)/tests/data/ac3-to-mp4-header.mp4 \
+        -segment_format_options movflags=frag_custom+dash+delay_moov \
+        -y $(TARGET_PATH)/tests/data/ac3-to-mp4-header-%03d.mp4 -nostdin 2>/dev/null
+
+tests/data/ac3-to-mp4-header-%.mp4: tests/data/ac3-to-mp4-header.mp4 ;
+
+FATE_AC3_SEGMENT_PARTS += 000 001
+
+tests/data/eac3-to-mp4-header.mp4: TAG = GEN
+tests/data/eac3-to-mp4-header.mp4: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+	$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+        -i $(TARGET_SAMPLES)/eac3/csi_miami_5.1_256_spx_small.eac3 \
+        -f segment -segment_time 1 -map 0 -flags +bitexact -codec copy \
+        -segment_header_filename $(TARGET_PATH)/tests/data/eac3-to-mp4-header.mp4 \
+        -segment_format_options movflags=frag_custom+dash+delay_moov \
+        -y $(TARGET_PATH)/tests/data/eac3-to-mp4-header-%03d.mp4 -nostdin 2>/dev/null
+
+tests/data/eac3-to-mp4-header-%.mp4: tests/data/eac3-to-mp4-header.mp4 ;
+
 tests/data/adts-to-mkv-cated-all.mkv: TAG = GEN
 tests/data/adts-to-mkv-cated-all.mkv: tests/data/adts-to-mkv-header.mkv $(FATE_SEGMENT_PARTS:%=tests/data/adts-to-mkv-header-%.mkv) | tests/data
 	$(M)cat $^ >$@
@@ -119,6 +143,22 @@  tests/data/adts-to-mkv-cated-%.mkv: TAG = GEN
 tests/data/adts-to-mkv-cated-%.mkv: tests/data/adts-to-mkv-header.mkv tests/data/adts-to-mkv-header-%.mkv | tests/data
 	$(M)cat $^ >$@
 
+tests/data/ac3-to-mp4-cated-all.mp4: TAG = GEN
+tests/data/ac3-to-mp4-cated-all.mp4: tests/data/ac3-to-mp4-header.mp4 $(FATE_AC3_SEGMENT_PARTS:%=tests/data/ac3-to-mp4-header-%.mp4) | tests/data
+	$(M)cat $^ >$@
+
+tests/data/ac3-to-mp4-cated-%.mp4: TAG = GEN
+tests/data/ac3-to-mp4-cated-%.mp4: tests/data/ac3-to-mp4-header.mp4 tests/data/ac3-to-mp4-header-%.mp4 | tests/data
+	$(M)cat $^ >$@
+
+tests/data/eac3-to-mp4-cated-all.mp4: TAG = GEN
+tests/data/eac3-to-mp4-cated-all.mp4: tests/data/eac3-to-mp4-header.mp4 $(FATE_AC3_SEGMENT_PARTS:%=tests/data/eac3-to-mp4-header-%.mp4) | tests/data
+	$(M)cat $^ >$@
+
+tests/data/eac3-to-mp4-cated-%.mp4: TAG = GEN
+tests/data/eac3-to-mp4-cated-%.mp4: tests/data/eac3-to-mp4-header.mp4 tests/data/eac3-to-mp4-header-%.mp4 | tests/data
+	$(M)cat $^ >$@
+
 FATE_SEGMENT += fate-segment-mp4-to-ts
 fate-segment-mp4-to-ts: tests/data/mp4-to-ts.m3u8
 fate-segment-mp4-to-ts: CMD = framecrc -flags +bitexact -i $(TARGET_PATH)/tests/data/mp4-to-ts.m3u8 -c copy
@@ -135,7 +175,25 @@  FATE_SEGMENT_ALLPARTS += all
 FATE_SEGMENT_SPLIT += $(FATE_SEGMENT_ALLPARTS:%=fate-segment-adts-to-mkv-header-%)
 $(foreach N,$(FATE_SEGMENT_ALLPARTS),$(eval $(N:%=fate-segment-adts-to-mkv-header-%): tests/data/adts-to-mkv-cated-$(N).mkv))
 fate-segment-adts-to-mkv-header-%: CMD = framecrc -flags +bitexact -i $(TARGET_PATH)/tests/data/$(@:fate-segment-adts-to-mkv-header-%=adts-to-mkv-cated-%).mkv -c copy
-FATE_SEGMENT-$(call ALLYES, AAC_DEMUXER AAC_ADTSTOASC_BSF MATROSKA_MUXER MATROSKA_DEMUXER SEGMENT_MUXER HLS_DEMUXER) += $(FATE_SEGMENT_SPLIT)
+FATE_SEGMENT-$(call ALLYES, AAC_DEMUXER AAC_ADTSTOASC_BSF MATROSKA_MUXER MATROSKA_DEMUXER SEGMENT_MUXER) += $(FATE_SEGMENT_SPLIT)
+
+FATE_SEGMENT_AC3_ALLPARTS = $(FATE_AC3_SEGMENT_PARTS)
+FATE_SEGMENT_AC3_ALLPARTS += all
+FATE_SEGMENT_AC3_SPLIT += $(FATE_SEGMENT_AC3_ALLPARTS:%=fate-segment-ac3-to-mp4-header-%)
+$(foreach N,$(FATE_SEGMENT_ALLPARTS),$(eval $(N:%=fate-segment-ac3-to-mp4-header-%): tests/data/ac3-to-mp4-cated-$(N).mp4))
+fate-segment-ac3-to-mp4-header-%: CMD = framecrc -flags +bitexact -i $(TARGET_PATH)/tests/data/$(@:fate-segment-ac3-to-mp4-header-%=ac3-to-mp4-cated-%).mp4 -c copy
+fate-segment-ac3-to-mp4-header-md5sum: tests/data/ac3-to-mp4-header.mp4
+fate-segment-ac3-to-mp4-header-md5sum: CMD = do_md5sum tests/data/ac3-to-mp4-header.mp4
+FATE_SEGMENT_AC3_SPLIT += fate-segment-ac3-to-mp4-header-md5sum
+FATE_SEGMENT-$(call ALLYES, AC3_DEMUXER MP4_MUXER MOV_DEMUXER SEGMENT_MUXER) += $(FATE_SEGMENT_AC3_SPLIT)
+
+FATE_SEGMENT_EAC3_SPLIT += $(FATE_SEGMENT_AC3_ALLPARTS:%=fate-segment-eac3-to-mp4-header-%)
+$(foreach N,$(FATE_SEGMENT_ALLPARTS),$(eval $(N:%=fate-segment-eac3-to-mp4-header-%): tests/data/eac3-to-mp4-cated-$(N).mp4))
+fate-segment-eac3-to-mp4-header-%: CMD = framecrc -flags +bitexact -i $(TARGET_PATH)/tests/data/$(@:fate-segment-eac3-to-mp4-header-%=eac3-to-mp4-cated-%).mp4 -c copy
+fate-segment-eac3-to-mp4-header-md5sum: tests/data/eac3-to-mp4-header.mp4
+fate-segment-eac3-to-mp4-header-md5sum: CMD = do_md5sum tests/data/eac3-to-mp4-header.mp4
+FATE_SEGMENT_EAC3_SPLIT += fate-segment-eac3-to-mp4-header-md5sum
+FATE_SEGMENT-$(call ALLYES, EAC3_DEMUXER AC3_PARSER MP4_MUXER MOV_DEMUXER SEGMENT_MUXER) += $(FATE_SEGMENT_EAC3_SPLIT)
 
 FATE_SAMPLES_FFMPEG += $(FATE_SEGMENT-yes)
 
diff --git a/tests/ref/fate/segment-ac3-to-mp4-header-000 b/tests/ref/fate/segment-ac3-to-mp4-header-000
new file mode 100644
index 0000000000..3d85d4b313
--- /dev/null
+++ b/tests/ref/fate/segment-ac3-to-mp4-header-000
@@ -0,0 +1,38 @@ 
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: ac3
+#sample_rate 0: 48000
+#channel_layout 0: 60f
+#channel_layout_name 0: 5.1(side)
+0,          0,          0,     1536,     1792, 0xc6250823, S=1,        4, 0x00000000
+0,       1536,       1536,     1536,     1792, 0xb76a1098
+0,       3072,       3072,     1536,     1792, 0xfe6e1038
+0,       4608,       4608,     1536,     1792, 0x102f060a
+0,       6144,       6144,     1536,     1792, 0xfd881629
+0,       7680,       7680,     1536,     1792, 0x950505f6
+0,       9216,       9216,     1536,     1792, 0x3d9a143f
+0,      10752,      10752,     1536,     1792, 0xa2261142
+0,      12288,      12288,     1536,     1792, 0x9cc9053d
+0,      13824,      13824,     1536,     1792, 0xaaeb109b
+0,      15360,      15360,     1536,     1792, 0xd36308f6
+0,      16896,      16896,     1536,     1792, 0xb08a125d
+0,      18432,      18432,     1536,     1792, 0xd8d31026
+0,      19968,      19968,     1536,     1792, 0x9b87a34d
+0,      21504,      21504,     1536,     1792, 0x51ed77f6
+0,      23040,      23040,     1536,     1792, 0x29c16ed2
+0,      24576,      24576,     1536,     1792, 0x8c9662d6
+0,      26112,      26112,     1536,     1792, 0x32c85025
+0,      27648,      27648,     1536,     1792, 0x32914d88
+0,      29184,      29184,     1536,     1792, 0x84b9382b
+0,      30720,      30720,     1536,     1792, 0x003e4890
+0,      32256,      32256,     1536,     1792, 0x70325b4e
+0,      33792,      33792,     1536,     1792, 0x80e04a58
+0,      35328,      35328,     1536,     1792, 0x2c46323a
+0,      36864,      36864,     1536,     1792, 0x7be152a5
+0,      38400,      38400,     1536,     1792, 0x08615466
+0,      39936,      39936,     1536,     1792, 0x55364eaf
+0,      41472,      41472,     1536,     1792, 0x46595d56
+0,      43008,      43008,     1536,     1792, 0xdf476ace
+0,      44544,      44544,     1536,     1792, 0x9ff767dc
+0,      46080,      46080,     1536,     1792, 0xb4d450a7
+0,      47616,      47616,     1536,     1792, 0x032c7506
diff --git a/tests/ref/fate/segment-ac3-to-mp4-header-001 b/tests/ref/fate/segment-ac3-to-mp4-header-001
new file mode 100644
index 0000000000..ce7cc761b5
--- /dev/null
+++ b/tests/ref/fate/segment-ac3-to-mp4-header-001
@@ -0,0 +1,30 @@ 
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: ac3
+#sample_rate 0: 48000
+#channel_layout 0: 60f
+#channel_layout_name 0: 5.1(side)
+0,          0,          0,     1536,     1792, 0x50e35426, S=1,        4, 0x00000000
+0,       1536,       1536,     1536,     1792, 0xe5575597
+0,       3072,       3072,     1536,     1792, 0x86565611
+0,       4608,       4608,     1536,     1792, 0xed6f54aa
+0,       6144,       6144,     1536,     1792, 0x4cee4aab
+0,       7680,       7680,     1536,     1792, 0x8aa33ac7
+0,       9216,       9216,     1536,     1792, 0xb665442c
+0,      10752,      10752,     1536,     1792, 0x9a4b647d
+0,      12288,      12288,     1536,     1792, 0xf40d582d
+0,      13824,      13824,     1536,     1792, 0xf22e5d98
+0,      15360,      15360,     1536,     1792, 0x2f7745be
+0,      16896,      16896,     1536,     1792, 0xa918561a
+0,      18432,      18432,     1536,     1792, 0x59cc56fb
+0,      19968,      19968,     1536,     1792, 0xaefe5dca
+0,      21504,      21504,     1536,     1792, 0x80ba657d
+0,      23040,      23040,     1536,     1792, 0x09137032
+0,      24576,      24576,     1536,     1792, 0xf51b5d34
+0,      26112,      26112,     1536,     1792, 0x1d695fb1
+0,      27648,      27648,     1536,     1792, 0xf6f56509
+0,      29184,      29184,     1536,     1792, 0xd1f658d5
+0,      30720,      30720,     1536,     1792, 0xb8614f64
+0,      32256,      32256,     1536,     1792, 0x8dd55743
+0,      33792,      33792,     1536,     1792, 0xcb1f50df
+0,      35328,      35328,     1536,     1440, 0xa129aa95
diff --git a/tests/ref/fate/segment-ac3-to-mp4-header-all b/tests/ref/fate/segment-ac3-to-mp4-header-all
new file mode 100644
index 0000000000..e0f45c494d
--- /dev/null
+++ b/tests/ref/fate/segment-ac3-to-mp4-header-all
@@ -0,0 +1,62 @@ 
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: ac3
+#sample_rate 0: 48000
+#channel_layout 0: 60f
+#channel_layout_name 0: 5.1(side)
+0,          0,          0,     1536,     1792, 0xc6250823, S=1,        4, 0x00000000
+0,       1536,       1536,     1536,     1792, 0xb76a1098
+0,       3072,       3072,     1536,     1792, 0xfe6e1038
+0,       4608,       4608,     1536,     1792, 0x102f060a
+0,       6144,       6144,     1536,     1792, 0xfd881629
+0,       7680,       7680,     1536,     1792, 0x950505f6
+0,       9216,       9216,     1536,     1792, 0x3d9a143f
+0,      10752,      10752,     1536,     1792, 0xa2261142
+0,      12288,      12288,     1536,     1792, 0x9cc9053d
+0,      13824,      13824,     1536,     1792, 0xaaeb109b
+0,      15360,      15360,     1536,     1792, 0xd36308f6
+0,      16896,      16896,     1536,     1792, 0xb08a125d
+0,      18432,      18432,     1536,     1792, 0xd8d31026
+0,      19968,      19968,     1536,     1792, 0x9b87a34d
+0,      21504,      21504,     1536,     1792, 0x51ed77f6
+0,      23040,      23040,     1536,     1792, 0x29c16ed2
+0,      24576,      24576,     1536,     1792, 0x8c9662d6
+0,      26112,      26112,     1536,     1792, 0x32c85025
+0,      27648,      27648,     1536,     1792, 0x32914d88
+0,      29184,      29184,     1536,     1792, 0x84b9382b
+0,      30720,      30720,     1536,     1792, 0x003e4890
+0,      32256,      32256,     1536,     1792, 0x70325b4e
+0,      33792,      33792,     1536,     1792, 0x80e04a58
+0,      35328,      35328,     1536,     1792, 0x2c46323a
+0,      36864,      36864,     1536,     1792, 0x7be152a5
+0,      38400,      38400,     1536,     1792, 0x08615466
+0,      39936,      39936,     1536,     1792, 0x55364eaf
+0,      41472,      41472,     1536,     1792, 0x46595d56
+0,      43008,      43008,     1536,     1792, 0xdf476ace
+0,      44544,      44544,     1536,     1792, 0x9ff767dc
+0,      46080,      46080,     1536,     1792, 0xb4d450a7
+0,      47616,      47616,     1536,     1792, 0x032c7506
+0,      49152,      49152,     1536,     1792, 0x50e35426
+0,      50688,      50688,     1536,     1792, 0xe5575597
+0,      52224,      52224,     1536,     1792, 0x86565611
+0,      53760,      53760,     1536,     1792, 0xed6f54aa
+0,      55296,      55296,     1536,     1792, 0x4cee4aab
+0,      56832,      56832,     1536,     1792, 0x8aa33ac7
+0,      58368,      58368,     1536,     1792, 0xb665442c
+0,      59904,      59904,     1536,     1792, 0x9a4b647d
+0,      61440,      61440,     1536,     1792, 0xf40d582d
+0,      62976,      62976,     1536,     1792, 0xf22e5d98
+0,      64512,      64512,     1536,     1792, 0x2f7745be
+0,      66048,      66048,     1536,     1792, 0xa918561a
+0,      67584,      67584,     1536,     1792, 0x59cc56fb
+0,      69120,      69120,     1536,     1792, 0xaefe5dca
+0,      70656,      70656,     1536,     1792, 0x80ba657d
+0,      72192,      72192,     1536,     1792, 0x09137032
+0,      73728,      73728,     1536,     1792, 0xf51b5d34
+0,      75264,      75264,     1536,     1792, 0x1d695fb1
+0,      76800,      76800,     1536,     1792, 0xf6f56509
+0,      78336,      78336,     1536,     1792, 0xd1f658d5
+0,      79872,      79872,     1536,     1792, 0xb8614f64
+0,      81408,      81408,     1536,     1792, 0x8dd55743
+0,      82944,      82944,     1536,     1792, 0xcb1f50df
+0,      84480,      84480,     1536,     1440, 0xa129aa95
diff --git a/tests/ref/fate/segment-ac3-to-mp4-header-md5sum b/tests/ref/fate/segment-ac3-to-mp4-header-md5sum
new file mode 100644
index 0000000000..41323e70d2
--- /dev/null
+++ b/tests/ref/fate/segment-ac3-to-mp4-header-md5sum
@@ -0,0 +1 @@ 
+b6ead975a878a146ca9bfe5a5e6345b3 *tests/data/ac3-to-mp4-header.mp4
diff --git a/tests/ref/fate/segment-eac3-to-mp4-header-000 b/tests/ref/fate/segment-eac3-to-mp4-header-000
new file mode 100644
index 0000000000..69635c1eb0
--- /dev/null
+++ b/tests/ref/fate/segment-eac3-to-mp4-header-000
@@ -0,0 +1,38 @@ 
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: eac3
+#sample_rate 0: 48000
+#channel_layout 0: 60f
+#channel_layout_name 0: 5.1(side)
+0,          0,          0,     1536,     1024, 0x2a56e574, S=1,        4, 0x00000000
+0,       1536,       1536,     1536,     1024, 0x055df18f
+0,       3072,       3072,     1536,     1024, 0x2030e3d1
+0,       4608,       4608,     1536,     1024, 0x1d84e6d1
+0,       6144,       6144,     1536,     1024, 0xd13cf965
+0,       7680,       7680,     1536,     1024, 0x8b20fc56
+0,       9216,       9216,     1536,     1024, 0xc942f304
+0,      10752,      10752,     1536,     1024, 0x29c40d92
+0,      12288,      12288,     1536,     1024, 0xa3e5ed75
+0,      13824,      13824,     1536,     1024, 0xdf3ff3f5
+0,      15360,      15360,     1536,     1024, 0x14d6e8fd
+0,      16896,      16896,     1536,     1024, 0x1abaf108
+0,      18432,      18432,     1536,     1024, 0x0118e617
+0,      19968,      19968,     1536,     1024, 0xa879f227
+0,      21504,      21504,     1536,     1024, 0xb19cf385
+0,      23040,      23040,     1536,     1024, 0x7831dd07
+0,      24576,      24576,     1536,     1024, 0xc3f9f4fb
+0,      26112,      26112,     1536,     1024, 0x628bf77e
+0,      27648,      27648,     1536,     1024, 0x826de875
+0,      29184,      29184,     1536,     1024, 0x0fa1eeff
+0,      30720,      30720,     1536,     1024, 0xa6bcfa53
+0,      32256,      32256,     1536,     1024, 0x6edee378
+0,      33792,      33792,     1536,     1024, 0xa4b9e5b4
+0,      35328,      35328,     1536,     1024, 0xb26dfa72
+0,      36864,      36864,     1536,     1024, 0x10c2e81d
+0,      38400,      38400,     1536,     1024, 0x1765d7bd
+0,      39936,      39936,     1536,     1024, 0x23cbebf4
+0,      41472,      41472,     1536,     1024, 0xfbd4ff1d
+0,      43008,      43008,     1536,     1024, 0x2683f22b
+0,      44544,      44544,     1536,     1024, 0x00baf4c6
+0,      46080,      46080,     1536,     1024, 0x99e0edcd
+0,      47616,      47616,     1536,     1024, 0x78e60506
diff --git a/tests/ref/fate/segment-eac3-to-mp4-header-001 b/tests/ref/fate/segment-eac3-to-mp4-header-001
new file mode 100644
index 0000000000..55b56a3b96
--- /dev/null
+++ b/tests/ref/fate/segment-eac3-to-mp4-header-001
@@ -0,0 +1,21 @@ 
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: eac3
+#sample_rate 0: 48000
+#channel_layout 0: 60f
+#channel_layout_name 0: 5.1(side)
+0,          0,          0,     1536,     1024, 0x1be3fea9, S=1,        4, 0x00000000
+0,       1536,       1536,     1536,     1024, 0x4b65fb5f
+0,       3072,       3072,     1536,     1024, 0xe044eed5
+0,       4608,       4608,     1536,     1024, 0x4336ed35
+0,       6144,       6144,     1536,     1024, 0x93e6facc
+0,       7680,       7680,     1536,     1024, 0x4bebe3a0
+0,       9216,       9216,     1536,     1024, 0xa54fec79
+0,      10752,      10752,     1536,     1024, 0x9481de90
+0,      12288,      12288,     1536,     1024, 0x6032f9ac
+0,      13824,      13824,     1536,     1024, 0xfd0dfb2d
+0,      15360,      15360,     1536,     1024, 0x0fa7f0b0
+0,      16896,      16896,     1536,     1024, 0xef04ea99
+0,      18432,      18432,     1536,     1024, 0xe477ed37
+0,      19968,      19968,     1536,     1024, 0x8dd9eab1
+0,      21504,      21504,     1536,     1024, 0x96adf25d
diff --git a/tests/ref/fate/segment-eac3-to-mp4-header-all b/tests/ref/fate/segment-eac3-to-mp4-header-all
new file mode 100644
index 0000000000..5452885983
--- /dev/null
+++ b/tests/ref/fate/segment-eac3-to-mp4-header-all
@@ -0,0 +1,53 @@ 
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: eac3
+#sample_rate 0: 48000
+#channel_layout 0: 60f
+#channel_layout_name 0: 5.1(side)
+0,          0,          0,     1536,     1024, 0x2a56e574, S=1,        4, 0x00000000
+0,       1536,       1536,     1536,     1024, 0x055df18f
+0,       3072,       3072,     1536,     1024, 0x2030e3d1
+0,       4608,       4608,     1536,     1024, 0x1d84e6d1
+0,       6144,       6144,     1536,     1024, 0xd13cf965
+0,       7680,       7680,     1536,     1024, 0x8b20fc56
+0,       9216,       9216,     1536,     1024, 0xc942f304
+0,      10752,      10752,     1536,     1024, 0x29c40d92
+0,      12288,      12288,     1536,     1024, 0xa3e5ed75
+0,      13824,      13824,     1536,     1024, 0xdf3ff3f5
+0,      15360,      15360,     1536,     1024, 0x14d6e8fd
+0,      16896,      16896,     1536,     1024, 0x1abaf108
+0,      18432,      18432,     1536,     1024, 0x0118e617
+0,      19968,      19968,     1536,     1024, 0xa879f227
+0,      21504,      21504,     1536,     1024, 0xb19cf385
+0,      23040,      23040,     1536,     1024, 0x7831dd07
+0,      24576,      24576,     1536,     1024, 0xc3f9f4fb
+0,      26112,      26112,     1536,     1024, 0x628bf77e
+0,      27648,      27648,     1536,     1024, 0x826de875
+0,      29184,      29184,     1536,     1024, 0x0fa1eeff
+0,      30720,      30720,     1536,     1024, 0xa6bcfa53
+0,      32256,      32256,     1536,     1024, 0x6edee378
+0,      33792,      33792,     1536,     1024, 0xa4b9e5b4
+0,      35328,      35328,     1536,     1024, 0xb26dfa72
+0,      36864,      36864,     1536,     1024, 0x10c2e81d
+0,      38400,      38400,     1536,     1024, 0x1765d7bd
+0,      39936,      39936,     1536,     1024, 0x23cbebf4
+0,      41472,      41472,     1536,     1024, 0xfbd4ff1d
+0,      43008,      43008,     1536,     1024, 0x2683f22b
+0,      44544,      44544,     1536,     1024, 0x00baf4c6
+0,      46080,      46080,     1536,     1024, 0x99e0edcd
+0,      47616,      47616,     1536,     1024, 0x78e60506
+0,      49152,      49152,     1536,     1024, 0x1be3fea9
+0,      50688,      50688,     1536,     1024, 0x4b65fb5f
+0,      52224,      52224,     1536,     1024, 0xe044eed5
+0,      53760,      53760,     1536,     1024, 0x4336ed35
+0,      55296,      55296,     1536,     1024, 0x93e6facc
+0,      56832,      56832,     1536,     1024, 0x4bebe3a0
+0,      58368,      58368,     1536,     1024, 0xa54fec79
+0,      59904,      59904,     1536,     1024, 0x9481de90
+0,      61440,      61440,     1536,     1024, 0x6032f9ac
+0,      62976,      62976,     1536,     1024, 0xfd0dfb2d
+0,      64512,      64512,     1536,     1024, 0x0fa7f0b0
+0,      66048,      66048,     1536,     1024, 0xef04ea99
+0,      67584,      67584,     1536,     1024, 0xe477ed37
+0,      69120,      69120,     1536,     1024, 0x8dd9eab1
+0,      70656,      70656,     1536,     1024, 0x96adf25d
diff --git a/tests/ref/fate/segment-eac3-to-mp4-header-md5sum b/tests/ref/fate/segment-eac3-to-mp4-header-md5sum
new file mode 100644
index 0000000000..8fadc43ae6
--- /dev/null
+++ b/tests/ref/fate/segment-eac3-to-mp4-header-md5sum
@@ -0,0 +1 @@ 
+362c70697f36c24f14611c6f1a1a49c1 *tests/data/eac3-to-mp4-header.mp4