Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multichannel LPCM always downmixed to stereo on HDMI 7.1-capable device #3319

Closed
GeoffMPV opened this issue Jul 6, 2016 · 14 comments

Comments

@GeoffMPV
Copy link

commented Jul 6, 2016

mpv git-ad2d10a built Feb 29 03:20:47

Reproduction steps

Play media file with multichannel non-bitstreamable audio such as LPCM-5.1

Expected behavior

Pass unchanged audio with original channel map to output

Actual behavior

ALSA reports HDMI device as stereo causing mpv to remix audio to 2.0

Log files

Extract below along with config files

Another ALSA headache, judging by the code comments in alsa.c. I'm hoping to have a single command-line call to mpv that will work for any media file with any audio, bitstreamable formats to be bitstreamed over HDMI to the AVR, all other formats to be passed/converted to multichannel LPCM over HDMI to the AVR.

System: Home Theatre PC - Asus Z87 board and Intel Ivybridge i3 CPU using onboard graphics/audio - no addon cards at all. The PC is connected via HDMI to an AV Receiver with 5.1 speakers, no other devices apart from the TV - a very simple system.

Bitstreaming works fine. I determined the correct device from the MPV audio-devices list and put it in the config file, along with the audio-spdif parameter. Media files with ac3, truehd, dts and dts-hd are bitstreamed over HDMI to the AVR that correctly identifies the format on its panel.

However despite trying numerous permutations of settings in various config files (such as .asoundrc), multichannel audio, e.g. LPCM-5.1, is always downmixed to 2.0. The verbose output confirms that ALSA is reporting the channel map as stereo FL FR, causing MPV to do a Remix, despite the alsacap utility reporting the capability as 2..8 channel:-

Log extract:-

[ad] Codec list:
[ad] lavc:pcm_s16le - PCM signed 16-bit little-endian
[ad] Opening audio decoder lavc:pcm_s16le
[ad] Requesting 1 threads for decoding.
[ad] Selected audio codec: PCM signed 16-bit little-endian [lavc:pcm_s16le]
[cplayer] Starting playback...
[af] Audio filter chain:
[af] [in] 48000Hz 5.1 6ch s16
[af] [out] 48000Hz 5.1 6ch s16
[af] [ao] 48000Hz 5.1 6ch s16
[ao] Trying audio driver 'alsa'
[ao] Using preferred device 'hdmi:CARD=PCH,DEV=0'
[ao/alsa] requested format: 48000 Hz, 5.1 channels, s16
[ao/alsa] using ALSA version: 1.0.27.2
[ao/alsa] opening device 'hdmi:CARD=PCH,DEV=0'
[ao/alsa] trying format s16
[ao/alsa] channel map reported by ALSA: FL FR
[ao/alsa] which we understand as: stereo
[ao/alsa] using the ALSA channel map.
[ao/alsa] which is what we requested.

alsacap output:-

*** Scanning for playback devices ***
Card 0, ID 'PCH', name 'HDA Intel PCH'
Device 0, ID 'ALC887-VD Analog', name 'ALC887-VD Analog', 1 subdevices (1 available)
2..6 channels, sampling rate 44100..192000 Hz
Sample formats: S16_LE, S32_LE
Subdevice 0, name 'subdevice #0'
Device 1, ID 'ALC887-VD Digital', name 'ALC887-VD Digital', 1 subdevices (1 available)
2 channels, sampling rate 32000..192000 Hz
Sample formats: S16_LE, S32_LE
Subdevice 0, name 'subdevice #0'
Device 3, ID 'HDMI 0', name 'HDMI 0', 1 subdevices (1 available)
2..8 channels, sampling rate 32000..192000 Hz
Sample formats: S16_LE, S32_LE
Subdevice 0, name 'subdevice #0'

mpv config file (the last 2 lines are probably redundant but I tried them anyway - makes no difference):-

ao=alsa
audio-device='alsa/hdmi:CARD=PCH,DEV=0'
audio-spdif=truehd,ac3,dts-hd
audio-channels=6
ad-lavc-downmix=no

mpv audio-device list:-

List of detected audio devices:
'auto' (Autoselect device)
'pulse/alsa_output.pci-0000_00_1b.0.hdmi-surround' (Built-in Audio Digital Surround 5.1 (HDMI))
'alsa/default' (Playback/recording through the PulseAudio sound server)
'alsa/hdmi:CARD=PCH,DEV=0' (HDA Intel PCH, HDMI 0/HDMI Audio Output)
'alsa/plughw:CARD=PCH,DEV=0' (HDA Intel PCH, ALC887-VD Analog/Hardware device with all software conversions)
'alsa/plughw:CARD=PCH,DEV=1' (HDA Intel PCH, ALC887-VD Digital/Hardware device with all software conversions)
'alsa/plughw:CARD=PCH,DEV=3' (HDA Intel PCH, HDMI 0/Hardware device with all software conversions)
'oss' (Default (oss))
'jack' (Default (jack))

