Opened 11 years ago

Last modified 7 years ago

#3175 open defect

audio (aac) silently on streamcopy from mpegts to flv

Reported by: iluvatar Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: aac flv
Cc: fabled@iki.fi Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

If you do streamcopy from mpegts to flv with audiocodec aac audio in output is silently.
Reproduced with internal aac encoder, faac and libfdk_aac.
The problem occurs, because AudioSpecificConfig (ASC) is not written on streamcopy. Bitstream filter aac_adtstoasc_bsf.c writes ASC correctly (line 94-99) but too late (after flv header).
If you write ASC in flvenc.c manually, encoded file is written correctly:

--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -397,7 +397,8 @@ static int flv_write_header(AVFormatContext *s)
             if (enc->codec_id == AV_CODEC_ID_AAC) {
                 avio_w8(pb, get_audio_flags(s, enc));
                 avio_w8(pb, 0); // AAC sequence header
-                avio_write(pb, enc->extradata, enc->extradata_size);
+                avio_wb16(pb, 5000); // ^= 0x1388; AAC LC, 22050 Hz, 1 channel
+                //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

More information about ASC:
http://wiki.multimedia.cx/index.php?title=MPEG-4_Audio#Audio_Specific_Config
I don't know if you can call bitstream filter before writing flv header.

How to reproduce:

% ffmpeg -re -i /tmp/input.ts -c:v copy -c:a libfaac -b:a 32k -ar 22050 -ac 1 -f mpegts udp://localhost:1234
ffmpeg version N-58470-g3c846fd Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov 26 2013 14:56:57 with gcc 4.4.5 (Debian 4.4.5-8)
  configuration: --enable-nonfree --enable-libfaac --enable-libx264 --enable-gpl --enable-libzmq --enable-libfreetype --enable-ffplay --enable-librtmp --enable-libfdk-aac --enable-libmp3lame --enable-libvpx
  libavutil      52. 55.100 / 52. 55.100
  libavcodec     55. 44.100 / 55. 44.100
  libavformat    55. 21.102 / 55. 21.102
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 91.100 /  3. 91.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mpegts, from '/tmp/input.ts':
  Duration: 00:01:00.00, start: 1.378667, bitrate: 2319 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream #0:1[0x101](deu): Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 121 kb/s
Output #0, mpegts, to 'udp://localhost:1234':
  Metadata:
    encoder         : Lavf55.21.102
    Stream #0:0: Video: h264 ([27][0][0][0] / 0x001B), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 50 fps, 90k tbn, 50 tbc
    Stream #0:1(deu): Audio: aac (libfaac), 22050 Hz, mono, s16, 32 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (aac -> libfaac)
Press [q] to stop, [?] for help

% ffmpeg -i udp://localhost:1234 -c copy -bsf:a aac_adtstoasc -f flv output.flv

My intention is to stream one mpegts (with one h264 and multiple languages -> aac) to a local udp port and then steam each language in extra processes to different flash servers.

Change History (9)

comment:1 by Carl Eugen Hoyos, 11 years ago

Keywords: streamcopy removed

Do I understand correctly that you added console output for the command that does not show the problem, ie for a command that works ok?

Is udp necessary to reproduce this issue or is it sufficient to remux a fate sample?

Last edited 11 years ago by Carl Eugen Hoyos (previous) (diff)

in reply to:  1 ; comment:2 by iluvatar, 11 years ago

Replying to cehoyos:

Do I understand correctly that you added console output for the command that does not show the problem, ie for a command that works ok?

Audio stream in my sample output.flv is silently. If I change flvenc.c as described above output.flv is good.

Is udp necessary to reproduce this issue or is it sufficient to remux a fate sample?

Udp is not necessary. Here is a better sample:

ffmpeg -i fate-suite/aac/CT_DecoderCheck/File1.aac -c copy -f flv -bsf:a aac_adtstoasc /tmp/File1.flv

I played flv with vlc.

in reply to:  2 ; comment:3 by Carl Eugen Hoyos, 11 years ago

Replying to iluvatar:

Replying to cehoyos:

Do I understand correctly that you added console output for the command that does not show the problem, ie for a command that works ok?

Audio stream in my sample output.flv is silently.

But for the command that outputs output.flv, you did not add console output. You did add console output for a command that I suspect works fine or doesn't it?

If I change flvenc.c as described above output.flv is good.

Is udp necessary to reproduce this issue or is it sufficient to remux a fate sample?

Udp is not necessary. Here is a better sample:

ffmpeg -i fate-suite/aac/CT_DecoderCheck/File1.aac -c copy -f flv -bsf:a aac_adtstoasc /tmp/File1.flv

Please add complete, uncut console output to make this a valid ticket.

in reply to:  3 comment:4 by iluvatar, 11 years ago

Replying to cehoyos:

Replying to iluvatar:

Replying to cehoyos:

Do I understand correctly that you added console output for the command that does not show the problem, ie for a command that works ok?

Audio stream in my sample output.flv is silently.

But for the command that outputs output.flv, you did not add console output. You did add console output for a command that I suspect works fine or doesn't it?

Yes, you are right, sorry. Here is the console output of the second command:

% ffmpeg -i udp://localhost:1234 -c copy -bsf:a aac_adtstoasc -f flv output.flv
ffmpeg version N-58470-g3c846fd Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov 26 2013 14:56:57 with gcc 4.4.5 (Debian 4.4.5-8)
  configuration: --enable-nonfree --enable-libfaac --enable-libx264 --enable-gpl --enable-libzmq --enable-libfreetype --enable-ffplay --enable-librtmp --enable-libfdk-aac --enable-libmp3lame --enable-libvpx
  libavutil      52. 55.100 / 52. 55.100
  libavcodec     55. 44.100 / 55. 44.100
  libavformat    55. 21.102 / 55. 21.102
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 91.100 /  3. 91.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[h264 @ 0xb0b74c0] non-existing PPS referenced
[h264 @ 0xb0b74c0] non-existing PPS 0 referenced
[h264 @ 0xb0b74c0] decode_slice_header error
[h264 @ 0xb0b74c0] no frame!
[mpegts @ 0xb098d80] PES packet size mismatch
Input #0, mpegts, from 'udp://localhost:1234':
  Duration: N/A, start: 68.552111, bitrate: 34 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 720x576 [SAR 16:11 DAR 20:11], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101](qaa): Audio: aac ([15][0][0][0] / 0x000F), 22050 Hz, mono, fltp, 34 kb/s
