Opened 6 years ago

Last modified 2 years ago

#7273 open defect

Exported AAC does not work properly

Reported by: DriverX Owned by:
Priority: important Component: ffmpeg
Version: 4.0.6 Keywords: aac regression
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

How to reproduce:

% ffmpeg -i in.flac -acodec aac -b:a 384k out.aac
ffmpeg version 4.0.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 8.1.1 (GCC) 20180531

If I open 'out.aac' from the beginning (0 seconds), everythings works fine and I can jump at any position with no problem.
But if the player try to start to reproduce it from the middle of the file (2 or 3 minutes) the player hangs and it do not reproduce the file.
I have tested this behavior with smplayer (with mpv) and also with kodi.
If the AAC file is embedded in an mkv with multiple audio tracks I can't switch from an audio track to another one, unless I move back to the start of the file.

Also, the exported file has a wrong channel layout,
if the original file was:
Channel positions: Front: L C R, Side: L R, LFE
the exported one is:
Channel positions: Front: L C R, Side: C, Back: L R
I don't know if this 2 problems are related but it's the only difference that i noticed.

With ffmpeg 3.4.2 everythings works fine, instead with ffmpeg 4.0.1 I have this issue.

Change History (8)

comment:1 by Carl Eugen Hoyos, 6 years ago

Component: ffmpegundetermined
Keywords: aac regression added

This has currently very little similarities with a valid ticket.

Do you want to report a regression since fbf295e2?

in reply to:  1 comment:2 by DriverX, 6 years ago

Replying to cehoyos:

I'm sorry if this is not good.
I just wanted to report a bug and I described it.


Do you want to report a regression since fbf295e2?

I want to report a regression from 3.4.2, I don't know where I can find this 'fbf295e2' code.
I checked the git ID of the commit related to 3.4.2 but it is not 'fbf295e2'.


Please tell me what I can do to improve this ticket
Thank you

comment:3 by Carl Eugen Hoyos, 6 years ago

If you cannot compile fbf295e2 yourself, please test current FFmpeg git head (nothing else is supported here), provide the command line you tested together with the complete, uncut console output and explain if I can reproduce with ffplay/ffmpeg or only with other players.

comment:4 by DriverX, 6 years ago

I compiled and tested this with the current git head.

The output when I convert a file into AAC:

