Opened 4 years ago

Last modified 4 years ago

#3723 new defect

aac copy issue with -bsf:a aac_adtstoasc when container is not flv, m4a, mov or mp4

Reported by: feelart Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
When copying an aac from one container to another with the -bsf:a aac_adtstoasc Bitstream Filters, then ouput is malformed and can not be read of just for about 2 seconds.

Ref: https://www.ffmpeg.org/ffmpeg-bitstream-filters.html#aac_005fadtstoasc

How to reproduce:

ffmpeg -i aac_test.aac -c:a copy -bsf:a aac_adtstoasc aac_try_with_bsf.avi

An ouput is created, but can not be played.

Instead of avi, also try with aac, ac3, dts, wav, wmv and see the issue.

P.S. Maybe linked with
https://trac.ffmpeg.org/ticket/3715
https://trac.ffmpeg.org/ticket/3658

E:\_PS\dbtest\mm_audio_codec>ffmpeg -i aac_test.aac -c:a copy -bsf:a aac_adtstoasc aac_try_with_bsf.aac
ffmpeg version N-63968-g73d820e Copyright (c) 2000-2014 the FFmpeg developers
  built on Jun 15 2014 00:52:21 with gcc 4.8.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fo
ntconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --ena
ble-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable
-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-lib
schroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enab
le-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp -
-enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
  libavutil      52. 89.100 / 52. 89.100
  libavcodec     55. 66.101 / 55. 66.101
  libavformat    55. 43.100 / 55. 43.100
  libavdevice    55. 13.101 / 55. 13.101
  libavfilter     4.  8.100 /  4.  8.100
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
[aac @ 0000000002c984a0] Estimating duration from bitrate, this may be inaccurate
Input #0, aac, from 'aac_test.aac':
  Duration: 00:00:14.72, bitrate: 124 kb/s
    Stream #0:0: Audio: aac, 44100 Hz, stereo, fltp, 124 kb/s
Output #0, adts, to 'aac_try_with_bsf.aac':
  Metadata:
    encoder         : Lavf55.43.100
    Stream #0:0: Audio: aac, 44100 Hz, stereo, 124 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=     219kB time=00:00:14.02 bitrate= 128.1kbits/s
video:0kB audio:219kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%

E:\_PS\dbtest\mm_audio_codec>

Now, ffmpeg -i on output:

E:\_PS\dbtest\mm_audio_codec>ffmpeg -i aac_try_with_bsf.aac
ffmpeg version N-63968-g73d820e Copyright (c) 2000-2014 the FFmpeg developers
  built on Jun 15 2014 00:52:21 with gcc 4.8.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fo
ntconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --ena
ble-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable
-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-lib
schroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enab
le-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp -
-enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
  libavutil      52. 89.100 / 52. 89.100
  libavcodec     55. 66.101 / 55. 66.101
  libavformat    55. 43.100 / 55. 43.100
  libavdevice    55. 13.101 / 55. 13.101
  libavfilter     4.  8.100 /  4.  8.100
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
[aac @ 0000000000310280] Format aac detected only with low score of 1, misdetection possible!
[aac @ 00000000051504e0] channel element 1.0 is not allocated
[aac @ 00000000051504e0] More than one AAC RDB per ADTS frame is not implemented. Update your FFmpeg version to t
he newest one from Git. If the problem still occurs, it means that your file has a feature which has not been imp
lemented.
[aac @ 00000000051504e0] Number of bands (12) exceeds limit (9).
[aac @ 00000000051504e0] channel element 2.14 is not allocated
[aac @ 00000000051504e0] Assuming an incorrectly encoded 7.1 channel layout instead of a spec-compliant 7.1(wide)
 layout, use -strict 1 to decode according to the specification instead.