Output #0, flv, to 'output.flv':
  Metadata:
    encoder         : Lavf55.21.102
    Stream #0:0: Video: h264 ([7][0][0][0] / 0x0007), yuv420p, 720x576 [SAR 16:11 DAR 20:11], q=2-31, 25 fps, 1k tbn, 90k tbc
    Stream #0:1(qaa): Audio: aac ([10][0][0][0] / 0x000A), 22050 Hz, mono, 34 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  217 fps= 53 q=-1.0 Lsize=    3671kB time=00:00:10.03 bitrate=2998.0kbits/s
video:3625kB audio:39kB subtitle:0 global headers:0kB muxing overhead 0.190463%

If I change flvenc.c as described above output.flv is good.

Is udp necessary to reproduce this issue or is it sufficient to remux a fate sample?

Udp is not necessary. Here is a better sample:

ffmpeg -i fate-suite/aac/CT_DecoderCheck/File1.aac -c copy -f flv -bsf:a aac_adtstoasc /tmp/File1.flv

Please add complete, uncut console output to make this a valid ticket.

% ffmpeg -i aac/CT_DecoderCheck/File1.aac -c copy -f flv -bsf:a aac_adtstoasc File1.flv
ffmpeg version N-58470-g3c846fd Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov 26 2013 14:56:57 with gcc 4.4.5 (Debian 4.4.5-8)
  configuration: --enable-nonfree --enable-libfaac --enable-libx264 --enable-gpl --enable-libzmq --enable-libfreetype --enable-ffplay --enable-librtmp --enable-libfdk-aac --enable-libmp3lame --enable-libvpx
  libavutil      52. 55.100 / 52. 55.100
  libavcodec     55. 44.100 / 55. 44.100
  libavformat    55. 21.102 / 55. 21.102
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 91.100 /  3. 91.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
[aac @ 0x9968da0] Estimating duration from bitrate, this may be inaccurate
Input #0, aac, from 'aac/CT_DecoderCheck/File1.aac':
  Metadata:
    title           : The 1st file
    artist          : Coding Technologies
    album           : aacPlus Decoder Check
    date            : 2007
  Duration: 00:00:09.20, bitrate: 27 kb/s
    Stream #0:0: Audio: aac, 44100 Hz, stereo, fltp, 27 kb/s