ffmpeg -v debug -i in.flac -acodec aac -b:a 384k out.aac                                                                                                                       :(
ffmpeg version N-91398-gd08d4a8c73 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 8.1.1 (GCC) 20180531
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avresample --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
  libavutil      56. 18.102 / 56. 18.102
  libavcodec     58. 20.104 / 58. 20.104
  libavformat    58. 17.101 / 58. 17.101
  libavdevice    58.  4.101 / 58.  4.101
  libavfilter     7. 25.100 /  7. 25.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument 'debug'.
Reading option '-i' ... matched as input url with argument 'in.flac'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'aac'.
Reading option '-b:a' ... matched as option 'b' (video bitrate (please use -b:v)) with argument '384k'.
Reading option 'out.aac' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url in.flac.
Successfully parsed a group of options.
Opening an input file: in.flac.
[NULL @ 0x55950e7cfb40] Opening 'in.flac' for reading
[file @ 0x55950e7d0640] Setting default whitelist 'file,crypto'
[flac @ 0x55950e7cfb40] Format flac probed with size=2048 and score=100
[flac @ 0x55950e7cfb40] Before avformat_find_stream_info() pos: 86 bytes read:32768 seeks:0 nb_streams:1
[flac @ 0x55950e7cfb40] All info found
[flac @ 0x55950e7cfb40] After avformat_find_stream_info() pos: 54272 bytes read:65536 seeks:0 frames:1
Input #0, flac, from 'in.flac':
  Duration: 00:57:47.26, start: 0.000000, bitrate: 1626 kb/s
    Stream #0:0, 1, 1/48000: Audio: flac, 48000 Hz, 5.1(side), s16
Successfully opened the file.
Parsing a group of options: output url out.aac.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument aac.
Applying option b:a (video bitrate (please use -b:v)) with argument 384k.
Successfully parsed a group of options.
Opening an output file: out.aac.
[file @ 0x55950e7fb340] Setting default whitelist 'file,crypto'
Successfully opened the file.
detected 4 logical cores
Stream mapping:
  Stream #0:0 -> #0:0 (flac (native) -> aac (native))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 4 times
[graph_0_in_0_0 @ 0x55950e8877c0] Setting 'time_base' to value '1/48000'
[graph_0_in_0_0 @ 0x55950e8877c0] Setting 'sample_rate' to value '48000'
[graph_0_in_0_0 @ 0x55950e8877c0] Setting 'sample_fmt' to value 's16'
[graph_0_in_0_0 @ 0x55950e8877c0] Setting 'channel_layout' to value '0x60f'
[graph_0_in_0_0 @ 0x55950e8877c0] tb:1/48000 samplefmt:s16 samplerate:48000 chlayout:0x60f
[format_out_0_0 @ 0x55950e887dc0] Setting 'sample_fmts' to value 'fltp'
[format_out_0_0 @ 0x55950e887dc0] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350'
[format_out_0_0 @ 0x55950e887dc0] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
[AVFilterGraph @ 0x55950e880800] query_formats: 4 queried, 6 merged, 3 already done, 0 delayed
[auto_resampler_0 @ 0x55950e88ab40] [SWR @ 0x55950e88b040] Using s16p internally between filters
[auto_resampler_0 @ 0x55950e88ab40] ch:6 chl:5.1(side) fmt:s16 r:48000Hz -> ch:6 chl:5.1(side) fmt:fltp r:48000Hz
[aac @ 0x55950e7d7b00] Using a PCE to encode channel layout
Output #0, adts, to 'out.aac':
  Metadata:
    encoder         : Lavf58.17.101
    Stream #0:0, 0, 1/48000: Audio: aac (LC), 48000 Hz, 5.1(side), fltp (16 bit), delay 1024, 384 kb/s
    Metadata:
      encoder         : Lavc58.20.104 aac
[NULL @ 0x55950e7d1480] dropping low score -39 frame header from offset 7452 to 15662
[NULL @ 0x55950e7d1480] dropping low score -39 frame header from offset 18664 to 21583
[NULL @ 0x55950e7d1480] dropping low score -39 frame header from offset 2045 to 17809
[NULL @ 0x55950e7d1480] dropping low score -59 frame header from offset 12830 to 18432
[NULL @ 0x55950e7d1480] dropping low score -45 frame header from offset 3096 to 16319
[flac @ 0x55950e7cfb40] first_dts 0 not matching first dts 166391808 (pts 166391808, duration 4096) in the queue
[out_0_0 @ 0x55950e888900] EOF on sink link out_0_0:default.
No more output streams to write to, finishing.
size=  163837kB time=00:57:47.26 bitrate= 387.1kbits/s speed=36.3x    
video:0kB audio:162726kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.682780%
Input file #0 (in.flac):
  Input stream #0:0 (audio): 40632 packets read (705031862 bytes); 40632 frames decoded (166428672 samples); 
  Total: 40632 packets (705031862 bytes) demuxed
Output file #0 (out.aac):
  Output stream #0:0 (audio): 162528 frames encoded (166428672 samples); 162529 packets muxed (166631336 bytes); 
  Total: 162529 packets (166631336 bytes) muxed
40632 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x55950e7fb4c0] Statistics: 0 seeks, 640 writeouts
[aac @ 0x55950e7d7b00] Qavg: 232.956
[AVIOContext @ 0x55950e7d8a80] Statistics: 705031948 bytes read, 0 seeks

If I reproduce the file with ffplay, from the beginning it works fine.

Instead if I reproduce the file by specifing -ss in ffplay I get this error and no sound is played:

ffplay -ss 0:2:0.000 out.aac                                                                                                                                                   :(
ffplay version N-91398-gd08d4a8c73 Copyright (c) 2003-2018 the FFmpeg developers
  built with gcc 8.1.1 (GCC) 20180531
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avresample --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
  libavutil      56. 18.102 / 56. 18.102
  libavcodec     58. 20.104 / 58. 20.104
  libavformat    58. 17.101 / 58. 17.101
  libavdevice    58.  4.101 / 58.  4.101
  libavfilter     7. 25.100 /  7. 25.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
[aac @ 0x7f4a0c000b80] Estimating duration from bitrate, this may be inaccurate
Input #0, aac, from 'out.aac':
  Duration: 01:19:13.09, bitrate: 282 kb/s
    Stream #0:0: Audio: aac (LC), 48000 Hz, 6 channels, fltp, 388 kb/s
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated
    Last message repeated 684 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2096 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 1803 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2153 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2125 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2178 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2159 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2091 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2108 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2159 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2167 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2173 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2196 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2189 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2157 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2153 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2152 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2181 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2103 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2105 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2182 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2191 times
[aac @ 0x7f4a0c2528c0] channel element 0.1 is not allocated f=0/0   
    Last message repeated 2233 times

If I convert a 2.0 track instead of a 5.1 there are no issues.

comment:5 by Christoph Rackwitz, 3 years ago

I am encountering this issue too, from an original DTS track with [C L R Ls Rs LFE] layout, which is mapped to AAC [L R C Cb Lb Rb]. those channel layouts are reported by mediainfo. playback in VLC confirms mixed up channels.

I was made aware of this ticket from https://stackoverflow.com/questions/51908093/converting-dts-to-aac-with-ffmpeg-shifts-spoken-audio-to-the-right

I will attempt to compile the information you requested, from my situation. I think this issue needs attention.

comment:7 by Christoph Rackwitz, 3 years ago

input:
ffmpeg v4.3.1 says Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
VLC 3.0.11 says 3F2M/LFE

during encode, ffmpeg does say
[aac @ 000001a8e96a1400] Using a PCE to encode channel layout "5.1(side)"
and
Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, 5.1(side), fltp, 384 kb/s (default)

output:
ffprobe says Audio: aac (LC), 48000 Hz, 6 channels, fltp (default)
VLC says Unknown-chan-mask

demanding -af "channelmap=channel_layout=5.1(side)" changes nothing.

is there a workaround? I was hoping to at least be able to help ffmpeg do the right thing with some arguments/switches.

my current workaround is to use an old build of v3.4.2 which I'm not too happy about because it says 5.1(side) while encoding, but probing the file reports just 5.1, which is better than 6 but not the same as 5.1(side).

Last edited 3 years ago by Christoph Rackwitz (previous) (diff)

comment:8 by juanitogan, 2 years ago

Component: undeterminedffmpeg
Version: unspecified4.0.6

Still having this issue in ffmpeg 5.0.

It appears that regardless of how I produce an AAC with 5.1 channels of FL+FR+FC+LFE+SL+SR, ffprobe always reports channel_layout=unknown like so:

[STREAM]
index=1
codec_name=aac
codec_long_name=AAC (Advanced Audio Coding)
profile=LC
codec_type=audio
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=fltp
sample_rate=48000
channels=6
channel_layout=unknown
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
extradata_size=26
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
DISPOSITION:captions=0
DISPOSITION:descriptions=0
DISPOSITION:metadata=0
DISPOSITION:dependent=0
DISPOSITION:still_image=0
TAG:language=eng
TAG:ENCODER=Lavc59.18.100 aac
TAG:DURATION=00:01:00.021000000
[/STREAM]

I've tried all sorts of workarounds including:

-channel_layout "5.1(side)"
-channel_layout FL+FR+FC+LFE+SL+SR
-channel_layout 1551
-af "channelmap=
-af "channelmap=map=
-af "aformat=channel_layouts=
-filter_complex "channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR];[FL][FR][FC][BL][BR][LFE]join=inputs=6:channel_layout=1551:map=0.0-FL|1.0-FR|2.0-FC|3.0-SL|4.0-SR|5.0-LFE[a]"

... and who knows what else.

Currently, a somewhat useful alternative appears to be to explicitly convert 5.1(side) to 5.1 (with something like -channel_layout 5.1) ... but I've only loosely checked the stereo output of that so far and cannot yet say where the other channels land.

Note: See TracTickets for help on using tickets.