#2782 closed defect (worksforme)
aac - Malformed AAC bitstream - incorrectly fixed with -bsf:a aac_adtstoasc' option
Reported by: | feelart | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | avformat |
Version: | git-master | Keywords: | aac mov |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Observing some improper fixing on a bunch of aac using FFmeg
F:\Youtube Extract\Music>ffmpeg -i alice.aac -c:a copy aliceFF.mp4 ffmpeg version N-54691-g7f4a1fd Copyright (c) 2000-2013 the FFmpeg developers built on Jul 12 2013 16:31:48 with gcc 4.7.3 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig -- enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enab le-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --e nable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-lib theora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib libavutil 52. 39.100 / 52. 39.100 libavcodec 55. 18.102 / 55. 18.102 libavformat 55. 12.102 / 55. 12.102 libavdevice 55. 3.100 / 55. 3.100 libavfilter 3. 80.101 / 3. 80.101 libswscale 2. 3.100 / 2. 3.100 libswresample 0. 17.102 / 0. 17.102 libpostproc 52. 3.100 / 52. 3.100 [aac @ 0000000002686fe0] Estimating duration from bitrate, this may be inaccurate Input #0, aac, from 'alice.aac': Metadata: title : Alice Deejay - Better Off Alon Duration: 00:03:46.41, bitrate: 77 kb/s Stream #0:0: Audio: aac, 44100 Hz, stereo, fltp, 77 kb/s Output #0, mp4, to 'aliceFF.mp4': Metadata: title : Alice Deejay - Better Off Alon encoder : Lavf55.12.102 Stream #0:0: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 77 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Press [q] to stop, [?] for help [mp4 @ 000000000030a620] Malformed AAC bitstream detected: use audio bitstream filter 'aac_adtstoasc' to fix it ('-bsf:a aac _adtstoasc' option with ffmpeg) av_interleaved_write_frame(): Operation not permitted
Now trying, to fix it with -bsf:a aac_adtstoasc
F:\Youtube Extract\Music>ffmpeg -i alice.aac -c:a copy -bsf:a aac_adtstoasc aliceFF_bsf.mp4 ffmpeg version N-54691-g7f4a1fd Copyright (c) 2000-2013 the FFmpeg developers built on Jul 12 2013 16:31:48 with gcc 4.7.3 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig -- enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enab le-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --e nable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-lib theora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib libavutil 52. 39.100 / 52. 39.100 libavcodec 55. 18.102 / 55. 18.102 libavformat 55. 12.102 / 55. 12.102 libavdevice 55. 3.100 / 55. 3.100 libavfilter 3. 80.101 / 3. 80.101 libswscale 2. 3.100 / 2. 3.100 libswresample 0. 17.102 / 0. 17.102 libpostproc 52. 3.100 / 52. 3.100 [aac @ 00000000002db740] Estimating duration from bitrate, this may be inaccurate Input #0, aac, from 'alice.aac': Metadata: title : Alice Deejay - Better Off Alon Duration: 00:03:46.41, bitrate: 77 kb/s Stream #0:0: Audio: aac, 44100 Hz, stereo, fltp, 77 kb/s Output #0, mp4, to 'aliceFF_bsf.mp4': Metadata: title : Alice Deejay - Better Off Alon encoder : Lavf55.12.102 Stream #0:0: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 77 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Press [q] to stop, [?] for help size= 2123kB time=00:02:39.17 bitrate= 109.3kbits/s video:0kB audio:2142kB subtitle:0 global headers:0kB muxing overhead -0.899321%
However, one sees that the fix is incorrect
F:\Youtube Extract\Music>aacgain -a -k aliceFF_bsf.mp4 aliceFF_bsf.mp4 Error: invalid file format aliceFF_bsf.mp4, code=15 aliceFF_bsf.mp4 is not a valid mp4/m4a file.
FYI: https://github.com/elfchief/mp3gain/tree/master/aacgain
On some other aac, I see aacgain error code=6
Finally, I tried to re-encode, but then raises another error, but still no proper fix.
F:\Youtube Extract\Music>ffmpeg -i alice.aac -bsf:a aac_adtstoasc aliceFF_NoCopy_bsf.mp4 ffmpeg version N-54691-g7f4a1fd Copyright (c) 2000-2013 the FFmpeg developers built on Jul 12 2013 16:31:48 with gcc 4.7.3 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig -- enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enab le-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --e nable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-lib theora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib libavutil 52. 39.100 / 52. 39.100 libavcodec 55. 18.102 / 55. 18.102 libavformat 55. 12.102 / 55. 12.102 libavdevice 55. 3.100 / 55. 3.100 libavfilter 3. 80.101 / 3. 80.101 libswscale 2. 3.100 / 2. 3.100 libswresample 0. 17.102 / 0. 17.102 libpostproc 52. 3.100 / 52. 3.100 [aac @ 000000000031d6c0] Estimating duration from bitrate, this may be inaccurate Input #0, aac, from 'alice.aac': Metadata: title : Alice Deejay - Better Off Alon Duration: 00:03:46.41, bitrate: 77 kb/s Stream #0:0: Audio: aac, 44100 Hz, stereo, fltp, 77 kb/s Output #0, mp4, to 'aliceFF_NoCopy_bsf.mp4': Metadata: title : Alice Deejay - Better Off Alon encoder : Lavf55.12.102 Stream #0:0: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s Stream mapping: Stream #0:0 -> #0:0 (aac -> libvo_aacenc) Press [q] to stop, [?] for help decode_band_types: Input buffer exhausted before END element found Error while decoding stream #0:0: Invalid data found when processing input [aac @ 000000000031a280] channel element 2.0 is not allocated Error while decoding stream #0:0: Error number -1 occurred size= 2515kB time=00:02:39.13 bitrate= 129.5kbits/s video:0kB audio:2487kB subtitle:0 global headers:0kB muxing overhead 1.109339%
Thanks
Attachments (2)
Change History (18)
by , 11 years ago
by , 11 years ago
Attachment: | patchmovaacnofail.diff added |
---|
comment:2 by , 11 years ago
Component: | avcodec → avformat |
---|---|
Keywords: | mov added; aac_adtstoasc removed |
Status: | new → open |
Allowing to remux the file is easy, see attached patch (poc). The problem is that neither WMP nor QT play the output file indicating that FFmpeg is correct in refusing to mux such samples.
Does MP4Box produce a file that can be decoded with one of them?
comment:3 by , 11 years ago
Replying to feelart:
However, one sees that the fix is incorrect
F:\Youtube Extract\Music>aacgain -a -k aliceFF_bsf.mp4 aliceFF_bsf.mp4 Error: invalid file format aliceFF_bsf.mp4, code=15 aliceFF_bsf.mp4 is not a valid mp4/m4a file.
Sorry, I originally missed this part of your ticket.
I tested the output of ffmpeg -i Alice.aac -acodec copy -bsf aac_adtstoasc out.mov
with the following applications:
WMP, QT, faad, totem, firefox (more than half of them certainly do not depend on FFmpeg)
All of them play the output file fine. Are you sure this is no problem with aacgain that you should report at their bugtracker?
follow-up: 5 comment:4 by , 11 years ago
Regarding MP4Box, I don't know this tool.
https://github.com/elfchief/mp3gain/blob/master/aacgain/aacgain.cpp
Line 317&318
//ignore error 4 (scalefactor out of range) which seems to happen on some tracks //other errors are fatal
aacgain starts to process the file almost till the end, then stops on fatal error.
Same kind of fatal error both with
ffmpeg -i alice.aac -bsf:a aac_adtstoasc -vol 312 test.aac or ffmpeg -y -i alice.aac -bsf:a aac_adtstoasc -af volume=1.5 test.aac
F:\Youtube Extract\Music>ffmpeg -y -i alice.aac -bsf:a aac_adtstoasc -af volume=1.5 test.aac ffmpeg version N-54691-g7f4a1fd Copyright (c) 2000-2013 the FFmpeg developers built on Jul 12 2013 16:31:48 with gcc 4.7.3 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --en able-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-l ibgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable- libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora - -enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable- libxavs --enable-libxvid --enable-zlib libavutil 52. 39.100 / 52. 39.100 libavcodec 55. 18.102 / 55. 18.102 libavformat 55. 12.102 / 55. 12.102 libavdevice 55. 3.100 / 55. 3.100 libavfilter 3. 80.101 / 3. 80.101 libswscale 2. 3.100 / 2. 3.100 libswresample 0. 17.102 / 0. 17.102 libpostproc 52. 3.100 / 52. 3.100 [aac @ 0000000002529fe0] Estimating duration from bitrate, this may be inaccurate Input #0, aac, from 'alice.aac': Metadata: title : Alice Deejay - Better Off Alon Duration: 00:03:46.41, bitrate: 77 kb/s Stream #0:0: Audio: aac, 44100 Hz, stereo, fltp, 77 kb/s Output #0, adts, to 'test.aac': Metadata: title : Alice Deejay - Better Off Alon encoder : Lavf55.12.102 Stream #0:0: Audio: aac (libvo_aacenc), 44100 Hz, stereo, s16, 128 kb/s Stream mapping: Stream #0:0 -> #0:0 (aac -> libvo_aacenc) Press [q] to stop, [?] for help decode_band_types: Input buffer exhausted before END element found Error while decoding stream #0:0: Invalid data found when processing input [aac @ 0000000002536ea0] channel element 2.0 is not allocated Error while decoding stream #0:0: Error number -1 occurred size= 2440kB time=00:02:39.13 bitrate= 125.6kbits/s video:0kB audio:2487kB subtitle:0 global headers:0kB muxing overhead -1.884090%
So far as I understand, it's a bug for ffmpeg.
I have other samples, which throw other error.
P.S. Work in progress against annoying important de-synch bugs such as ticket 2400?
follow-up: 6 comment:5 by , 11 years ago
Resolution: | → worksforme |
---|---|
Status: | open → closed |
Replying to feelart:
I will close this ticket since I don't see much indication that there is anything that should (or can) be fixed in FFmpeg, feel free to reopen if you can add information that indicates I am wrong.
Same kind of fatal error both with
ffmpeg -i alice.aac -bsf:a aac_adtstoasc -vol 312 test.aac or ffmpeg -y -i alice.aac -bsf:a aac_adtstoasc -af volume=1.5 test.aac
bitstreamfilters (-bsf) only work with -codec copy so these command lines make no sense.
decode_band_types: Input buffer exhausted before END element found Error while decoding stream #0:0: Invalid data found when processing input [aac @ 0000000002536ea0] channel element 2.0 is not allocated Error while decoding stream #0:0: Error number -1 occurred
I assume this is what you mean with fatal errors:
The messages are shown because - as you already indicated in comment:1 - the sample was cut in the middle of the file, since it wasn't cut on a frame boundary ffmpeg inevitably will fail on the last, incomplete frame.
There is nothing fatal about these messages though, ffmpeg finishes transcoding as expected or do I miss something?
So far as I understand, it's a bug for ffmpeg.
I am not sure I understand: Did you test the output file with any professional or proprietary software or a stream analyzer? Did any of them indicate an invalid output file?
I have other samples, which throw other error.
It is (obviously) not always a bug if FFmpeg throws an error. If you think it is a bug that FFmpeg throws an error, please open a ticket on this bug tracker, if you are not sure, please post a question on the ffmpeg-user mailing list.
P.S. Work in progress against annoying important de-synch bugs such as ticket #2400?
Patch welcome but note that I suspect it is trivial to workaround that issue, just copy audio into an adts container.
follow-up: 7 comment:6 by , 11 years ago
Replying to cehoyos:
Replying to feelart:
I will close this ticket since I don't see much indication that there is anything that should (or can) be fixed in FFmpeg, feel free to reopen if you can add information that indicates I am wrong.
Same kind of fatal error both with
ffmpeg -i alice.aac -bsf:a aac_adtstoasc -vol 312 test.aac or ffmpeg -y -i alice.aac -bsf:a aac_adtstoasc -af volume=1.5 test.aacbitstreamfilters (-bsf) only work with -codec copy so these command lines make no sense.
That's not correct, bitstream filters are applied *after* filtering and *before* sending the packet to the muxer.
comment:7 by , 11 years ago
Replying to saste:
Replying to cehoyos:
Replying to feelart:
I will close this ticket since I don't see much indication that there is anything that should (or can) be fixed in FFmpeg, feel free to reopen if you can add information that indicates I am wrong.
Do you also disagree with the above? I absolutely may miss something but I was unable to reproduce any problems with the original sample and the original command lines.
Same kind of fatal error both with
ffmpeg -i alice.aac -bsf:a aac_adtstoasc -vol 312 test.aac or ffmpeg -y -i alice.aac -bsf:a aac_adtstoasc -af volume=1.5 test.aacbitstreamfilters (-bsf) only work with -codec copy so these command lines make no sense.
That's not correct, bitstream filters are applied *after* filtering and *before* sending the packet to the muxer.
(I missed that the bitstream filters also work without -codec copy but note that for the -codec copy case there is no filtering, so your description does not apply for the typical use-case.)
Do the command lines actually make sense? I thought the aac_adtstoasc bitstream filter is only useful when stream-copying from adts to mov.
follow-up: 9 comment:8 by , 11 years ago
I will close this ticket since I don't see much indication that there is anything that should (or can) be fixed in FFmpeg
Wrong, if you try to change the volume with FFMpeg the output audio can not be read any more ! AACgain just fails to perform the volume change(normalization), while ffmpeg produces a wrong audio.
bitstreamfilters (-bsf) only work with -codec copy so these command lines make no sense.
ffmpeg -i alice.aac -c:a copy -bsf:a aac_adtstoasc -vol 312 test.aac
That does not work, because copy and vol are mutually exclusive...
Also, wrong output with
ffmpeg -i alice.aac -vol 312 test.aac
Do the command lines actually make sense?
As far, as I understand FFmpeg, to me yes, maybe not to you.
P.S. Work in progress against annoying important de-synch bugs such as ticket #2400?
Patch welcome but note that I suspect it is trivial to workaround that issue, just copy audio into an adts container.
Well, if it is that trivial, I'm surprised it's not already patched, maybe for next commit.
comment:9 by , 11 years ago
Replying to feelart:
Also, wrong output with
ffmpeg -i alice.aac -vol 312 test.aac
Could you elaborate? The command succeeds here, what do you mean with wrong output?
P.S. Work in progress against annoying important de-synch bugs such as ticket #2400?
Patch welcome but note that I suspect it is trivial to workaround that issue, just copy audio into an adts container.
Well, if it is that trivial, I'm surprised it's not already patched, maybe for next commit.
I don't know how difficult it is to fix the issue, I wrote that it is trivial to workaround it (just remux to aac).
comment:10 by , 11 years ago
ffmpeg -i alice.aac -vol 312 test.aac
The command succeeds here.
Yes, but can't play output audio, it's rubbish.
However, converting this output to mp3, now plays well
ffmpeg -i test.aac testMP3.mp3
FYI: directly re-encode as mp3, no encoding or play problem.
ffmpeg -i alice.aac -vol 312 outMP3.mp3
CCl: mp3 is failure proofed, not aac.
My guess are that with aac encoding, there are some overflow un/miss-handling and/or un/miss properly closed output aac stream.
comment:11 by , 11 years ago
I used the following command line:
$ ffmpeg -i Alice.aac -vol 312 -acodec aac -strict -2 test.aac
and tested the output file with faad, WMP and QT (all not FFmpeg-based), all of them decode the file without problems (as do mplayer -ac ffaac
and mplayer -ac faad
and vlc and ffplay).
comment:12 by , 11 years ago
Indeed, adding "-acodec aac -strict -2" to the command line makes it playable, otherwise not.
But interestingly,
ffmpeg -i Alice.aac -c:a copy -bsf:a aac_adtstoasc tMP4.mp4
Ouput plays, but aacgain can't normalize it.
While,
ffmpeg -t 159 -i Alice.aac -c:a copy -bsf:a aac_adtstoasc tMP4.mp4
159 sec being the true duration, then aacgain do normalize tMP4.mp4
If you put - t 160 or more, again aacgain can't normalize it.
So something is wrong, guessing in closing stream, either by
ffmpeg -i Alice.aac -c:a copy -bsf:a aac_adtstoasc tMP4.mp4 or ffmpeg -t 160 -i Alice.aac -c:a copy -bsf:a aac_adtstoasc tMP4.mp4
comment:13 by , 11 years ago
To summarize, you can't copy the aac stream without forcing to specify its duration!
ffmpeg -y -t 160 -i Alice.aac -c:a copy -bsf:a aac_adtstoasc t160MP4.mp4
ffmpeg -y -i Alice.aac -c:a copy -bsf:a aac_adtstoasc tMP4.mp4 ffmpeg -t 159 -i tMP4.mp4 -c:a copy tForcedTo159MP4.mp4
ffmpeg -t 159 -i Alice.aac -c:a copy -bsf:a aac_adtstoasc t159.mp4
Aacgain, can not normalize both t160MP4 and tMP4.mp4, while both tForcedTo159MP4.mp4 and t159.mp4 do not raise any issue.
comment:15 by , 11 years ago
Wheter you don't want to see the bug or you consider it as non implemented feature, you've the final word and won't put the matter futher.
Try also to append/concat to another aac, you'll see it won't work
But I know, such type of issue wouldn't exist with mp3, as it is not an experimental lib.
comment:16 by , 11 years ago
I remember having spent some time with closely related issues before you opened this ticket and re-reading the ticket, it appears I have done quite extensive testing with the sample you provided.
As explained, it appears to me that:
- FFmpeg refuses to mux files that cannot be played with certain third party application (and prints an appropriate message)
- If the right bitstream filter was selected, FFmpeg produces an output file that plays with the mentioned applications (WMP, QT etc.)
- If the input file was badly edited (does not end at a frame boundary), FFmpeg prints a warning but succeeds muxing.
There absolutely may be an issue, but I was unable to reproduce it (using the command lines you provided).
If you believe there is an issue, please explain how it can be reproduced but if the explanation is just "WMP and QT play the file but aacgain fails" than I honestly wonder why you think the bug is in FFmpeg.
Of course stream is incomplete and stops at 2:49 and not at 3:46 as its duration.
But it just shows, the effect on a cut file.