aplay -l output:-

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC887-VD Analog [ALC887-VD Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: ALC887-VD Digital [ALC887-VD Digital]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0

@wm4

This comment has been minimized.

Copy link
Member

commented Jul 6, 2016

Seems like it doesn't list channel layouts at all?

You could try with the ignore-chmap suboption.

@GeoffMPV

This comment has been minimized.

Copy link
Author

commented Jul 6, 2016

Thanks very much for such a swift reply, I'll try that as soon as I can.

@GeoffMPV

This comment has been minimized.

Copy link
Author

commented Jul 7, 2016

I tried ignore-chmap in the mpv config file and thought it had worked when alsa reported a multichannel map, but:-

The channel map reported by alsa is FL FR RL RR FC LFE, which corresponds to the audio-channels parameter "5.1(alsa)". This results in audio going to the wrong speakers.
The LPCM in the movie is FL FR FC LFE RL RR, which corresponds to the parameter "5.1".

It's a Catch 22 now: I've tried specifing the correct channel map in audio-channels, both as "5.1" and an explicit channel layout, but in both cases of course ignore-chmap tells alsa to ignore it.

Research ongoing - if you can think of a good way out, let me know.
I found a way of setting a default channel map but it applies to Pulse, and the entanglement of alsa and Pulse is really confusing to me. Besides I don't know what other scenarios that might adversely affect.

@wm4

This comment has been minimized.

Copy link
Member

commented Jul 7, 2016

Well, if ALSA reports a channel map, it's not so bad.

But the problem seems to be that it doesn't list any channel maps, so mpv never gets so far?

@wm4

This comment has been minimized.

Copy link
Member

commented Jul 7, 2016

Also, if Pulse is running, you should probably use ao_pulse.

@GeoffMPV

This comment has been minimized.

Copy link
Author

commented Jul 13, 2016

A quick report on (lack of) progress on the original problem, it might help other people setting up an HTPC/AVR system.
To recap, I was hoping for a javascript function containing a single command-line call of mpv that worked correctly for any media file, bitstreaming audio to the AVR for all formats that support it and decoding all others to forward as multichannel LPCM. After a solid week with so many experiments I can't remember them all, I've concluded that it very likely can't be done.

I've adopted the more robust approach of separating bitstreamable formats from others and specifying a different audio device for each, which means an extra argument to the function and having two calls of mpv. Referring to my audio-devices file posted above, the arrangement that works in all cases is (in pseudo-code):

function play (mediafile, bitstreamable)
...
if bitstreamable then
mpv --audio-device=alsa/hdmi:CARD=PCH,DEV=0 ... mediafile
else
mpv --audio-device=pulse/alsa_output.pci-0000_00_1b.0.hdmi-surround audio-channels="5.1(side)" ... mediafile
...

Inelegant, but it works well and is easier to manage if something changes system-wise.
Interestingly the audio-channels argument "5.1" gave incorrect speaker output, I found by experimentation that it needed to be "5.1(side)".

@wm4

This comment has been minimized.

Copy link
Member

commented Jul 13, 2016

That seems like a blind hack.

Interestingly the audio-channels argument "5.1" gave incorrect speaker output, I found by experimentation that it needed to be "5.1(side)".

What?

@GeoffMPV

This comment has been minimized.

Copy link
Author

commented Jul 13, 2016

mpv --audio-channels=help lists three variations of 5.1:- "5.1", "5.1(alsa)" and "5.1(side)".
Playing a file with LPCM-5.1, using "5.1", the AVR indicated multichannel output but oddly the right rear speaker was silent. Changing it to "5.1(side)" all speakers appeared to work correctly.

@wm4

This comment has been minimized.

Copy link
Member

commented Jul 13, 2016

It might be setting the correct HDMI layout, and the AVR doesn't support it. Just a theory.

@noee

This comment has been minimized.

Copy link

commented Oct 8, 2016

I had the same problem (openSUSE TW w/Pulse installed). It started failing sometime in the last few months (had been working fine for a couple of years):

[ao/alsa] using ALSA version: 1.1.2                                                                                                      
[ao/alsa] opening device 'hdmi:CARD=HDMI,DEV=0'                                                                                          
[ao/alsa] trying format float                                                                                                            
[ao/alsa] trying format double                                                                                                           
[ao/alsa] trying format s32                                                                                                              
[ao/alsa] snd_pcm_query_chmaps() returned NULL

I then added the ignore-chmap option and set channels to 5.1(alsa) and now it works. When I tried pulse, the channels were clearly not mapped properly for my AVR and there was no sound.

Also interesting is that my audio player (JRiver MediaCenter) has handled alsa multichannel just fine.

@GeoffMPV

This comment has been minimized.

Copy link
Author

commented Oct 9, 2016

From this and other research, I've concluded that having multichannel LPCM in an MKV file is a very bad idea, the channel layout is unreliable. Some combination of the method used to produce the media file, the operating system, the software player and hardware will conspire to cause layout problems in some cases.
Fortunately for me, not many of my media files have LPCM-5.1 so I converted the audio to FLAC-5.1 and remuxed them, all work correctly now.

@noee

This comment has been minimized.

Copy link

commented Oct 9, 2016

fwiw, in my case, it was DTS, DTS-MA and AC3 that were in the MKV and were being decoded by "mpv" to multi-ch PCM for output where alsa::snd_pcm_query_chmaps() was returning NULL.

@wm4

This comment has been minimized.

Copy link
Member

commented Oct 14, 2016

ALSA obviously matters for output. I certainly wouldn't expect snd_pcm_query_champs() to return NULL, unless the kernel driver doesn't support it. (Or possibly some ALSA plugin "blocking" it.)

@Akemi Akemi added the ao:alsa label Sep 19, 2019

@Akemi

This comment has been minimized.

Copy link
Member

commented Sep 19, 2019

if this issue still persists, please open a new issue.

@Akemi Akemi closed this Sep 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.