Closed cloph closed 5 years ago
What is this issue about?
Who would want to create matrix-encoded audio? At best you'd probably want to decode it...
This is about being able to have surround sound via your dedicated receiver, when
To transfer surround via a single analog stereo connection, the ProLogic scheme was created by Dolby - that works by mapping identical left and right sounds to the center channel, and phase-inverted identical sounds to the surround speakers.
So the scenario where this is needed is for example: You play back the video on your laptop, but that doesn't have a digital output, only a stereo headphone jack. Or you simply have an old receiver that doesn't support digital audio Or you connect via HDMI/DisplayPort that does support digital audio, but your TV doesn't have suitable audio-out to pass into your receiver..
So the media file you play back has multichannel sound, and you have a set of 5.1 speakers (or just 4.0 in case of ProLogic, but still...) and you want to make use of those.
Ideally pulseaudio would allow to configure and select the downmix-to-prologic, but I didn't find a way to do so.
Have you tried this?
[dolby]
profile-desc="downmix 5.1 surround to Dolby Pro Logic compatible stereo"
af=lavrresample=o="matrix_encoding=dolby"
[dplii]
profile-desc="downmix 5.1 surround to Dolby Pro Logic II compatible stereo"
af=lavrresample=o="matrix_encoding=dplii"
[dpl-nolfe]
profile-desc="downmix 5.1 surround to Dolby Pro Logic compatible stereo - ignoring lfe"
af=lavrresample=o="matrix_encoding=dolby,mix_lfe_level=0"
[dplii-nolfe]
profile-desc="downmix 5.1 surround to Dolby Pro Logic II compatible stereo - ignoring lfe"
af=lavrresample=o="matrix_encoding=dplii,mix_lfe_level=0"
the lavrresample ones don't work - the syntax in the comment is not accepted, and using [ ] instead of the quotes doesn't do anything, neither did any of the other ones suggested on IRC work.
And as the purpose of downmixing has once again be queried on IRC: Not only for supporting surround-sound via a stereo-only connection (because that's all your receiver supports and that your playback device can offer), but also for playing back via stereo speaker setup this is useful. Default pulseaudio downmixing for example is very annoying to watch - the balance is off most of the time. Dialogue almost impossible to hear, so you increase the volume, but explosions and effects then blow out your ears... The downmixing using the pro-logic one has much nicer listening experience.
so this is meant to be used when
but all you can use is either a stereo-only setup or a stereo-only connection to your receiver. Think of a laptop connected to a big computer monitor. Computer monitors usually don't offer a way to output the audio/video signal, and laptops typically only have a stereo-audio output.
So if you as maintainers don't think it is useful to either have a easy-to-use audio-filter string or the profile or as samples in the documentation ā feel free to close the issue - there's no point in having it sitting around forever. I have it in my config after all and am happy with it :-)
Thanks, do you have a profile for 7.1 also?
sorry, no 7.1 profile, as I neither have 7.1 speaker setup nor 7.1 source to test with. But as it cannot be decoded back to 7.1 anyway using the ProLogic variants (IIRC it is only extrapolation on decode on using the additional channels), I'd just add the additional channels to the front left and right.
In other words: add another set of "1,0,0,1" to map the left additional surround to left channel, and right additional surround to right channel. You might reduce the value if it is too dominant. - or just drop those additional channels alltogether - that's easiest (and less likely to cause problems decoding).
Will do some testing, thanks.
There is missing hilbert transform in you encoder.
There is missing hilbert transform in you encoder.
Yes, the spec requires a 90 degree phase shift at all frequencies of the rear channels like in this implementation. Took a look at audio_mix.c and audio_mix_matrix.c and it doesn't look like ffmpeg is doing this either. Maybe I'm wrong though.
Looks like @richardpl just added the Hilbert tranform filter to ffmpeg https://github.com/FFmpeg/FFmpeg/commit/89bbf5c7ec18a3dff2e2505883a662d182ca6c3a
Sorry for the boob question but can anyone give me the complete config with the hilbert on transform? Or with matrix-encoding working?
re 90 degree phase shift: My understanding is that when the source is Dolby Surround, then the rear channels should already be shifted, so no additional shift needed when downmixing / or otherwise put: even when there was no phase shift, my receiver had no problem isolating the surround channels in prologic mode.
For sake of completeness, since mpv's pan filter was removed and thus you need different syntax now, here's a changed line for the dplii one:
EDIT: pasted a non-working line before - should have been BL and BR instead of SL and SR for 5.1 audio, and also the first quotation mark was misplaced - fixed below.
[dplii]
profile-desc="downmix 5.1 surround to Dolby Pro Logic II compatible stereo"
af='pan=stereo|FL < FL + 0.7071*FC + LFE + -0.7071*BL + -0.7071*SR | FR < FR + 0.7071*FC + LFE + 0.7071*SL + 0.7071*BR'
stuff below was added along with the edit:
JEEB on IRC mentioned that it is possible to use swresample's downmixing as follows:
--audio-swresample-o=matrix_encoding=dplii,lfe_mix_level=1 --audio-channels=stereo
this doesn't normalize the levels down, so is not equivalent to the line above, but would match
af='pan="stereo| FL = FL + 0.7071*FC + LFE + -0.7071*BL + -0.7071*BR | FR = FR + 0.7071*FC + LFE + 0.7071*BL + 0.7071*BR"'
instead (note double quoting here, as otherwise mpv wants to treat the = as option separator)
In plain stereo the swresample matrix encode is very close to the manual pan line (basically indistinguishable for me at least with the few test clips I used), so I'm happy with it.
tldr;
[dplii]
profile-desc="downmix 5.1 surround to Dolby Pro Logic II compatible stereo"
# mpv's own pan filter, obsolete
#af=pan=2:[1,0,0,1,0.7071,0.7071,1,1,-0.8718,0.4899,-0.4899,0.8718]
# lavrresample method, should be drop-in replacement for the above:
#af='pan="stereo| FL = FL + 0.7071*FC + LFE + -0.7071*BL + -0.7071*BR | FR = FR + 0.7071*FC + LFE + 0.7071*BL + 0.7071*BR"'
# same as above, and normalizing audio to avoid clipping (shouldn't be necessary for movies)
#af='pan=stereo| FL < FL + 0.7071*FC + LFE + -0.7071*BL + -0.7071*SR | FR < FR + 0.7071*FC + LFE + 0.7071*SL + 0.7071*BR'
# swresample method, use that unless you want to tweak the balance manually:
audio-swresample-o=matrix_encoding=dplii,lfe_mix_level=1
audio-channels=stereo
Awesome. I currently have a cheap very old Sony DAV-DZ230 which only supports ProLogic i/ii for external inputs. A ProLogic ii encoder is the only hope I have of using the surround sound with anything but the built in DVD player so thank you for this and I will try it out. :) Would be very useful to be built into MPV for sure!
if this issue still persists, please open a new issue.
Is the downmixing output compatible with the Dolby Surround for the VHS Hi-Fi Stereo audio?
The following pan filter settings can be used to downmix 5.1 surround to Dolby Pro Logic compatible stero for use with old amplifiers or when using multiple analog connections is too bothersome (like when connecting a laptop with only one audio-jack and no digital outputs) Mixing in the lfe channel to the center works fine on both receivers I did test on: A Sony STR-DE235 (Pro Logic only) and a Yamaha RX-V350 (Pro Logic II), but some sources write that it should not be mixed in, so there's also the variants where it is omitted.
Tested with the spoken 5.1 channel identification sample ( https://www2.iis.fraunhofer.de/AAC/ChID-BLITS-EBU.mp4 ) from https://www2.iis.fraunhofer.de/AAC/multichannel.html
(For some reason, on the web are different values for the PLII matrix' surround channels (0.8165 & 0.5774 instead of the 0.8718 0.4889 as provided in the wiki) ā but with those values you don't get clear separation of the surround left and surround right)