Output #0, flv, to 'File1.flv':
  Metadata:
    title           : The 1st file
    artist          : Coding Technologies
    album           : aacPlus Decoder Check
    date            : 2007
    encoder         : Lavf55.21.102
    Stream #0:0: Audio: aac ([10][0][0][0] / 0x000A), 44100 Hz, stereo, 27 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=      33kB time=00:00:07.84 bitrate=  34.1kbits/s
video:0kB audio:31kB subtitle:0 global headers:0kB muxing overhead 6.447092%

comment:5 by Carl Eugen Hoyos, 11 years ago

Reproduced by developer: set
Status: newopen

comment:6 by malakudi, 10 years ago

I've recently experienced this same issue. The real problem is that, when using codec copy with bitstream filter to write audio in flv, the flv header always reports that the audio is 44100 stereo. If the original source has these attributes, the resulting flv file is OK. If original source is different, like 22050 mono for example (as in the original poster example), the resulting file cannot be played back.

So in the following example:

ffprobe -i out.aac
Input #0, aac, from 'out.aac':
  Duration: 00:00:21.61, bitrate: 94 kb/s
    Stream #0:0: Audio: aac, 48000 Hz, stereo, fltp, 94 kb/s
ffmpeg -i out.aac -acodec copy -bsf:a aac_adtstoasc out.flv
Input #0, aac, from 'out.aac':
  Duration: 00:00:21.61, bitrate: 94 kb/s
    Stream #0:0: Audio: aac, 48000 Hz, stereo, fltp, 94 kb/s
Output #0, flv, to 'out.flv':
  Metadata:
    encoder         : Lavf55.33.100
    Stream #0:0: Audio: aac ([10][0][0][0] / 0x000A), 48000 Hz, stereo, 94 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=     258kB time=00:00:20.58 bitrate= 102.7kbits/s
video:0kB audio:248kB subtitle:0 data:0 global headers:0kB muxing overhead 3.888596%
ffprobe -i out.flv
Input #0, flv, from 'out.flv':
  Metadata:
    encoder         : Lavf55.33.100
  Duration: 00:00:20.59, start: 0.000000, bitrate: 102 kb/s
    Stream #0:0: Audio: aac, 44100 Hz, stereo, fltp, 94 kb/s

you can see that the resulting file has attibutes 44100 Hz, stereo, which is wrong. Actually it always has 44100, stereo, no matter what the input is, when using aac_adtstoasc bitstream filter.

However, if you transcode, flv has the correct header.
So, the bug is that the flv header is not updated correctly with the attributes of the input stream when using bitstream filter aac_adtstoasc.

I should also add that this is not happening if you output mp4 format. mp4 header is correcty updated. So the issue must be inside flv code.

edit: For test I've used ffmpeg version N-43479-gd4be3a8- statically linked linux amd64 binary from johnvansickle dot com

Last edited 10 years ago by malakudi (previous) (diff)

comment:7 by fabled, 10 years ago

Cc: fabled@iki.fi added

Same issue here. Any suggestions on how to fix this?

comment:8 by fabled, 10 years ago

Seems this was discussed on mailing list recently with (an ugly?) patch:
http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2014-May/157791.html

comment:9 by Terran Vigil, 7 years ago

Following as I'm seeing the same issue. It appears that a variation of the patch mentioned above was applied recently and can be invoked using:

-flvflags aac_seq_header_detect

However, the audio specific config that is written is incorrect - the audio object type and sample rate are both written incorrectly, at least with my test.

Note: See TracTickets for help on using tickets.