aboutsummaryrefslogtreecommitdiffstats
path: root/main/ffmpeg/fix-flv-extradata.patch
blob: 2fe5b08bcc5c6ca7bcd436ddf28fb05095c00a2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
https://trac.ffmpeg.org/ticket/3175

This patch is slightly cleaned up version of:
http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2014-May/157791.html

diff -ru ffmpeg-2.3.4.orig/libavformat/flvenc.c ffmpeg-2.3.4/libavformat/flvenc.c
--- ffmpeg-2.3.4.orig/libavformat/flvenc.c	2014-10-03 04:49:20.000000000 -0300
+++ ffmpeg-2.3.4/libavformat/flvenc.c	2014-12-04 11:37:23.286586875 -0200
@@ -414,11 +414,35 @@
             if (enc->codec_id == AV_CODEC_ID_AAC) {
                 avio_w8(pb, get_audio_flags(s, enc));
                 avio_w8(pb, 0); // AAC sequence header
+                if (enc->extradata_size < 2) {
+                    static const int mpeg4audio_sample_rates[16] = {
+                        96000, 88200, 64000, 48000, 44100, 32000,
+                        24000, 22050, 16000, 12000, 11025, 8000, 7350
+                    };
+                    int sample_rate_index;
+
+                    av_log(s, AV_LOG_WARNING, "AAC extradata empty!.\n");
+                    for (sample_rate_index = 0; sample_rate_index < 16; sample_rate_index++)
+                        if (enc->sample_rate == mpeg4audio_sample_rates[sample_rate_index])
+                            break;
+
+                    if (sample_rate_index < 16 && (enc->extradata = av_mallocz(2)) != NULL) {
+                        enc->extradata_size = 2;
+                        enc->extradata[0] = 0x10 | (sample_rate_index>>1);
+                        enc->extradata[1] = (sample_rate_index & 0x01)<<7 | enc->channels <<3;
+                    }
+                }
+                if (enc->extradata_size >= 2)
+                    av_log(s, AV_LOG_DEBUG, "AAC extradata size %d: %02x:%02x.\n", enc->extradata_size, enc->extradata[0], enc->extradata[1]);
                 avio_write(pb, enc->extradata, enc->extradata_size);
             } else {
                 avio_w8(pb, enc->codec_tag | FLV_FRAME_KEY); // flags
                 avio_w8(pb, 0); // AVC sequence header
                 avio_wb24(pb, 0); // composition time
+                if(enc->extradata_size>=2)
+                    av_log(s, AV_LOG_DEBUG, "Video extradata size %d: %02x:%02x.\n", enc->extradata_size, enc->extradata[0], enc->extradata[1]);
+                else
+                    av_log(s, AV_LOG_WARNING, "Video extradata empty!.\n");
                 ff_isom_write_avcc(pb, enc->extradata, enc->extradata_size);
             }
             data_size = avio_tell(pb) - pos;