[FFmpeg-trac] #6706(ffmpeg:new): channel_layout option ignored for non default layouts

FFmpeg trac at avcodec.org
Sat Sep 30 22:21:51 EEST 2017


#6706: channel_layout option ignored for non default layouts
-------------------------------------+-------------------------------------
             Reporter:  pkv          |                     Type:  defect
               Status:  new          |                 Priority:  normal
            Component:  ffmpeg       |                  Version:  git-
             Keywords:               |  master
  channel_layout                     |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------
 When selecting an output channel layout through -channel_output, if the
 channel layout is not a default one (ex: quad instead of 4.0, or octagonal
 instead of 7.1) , the option is ignored and the output is encoded with
 default layout.

 This error does not occur if one uses -af aformat to specify the layout.

 The defect does not depend on the muxer; I checked it occurs with mkv,
 wav, mp4. In the example below I use pcm as codec but I checked that the
 defect occurs also irrespective of the codec (ex: libopus, ...)

 I have pinpointed the source of the defect to:

 ffmpeg_opt.c, l.2526, function open_output_file (l.2091 of current head)

 {{{
 if (ost->enc_ctx->channels) {
                     f->channel_layout =
 av_get_default_channel_layout(ost->enc_ctx->channels);
                 }
 }}}

 These lines were introduced in commit
 198e8b8e774659eacaa7058c7f5704029af5bbbf ; however I don't think this is a
 regression because I could check the same errors occur on earlier builds.

 The error is most manifest in the case of '''identical input and output
 channel layouts''' (ex: both quad) because an '''auto-insertion of an
 auto_resampler filtergraph occurs''' to convert input from quad to 4.0
 while this should never happen (see below, last line of [auto_resampler]
 ).

 Here's uncut command line (build is latest one from zerano winx64 but
 defect is also on git-master head):


 {{{
 E:\ffmpeg-20170921-183fd30-win64-static\bin> ./ffmpeg -loglevel debug
 -channel_layout quad -i .\short4.wav -vn -c:a pcm_s16le -channel_layout
 quad -ar 48k shorter.wav
 ffmpeg version N-87353-g183fd30 Copyright (c) 2000-2017 the FFmpeg
 developers
   built with gcc 7.2.0 (GCC)
   configuration: --enable-gpl --enable-version3 --enable-cuda --enable-
 cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc
 --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
 --enable-gnutls --enable-iconv --enable-libass --enable-libbluray
 --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme
 --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame
 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264
 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy
 --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame
 --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-
 libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
 libx265 --enable-libxavs --enable-libxvid --enable-libxml2 --enable-
 libzimg --enable-lzma --enable-zlib
   libavutil      55. 76.100 / 55. 76.100
   libavcodec     57.106.101 / 57.106.101
   libavformat    57. 82.101 / 57. 82.101
   libavdevice    57.  8.101 / 57.  8.101
   libavfilter     6.105.100 /  6.105.100
   libswscale      4.  7.103 /  4.  7.103
   libswresample   2.  8.100 /  2.  8.100
   libpostproc    54.  6.100 / 54.  6.100
 Splitting the commandline.
 Reading option '-loglevel' ... matched as option 'loglevel' (set logging
 level) with argument 'debug'.
 Reading option '-channel_layout' ... matched as option 'channel_layout'
 (set channel layout) with argument 'quad'.
 Reading option '-i' ... matched as input url with argument '.\short4.wav'.
 Reading option '-vn' ... matched as option 'vn' (disable video) with
 argument '1'.
 Reading option '-c:a' ... matched as option 'c' (codec name) with argument
 'pcm_s16le'.
 Reading option '-channel_layout' ... matched as option 'channel_layout'
 (set channel layout) with argument 'quad'.
 Reading option '-ar' ... matched as option 'ar' (set audio sampling rate
 (in Hz)) with argument '48k'.
 Reading option 'shorter.wav' ... matched as output url.
 Finished splitting the commandline.
 Parsing a group of options: global .
 Applying option loglevel (set logging level) with argument debug.
 Successfully parsed a group of options.
 Parsing a group of options: input url .\short4.wav.
 Applying option channel_layout (set channel layout) with argument quad.
 Successfully parsed a group of options.
 Opening an input file: .\short4.wav.
 [NULL @ 0000000000706fe0] Opening '.\short4.wav' for reading
 [file @ 00000000011c2ec0] Setting default whitelist 'file,crypto'
 [wav @ 0000000000706fe0] Format wav probed with size=2048 and score=99
 [wav @ 0000000000706fe0] Before avformat_find_stream_info() pos: 102 bytes
 read:65638 seeks:1 nb_streams:1
 [wav @ 0000000000706fe0] parser not found for codec pcm_s24le, packets or
 times may be invalid.
     Last message repeated 1 times
 [wav @ 0000000000706fe0] All info found
 [wav @ 0000000000706fe0] After avformat_find_stream_info() pos: 204702
 bytes read:295014 seeks:1 frames:50
 Input #0, wav, from '.\short4.wav':
   Metadata:
     encoder         : Lavf57.82.101
   Duration: 00:00:05.00, bitrate: 4608 kb/s
     Stream #0:0, 50, 1/48000: Audio: pcm_s24le ([1][0][0][0] / 0x0001),
 48000 Hz, quad, s32 (24 bit), 4608 kb/s
 Successfully opened the file.
 Parsing a group of options: output url shorter.wav.
 Applying option vn (disable video) with argument 1.
 Applying option c:a (codec name) with argument pcm_s16le.
 Applying option channel_layout (set channel layout) with argument quad.
 Applying option ar (set audio sampling rate (in Hz)) with argument 48k.
 Successfully parsed a group of options.
 Opening an output file: shorter.wav.
 [file @ 0000000001212820] Setting default whitelist 'file,crypto'
 Successfully opened the file.
 Stream mapping:
   Stream #0:0 -> #0:0 (pcm_s24le (native) -> pcm_s16le (native))
 Press [q] to stop, [?] for help
 cur_dts is invalid (this is harmless if it occurs once at the start per
 stream)
 detected 8 logical cores
 [graph_0_in_0_0 @ 0000000001258280] Setting 'time_base' to value '1/48000'
 [graph_0_in_0_0 @ 0000000001258280] Setting 'sample_rate' to value '48000'
 [graph_0_in_0_0 @ 0000000001258280] Setting 'sample_fmt' to value 's32'
 [graph_0_in_0_0 @ 0000000001258280] Setting 'channel_layout' to value
 '0x33'
 [graph_0_in_0_0 @ 0000000001258280] tb:1/48000 samplefmt:s32
 samplerate:48000 chlayout:0x33
 [format_out_0_0 @ 000000000070b560] Setting 'sample_fmts' to value 's16'
 [format_out_0_0 @ 000000000070b560] Setting 'sample_rates' to value
 '48000'
 [format_out_0_0 @ 000000000070b560] Setting 'channel_layouts' to value
 '0x107'
 [format_out_0_0 @ 000000000070b560] auto-inserting filter
 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter
 'format_out_0_0'
 [AVFilterGraph @ 0000000001215b40] query_formats: 4 queried, 6 merged, 3
 already done, 0 delayed
 [auto_resampler_0 @ 000000000070bac0] [SWR @ 0000000001258fa0] Using fltp
 internally between filters
 [auto_resampler_0 @ 000000000070bac0] [SWR @ 0000000001258fa0] Matrix
 coefficients:
 [auto_resampler_0 @ 000000000070bac0] [SWR @ 0000000001258fa0] FL:
 FL:0.707107 FR:0.000000 BL:0.000000 BR:0.000000
 [auto_resampler_0 @ 000000000070bac0] [SWR @ 0000000001258fa0] FR:
 FL:0.000000 FR:0.707107 BL:0.000000 BR:0.000000
 [auto_resampler_0 @ 000000000070bac0] [SWR @ 0000000001258fa0] FC:
 FL:0.000000 FR:0.000000 BL:0.000000 BR:0.000000
 [auto_resampler_0 @ 000000000070bac0] [SWR @ 0000000001258fa0] BC:
 FL:0.000000 FR:0.000000 BL:0.500000 BR:0.500000
 [auto_resampler_0 @ 000000000070bac0] ch:4 chl:quad fmt:s32 r:48000Hz ->
 ch:4 chl:4.0 fmt:s16 r:48000Hz
 Output #0, wav, to 'shorter.wav':
   Metadata:
     ISFT            : Lavf57.82.101
     Stream #0:0, 0, 1/48000: Audio: pcm_s16le ([1][0][0][0] / 0x0001),
 48000 Hz, quad, s16, 3072 kb/s
     Metadata:
       encoder         : Lavc57.106.101 pcm_s16le
 [out_0_0 @ 000000000070b360] EOF on sink link out_0_0:default.
 No more output streams to write to, finishing.
 size=    1875kB time=00:00:05.00 bitrate=3072.2kbits/s speed= 277x
 video:0kB audio:1875kB subtitle:0kB other streams:0kB global headers:0kB
 muxing overhead: 0.005312%
 Input file #0 (.\short4.wav):
   Input stream #0:0 (audio): 704 packets read (2880480 bytes); 704 frames
 decoded (240040 samples);
   Total: 704 packets (2880480 bytes) demuxed
 Output file #0 (shorter.wav):
   Output stream #0:0 (audio): 704 frames encoded (240040 samples); 704
 packets muxed (1920320 bytes);
   Total: 704 packets (1920320 bytes) muxed
 704 frames successfully decoded, 0 decoding errors
 [AVIOContext @ 00000000007084a0] Statistics: 4 seeks, 11 writeouts
 [AVIOContext @ 0000000000707680] Statistics: 2946118 bytes read, 1 seeks
 }}}
 I have started investigating a patch; but I may need a few pointers on how
 to retrieve channel_layout , for instance from an OptionsContext (there is
 no channel_layout in the struct; presumably from OptionGroup g->codec_opts
 then ? not familiar enough with AvDictionary ).

--
Ticket URL: <https://trac.ffmpeg.org/ticket/6706>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list