[aac @ 00000000051504e0] channel element 3.13 is not allocated
[aac @ 00000000051504e0] Input buffer exhausted before END element found
[aac @ 00000000051504e0] Assuming an incorrectly encoded 7.1 channel layout instead of a spec-compliant 7.1(wide)
 layout, use -strict 1 to decode according to the specification instead.
[aac @ 00000000051504e0] channel element 3.2 is not allocated
[aac @ 00000000051504e0] Sample rate index in program config element does not match the sample rate index configu
red by the container.
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] channel element 1.9 is not allocated
[aac @ 00000000051504e0] channel element 2.5 is not allocated
[aac @ 00000000051504e0] channel element 2.6 is not allocated
[aac @ 00000000051504e0] Number of bands (22) exceeds limit (21).
[aac @ 00000000051504e0] Reserved bit set.
[aac @ 00000000051504e0] channel element 2.13 is not allocated
[aac @ 00000000051504e0] Reserved bit set.
[aac @ 00000000051504e0] channel element 2.2 is not allocated
[aac @ 00000000051504e0] Assuming an incorrectly encoded 7.1 channel layout instead of a spec-compliant 7.1(wide)
 layout, use -strict 1 to decode according to the specification instead.
[aac @ 00000000051504e0] Number of bands (9) exceeds limit (4).
[aac @ 00000000051504e0] channel element 2.0 is not allocated
[aac @ 00000000051504e0] channel element 2.2 is not allocated
[aac @ 00000000051504e0] channel element 3.1 is not allocated
[aac @ 00000000051504e0] Assuming an incorrectly encoded 7.1 channel layout instead of a spec-compliant 7.1(wide)
 layout, use -strict 1 to decode according to the specification instead.
[aac @ 00000000051504e0] Reserved bit set.
[aac @ 00000000051504e0] Sample rate index in program config element does not match the sample rate index configu
red by the container.
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] Prediction is not allowed in AAC-LC.
[aac @ 00000000051504e0] Sample rate index in program config element does not match the sample rate index configu
red by the container.
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] SBR was found before the first channel element.
[aac @ 00000000051504e0] channel element 3.10 is not allocated
[aac @ 00000000051504e0] Sample rate index in program config element does not match the sample rate index configu
red by the container.
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] Reserved bit set.
[aac @ 00000000051504e0] channel element 2.11 is not allocated
[aac @ 00000000051504e0] Assuming an incorrectly encoded 7.1 channel layout instead of a spec-compliant 7.1(wide)
 layout, use -strict 1 to decode according to the specification instead.
[aac @ 00000000051504e0] Sample rate index in program config element does not match the sample rate index configu
red by the container.
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] channel element 2.1 is not allocated
[aac @ 00000000051504e0] Reserved bit set.
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] Reserved bit set.
[aac @ 00000000051504e0] channel element 2.1 is not allocated
[aac @ 00000000051504e0] invalid band type
[aac @ 00000000051504e0] SBR was found before the first channel element.
[aac @ 00000000051504e0] Sample rate index in program config element does not match the sample rate index configu
red by the container.
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] Reserved bit set.
[aac @ 00000000051504e0] Sample rate index in program config element does not match the sample rate index configu
red by the container.
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] Assuming an incorrectly encoded 7.1 channel layout instead of a spec-compliant 7.1(wide)
 layout, use -strict 1 to decode according to the specification instead.
[aac @ 00000000051504e0] channel element 3.9 is not allocated
[aac @ 00000000051504e0] Reserved bit set.
[aac @ 00000000051504e0] decode_pce: Input buffer exhausted before END element found
[aac @ 00000000051504e0] Sample rate index in program config element does not match the sample rate index configu
red by the container.
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] Dependent coupling is not supported together with LTP
    Last message repeated 31 times
[aac @ 00000000051504e0] Sample rate index in program config element does not match the sample rate index configu
red by the container.
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] Inconsistent channel configuration.
[aac @ 00000000051504e0] get_buffer() failed
[aac @ 00000000051504e0] Assuming an incorrectly encoded 7.1 channel layout instead of a spec-compliant 7.1(wide)
 layout, use -strict 1 to decode according to the specification instead.
