Opened 17 months ago

#9248 new defect

FFplay does not try to guess channel layout for stereo wav-files with WAVE_FORMAT_PCM header

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


Creating the test file:

ffmpeg -f lavfi -i aevalsrc='sin(864*2*PI*t):c=stereo:d=3' aevalsrc.wav

Opening 'aevalsrc.wav' with ffmpeg you'll see:

ffmpeg -i aevalsrc.wav
Guessed Channel Layout for Input Stream #0.0 : stereo

This wav-file doesn't have a channel-layout-tag, so ffmpeg tries to guess it and sets the channel layout to stereo in this case. In order for ffmpeg not having to guess, you can manually specify -channel_layout stereo, which has the same outcome.
The channel layout is now set, which ffmpeg reports (with a more verbose loglevel) as:

[graph_0_in_0_0 @ xxx] [...] chlayout:0x3

With ffplay however this is not the case. It does play 'aevalsrc.wav', but also reports:

ffplay -v 40 aevalsrc.wav
[ffplay_abuffer @ xxx] [...] chlayout:(null)

According to the docs ffplay should have a -channel_layout option...

ffplay --help | grep "\-channel_layout"
  -channel_layout    <uint64>     ED..A...... (from 0 to 1.84467e+19) (default 0)

...but that somehow doesn't work:

ffplay -channel_layout stereo aevalsrc.wav
[pcm_s16le @ xxx] [Eval @ 05a6f2cc] Undefined constant or missing '(' in 'stereo'
[pcm_s16le @ xxx] Unable to parse option value "stereo"
[pcm_s16le @ xxx] Error setting option channel_layout to value stereo.

"The wav-file plays, so what's the problem?", you might say. Problems start to occur however when audio-filters are applied, like changing the tempo and pitch for instance:

ffplay -af "asetrate=22050" aevalsrc.wav
[auto_resampler_0 @ xxx] Cannot select channel layout for the link between filters auto_resampler_0 and Parsed_asetrate_0.
[auto_resampler_0 @ xxx] Unknown channel layouts not supported, try specifying a channel layout using 'aformat=channel_layouts=something'.

Using the "aformat"-filter, -af "aformat=cl=stereo,asetrate=22050", obviously works, though the channel layout is still unknown:

[ffplay_abuffer @ xxx] [...] chlayout:(null)

I don't understand however why -af "aformat=cl=stereo" is necessary for ffplay, why -channel_layout stereo doesn't work and why in the first place it doesn't try to guess the channel layout like ffmpeg does.

The only way I've found to play the wav-file with ffplay without the need for -af "aformat=cl=stereo" is to open 'aevalsrc.wav' with Audacity and save it as a wav-file with a WAVEX (WAVE_FORMAT_EXTENSIBLE) header. That way ffplay does recognize the channel layout:

[ffplay_abuffer @ xxx] [...] chlayout:0x3

Why with Audacity? Because of 'libavformat/riffenc.c'...

79 waveformatextensible = (par->channels > 2 && par->channel_layout) ||
80 par->channels == 1 && par->channel_layout && par->channel_layout != AV_CH_LAYOUT_MONO ||
81 par->channels == 2 && par->channel_layout && par->channel_layout != AV_CH_LAYOUT_STEREO ||
82 par->sample_rate > 48000 ||
83 par->codec_id == AV_CODEC_ID_EAC3 ||
84 av_get_bits_per_sample(par->codec_id) > 16;

...I believe ffmpeg never saves stereo audio streams as wav-files with a WAVEX header. And as far as I know there's no way to force that.

Change History (0)

Note: See TracTickets for help on using tickets.