[aac @ 00000000051504e0] channel element 2.4 is not allocated
[aac @ 00000000051504e0] channel element 3.15 is not allocated
[aac @ 00000000051504e0] Reserved bit set.
[aac @ 0000000000310280] decoding for stream 0 failed
[aac @ 0000000000310280] Estimating duration from bitrate, this may be inaccurate
[aac @ 0000000000310280] Could not find codec parameters for stream 0 (Audio: aac, stereo, fltp, 1109 kb/s): unsp
ecified sample rate
Consider increasing the value for the 'analyzeduration' and 'probesize' options
aac_try_with_bsf.aac: could not find codec parameters

E:\_PS\dbtest\mm_audio_codec>

Attachments (1)

aac_test.aac (223.5 KB) - added by feelart 4 years ago.

Download all attachments as: .zip

Change History (8)

Changed 4 years ago by feelart

comment:1 in reply to: ↑ description Changed 4 years ago by cehoyos

Replying to feelart:

ffmpeg -i aac_test.aac -c:a copy -bsf:a aac_adtstoasc aac_try_with_bsf.avi

I thought that avi needs the aac data in adts format and your input file is in adts format, why do you want to use the bitstream filter?

comment:2 Changed 4 years ago by feelart

I do wish not to use the bitstream filter, I'd rather prefer it is left internally.
However, as I understood it is a must requirement for m4a, flv, mp4 and mov.

As I understand, bsf is a mutual exclusive flag: you must use it on certain containers (m4a, flv, mp4 and mov), but must not on all others.

In the following CLI, ffmpeg clearly mentions "Conversion failed!" and no empty output (1 Kb)is created.

While in 1st example, namely:

>ffmpeg -i aac_test.aac -c:a copy -bsf:a aac_adtstoasc aac_try_with_bsf.aac

ffmpeg ought to exist, but currently does not and more prone to error creates an apparently good output.

This is either a feature enhancement or bug.

E:\_PS\dbtest\mm_audio_codec>ffmpeg -i aac_test.aac -c:a copy aac_try_with_bsf.mp4
ffmpeg version N-63968-g73d820e Copyright (c) 2000-2014 the FFmpeg developers
  built on Jun 15 2014 00:52:21 with gcc 4.8.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fo
ntconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --ena
ble-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable
-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-lib
schroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enab
le-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp -
-enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
  libavutil      52. 89.100 / 52. 89.100
  libavcodec     55. 66.101 / 55. 66.101
  libavformat    55. 43.100 / 55. 43.100
  libavdevice    55. 13.101 / 55. 13.101
  libavfilter     4.  8.100 /  4.  8.100
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
[aac @ 0000000000318320] Estimating duration from bitrate, this may be inaccurate
Input #0, aac, from 'aac_test.aac':
  Duration: 00:00:14.72, bitrate: 124 kb/s
    Stream #0:0: Audio: aac, 44100 Hz, stereo, fltp, 124 kb/s
Output #0, mp4, to 'aac_try_with_bsf.mp4':
  Metadata:
    encoder         : Lavf55.43.100
    Stream #0:0: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 124 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0000000004ee42e0] 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
size=       0kB time=00:00:00.02 bitrate=  88.9kbits/s
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

E:\_PS\dbtest\mm_audio_codec>

comment:3 Changed 4 years ago by cehoyos

Do I understand correctly that your request is that FFmpeg should warn if an invalid file is muxed?
And not that you want to mux asc into avi?

comment:4 Changed 4 years ago by feelart

ffmpeg should have a consistent behaviour and prevent failure.

ffmpeg -i <audioFile.container1> -c:a copy <audioFile.container2>

works for all audio(at least the one I usually use), EXCEPT when the audio is aac. In the case of aac, you have to know whether or not you must add or not -bsf:a aac_adtstoasc depending on the output container, i.e. the container gives the rule.

This is
1/ cumbersome for batch processing
One needs to program execeptions, that ffmpeg internally already partially do, it's "just" adding some test as:
WHEN (output_container) IN [m4a, flv, mov, mp4]

do -bsf:a aac_adtstoasc

ELSE do not apply -bsf:a aac_adtstoasc.

2/ prone to error and false error reporting

3/ currently, if you do apply -bsf:a aac_adtstoasc when the output container is NOT [m4a, flv, mov, mp4] a full size but corrupted file is created.
Additionally, it's really bad if you deleted the original file, thinking the change of container was well performed and realize sometimes later that the convertion failed.

comment:5 Changed 4 years ago by cehoyos

It is possible that this specific issue - avi does not warn if invalid aac stream are written - gets fixed but please understand that generally, ffmpeg (and the libraries) cannot guess what you want: If you specify a bitstream filter on the command line, you should expect that it is used and if you don't specify a bitstream filter, it won't be used. (There is a feature request for automatically inserting bitstream filters but this is not trivial and it is not what you request in your ticket description.)
Please understand that it is not the fault of the FFmpeg developers that different methods of writing aac into containers are defined.

comment:6 follow-up: Changed 4 years ago by feelart

It is possible that this specific issue - avi

It is not at all specific to avi, it is also for ac3, eac3, wav, wmv, etc.
It applies to ALL CONTAINERS to the exception of: m4a, flv mp4, mov.

if invalid aac stream are written - gets fixed but please understand that generally, ffmpeg (and the libraries) cannot guess what you want.

What do you mean? To my knowledge I do no see any guess in the command line, only a specific instruction to perform.
Furthermore, if you instruct

ffmpeg -i aac_test.aac -c:a copy aac_complain.flv

Than ffmpeg does complain and stop execution.

If you specify a bitstream filter on the command line, you should expect that it is used and if you don't specify a bitstream filter, it won't be used.

Normal, I do expect so, but one also expects that if one instructs something wrong, than at least a warning is raised. In the present case it is not.
Try for instance:

ffmpeg -i someOpusFile.opus -c:a copy someOpusFile.mp4

It won't work, but you wouldn't be "happy" if a "dummy" corrupted file was generated.

There is a feature request for automatically inserting bitstream filters but this is not trivial and it is not what you request in your ticket description.

The minimun request is to raise execution warning, if not a stop (stop is definitely desired for batch processing).
As there is already some IF clause to test for [m4a, flv mp4, mov], all I request is some ELSE clause.

Please understand that it is not the fault of the FFmpeg developers that different methods of writing aac into containers are defined.

I do understand.
All I try is to help making ffmpeg better and reliable, by I say that internally ffmpeg ought to handle whether or not to add a bitstream filter, instead of each user having to deal with it and every developer to write some switch statement - probably more by trial and error, than by aac specification knowledge.

comment:7 in reply to: ↑ 6 Changed 4 years ago by cehoyos

Replying to feelart:

It is possible that this specific issue - avi

It is not at all specific to avi, it is also for ac3

Please explain why putting aac into an ac3 container should produce a working file (one that has anything to do with ac3)?

eac3

Same: How can putting aac into eac3 produce anything useful (related to eac3)?

It applies to ALL CONTAINERS to the exception of: m4a, flv mp4, mov.

Yes: You request to output an invalid file and FFmpeg outputs an invalid file.
I don't think it will be possible to avoid all cases, we do try to avoid the obvious and hard-to-guess cases, but specifying a bitstream filter on the command line and expecting FFmpeg to know that the bitstream filter should not be used is asking too much imo.

Or in other words: You will always find command lines that produce invalid output files.

As there is already some IF clause to test for [m4a, flv mp4, mov], all I request is some ELSE clause.

No such if exists where the else clause would help with your issue.

Note: See TracTickets for help on using tickets.