View Full Version : Solved: Dolby ProLogic II downmix
mtsonline
12th March 2023, 23:13
Hi guys,
sorry to break in here and not opening a new topic, but even if this one is about 7.1 downmixing and my question is related to 5.1, I think it might be helpful for others too to have an answer here.
I have been searching a solution for many days now and maybe you can clear up things and help me to get this to work.
There are a few questions I cannot find an answer for.
I have 5 (and one lfe) separate wav files from a 5.1 production.
I would like to encode these files into one stereo (surround) wav file with proper dplII (Dolby Pro Logic II) encoding.
after reading this thread, I am even more confused, as I thought one would do this with aresample=matrix_encoding=dplii
and you use pan or format filters.
And additionally I ask myself, if the given examples here all apply the necessary phaseshift without doing this manually?
Here is a version I thought would be okay, but I am not sure if it does the right thing, and I am not excited about the result either.
# first try to phaseshift the surround channels:
/Applications/ffmpeg -y -i bl.wav -af aphaseshift=shift=0.5 bl_phaseshift.wav
/Applications/ffmpeg -y -i br.wav -af aphaseshift=shift=-0.5 br_phaseshift.wav
# no idea if the center also should be shifted - and if this at all is necessary to be done manually.
# then try to mix down to dplII stereo:
/Applications/ffmpeg -y -i fl.wav -i fc.wav -i fr.wav -i bl_phaseshift.wav -i br_phaseshift.wav -filter_complex "[0:0][1:0][2:0][3:0][4:0]amerge=inputs=5,aresample=matrix_encoding=dplii" surround.wav
so for me there are the following open questions:
1. do I have to apply the phaseshift when using matrix_encoding? ... or when using pan=stereo? Or does either of them apply it automatically?
2. is 0.5 and -0.5 the correct form to get the expected 90 degrees?
3. is amerge=inputs=5 the correct way to get the five wav files into the command?
4. which order do matrix_encoding and pan expect or how could I assign the right file to the right channel?
and last but not least
5. is matrix_encoding=dplii the right way to go or pan=stereo or should I even combine them (how)?
What I experienced is, that regardless of using pan or matrix_encoding the back speakers always play parts of the front channels and I could not find the right command / settings to prevent that, so that the back speakers only would play the parts of the back channels.
Hope someone can clear up things a bit and maybe help to find a solution that creates a valid pro logic II encoded wav file.
Thanks a lot!
Martin
tebasuna51
13th March 2023, 23:22
There are old discussions about that: http://forum.doom9.org/showthread.php?t=112122
mtsonline
14th March 2023, 11:15
Hi Tebasuna
and thanks for your reply.
i originally posted an answer to one of the old threads:
https://forum.doom9.org/showthread.php?t=181726&page=3
but it seems that my post was moved out.
I read all old topics on prologicII I could find and all my questions where not answered there - or I did not understand how to realice what I learned.
My questions are sumarizing everything, that is not clear and how to create a valid file.
The thread you linked tells me that
Lt = FL{0°} + 0.7071 C{0°} + 0.7071 LFE{0°} + 0.866 SL{+90°} + 0.5 SR{+90°}
Rt = FR{0°} + 0.7071 C{0°} + 0.7071 LFE{0°} + 0.5 SL{-90°} + 0.866 SR{-90°}
seems to be correct - this is what I also found from other sources and what I tried to do in my example.
So not phaseshifting the center seems to be correct. This was one of my questions. :-)
But all others still are not answered, because they are related to the ffmpeg commands that should be used to get a working DPLII wav file from five separate wav files.
Hope you or someone else can help me to get this working, as I really am searching and trying for weeks now with no good success and the manuals are missing details on this job.
so my adopted questions now would be:
1. I asume pan or matrix_encoding=dplii do not apply the phaseshift, so how would I do that correctly using ffmpeg?
2. is amerge=inputs=5 the correct way to get the five wav files into the command - or does this already corrupt the separate channels - so how would I get the five files correctly in the channels?
3. which order do matrix_encoding and pan expect or how could I assign the right file to the right channel? - is the order l - c - r - ls -rs or is it l- r- c- ls -rs ... or something different?
4. is matrix_encoding=dplii the right way to go or pan=stereo or should I even combine them or go a different way?
What I experienced is, that regardless of using pan or matrix_encoding the back speakers always play parts of the front channels and I could not find the right command / settings to prevent that, so that the back speakers only would play the parts of the back channels.
All in all one simple question ...
a: how could I encode five separate wav files into one dplii encoded wav file with one or more ffmpeg commands? ;-)
thanks everyone for any help
tebasuna51
14th March 2023, 23:06
1) Forget phaseshift
2) -filter_complex "[0:0][1:0][2:0][3:0][4:0]amerge=inputs=5"
work fine creating a 5.0 wav
3) The order is l- r- c- ls -rs
4) -ac 2 -af "aresample=matrix_encoding=dplii"
work fine over the 5.0 previously created
mtsonline
16th March 2023, 09:34
Thank you tebasuna
you say: "forget phaseshift"
I 'ld love to, but I am afraid I'll have to get it done correctly, as the results are not satisfying.
Refering to the discussion you linked in your first post, the conclusion was, that a phaseshift of +90 / -90 for the back channels is needed if surround panning occours. And Sony papers even go further and say, it is needed if there are similar melodies in different channels.
combining your answers to one command leads to:
-i fl -i fr -i fc -i bl -i br -filter_complex "[0:0][1:0][2:0][3:0][4:0]amerge=inputs=5, ac 2, aresample=matrix_encoding=dplii"
what is quite the same as my original finding ... not sure if the ac 2 does a difference here - what the only difference in the commands was.
I am still asking mysself what the different commands exactly do:
1. ac 2 - seems to pan / downmix the five channels to two channels. As I could do with the pan:stereo - used in the discussion to 7.1 downmixing I linked to. But I guess here no phaseshift is added. The only difference to manual pan seems the automated adjustment of channel volumes.
2. matrix_encoding=dplii - I thought this does quite the same as pan:stereo and ac 2 ... and what should this do with the output of ac 2 ... ac 2 delivers two channels. the matrix_encoding=dplii should take five in my understanding to be able to mix them correctly - but does it mix at all? And does this apply the phaseshift? There is no documentation on what it does - one would have to search the sourcecode to understand what will happen.
3. and if both do not apply the phaseshift, how would I do that correctly - my results are not great with aphaseshift and the different values from -1 / 0.5 / 0.25 - nowhere is stated how many degrees this would be. And is it enough to use this or would hilbert also be required? ... the documentation states, thaht hilbert should be used in combination with afier that should shift by 90 degrees afterwards. but also no documentation on how this could be done :-(
4. All in all I am disapointed as either of my tests results in in quite the same. The sound of the back channels also is played in front channels and parts of the front channel sounds is played at the back channels. Or is this a downside of prologic and cannot be solved? As i understood the prologic II encoding the phaseshift should make it possible to separate back channels from front channels correctly.
I wonder, why there is hardly any information on the net regarding prologic II downmixing - does nobody use it nowadays - and is there anything else / better to use for releasing surround music for radio stations and streaming?
best wishes
tebasuna51
16th March 2023, 14:09
Refering to the discussion you linked in your first post, the conclusion was, that a phaseshift of +90 / -90 for the back channels is needed if surround panning occours.
It is not my opinion, see my posts.
But maybe it depend with how was generated the channels:
1) If channels was from a previously encoded 5.1 file (like in pool, AC3, DTS,...) the surround channels there are already phaseshifted and not need another phaseshift.
2) If surround channels was generated from front channels maybe need a phaseshift to avoid interferences.
-i fl -i fr -i fc -i bl -i br -filter_complex "[0:0][1:0][2:0][3:0][4:0]amerge=inputs=5, ac 2, aresample=matrix_encoding=dplii"
I obtain:
[AVFilterGraph @ 000001f46d97c2c0] No such filter: 'ac 2'
Error initializing complex filters.
To avoid syntax problems in a first pass create a 5.0 wav and after check the downmix.
I recommend use 0º for surround contributions to FL, and 180º for FR with:
-af "pan=stereo|FL=.3254c0+.2301c2+.2818c3+.1627c4|FR=.3254c1+.2301c2-.1627c3-.2818c4"
But using:
-ac 2 -af "aresample=matrix_encoding=dplii"
The mix is 180º for FL and 0º for FR, like (checked mixing that part with output silence):
"pan=stereo|FL=.3254c0+.2301c2-.2818c3-.1627c4|FR=.3254c1+.2301c2+.1627c3+.2818c4"
Nothing about -90º, +90º
To listen the output the AVR must have activated the DPLII decoder. What is what?
mtsonline
16th March 2023, 18:24
Hi
>It is not my opinion, see my posts.
>But maybe it depend with how was generated the channels:
exactly what I think.
>1) If channels was from a previously encoded 5.1 file (like in pool, AC3, DTS,...) the surround channels there are already phaseshifted and not need another phaseshift.
yes - this is true for sure.
>2) If surround channels was generated from front channels maybe need a phaseshift to avoid interferences.
I have five separate channels from the surround production and some parts are shared, others are not - and this should be kept.
>[AVFilterGraph @ 000001f46d97c2c0] No such filter: 'ac 2'
>Error initializing complex filters.
>To avoid syntax problems in a first pass create a 5.0 wav and after check the downmix.
sorry, this was, what I did after your post - thought I could merge it into one - didn't test that though :-( So I keep the two separate commands for merging and encoding.
>I recommend use 0º for surround contributions to FL, and 180º for FR with:
>-af "pan=stereo|FL=.3254c0+.2301c2+.2818c3+.1627c4|FR=.3254c1+.2301c2-.1627c3-.2818c4"
so the "-" does phaseshift by 180° here?
>-ac 2 -af "aresample=matrix_encoding=dplii"
>The mix is 180º for FL and 0º for FR, like (checked mixing that part with output silence):
>"pan=stereo|FL=.3254c0+.2301c2-.2818c3-.1627c4|FR=.3254c1+.2301c2+.1627c3+.2818c4"
do you think this is worse, because of the interchanged sides? ...
>Nothing about -90º, +90º
But this would be what sony stated ... that was why I tried to find the solution to achive it.
>To listen the output the AVR must have activated the DPLII decoder. What is what?
both ac3 files sound exactly the same on my receiver ... and both sound correct - but they only have one sound at the same time though.
How did you exactly create them now - could you please give me the exact command so I can test under same condition with my inputfiles?
And how would I decide what fileformat to get ... yours was ac3 - would I just name the fileoutput .ac3 or .wav depending on what I would like to get - or would I have to alter the command?
thanks so much for all your help - hope I can get it to work for the more complex inputfiles too.
mtsonline
16th March 2023, 18:46
just tested with:
-i sound5.wav -af "pan=stereo|FL=.3254c0+.2301c2+.2818c3+.1627c4|FR=.3254c1+.2301c2-.1627c3-.2818c4" sound_pan.wav
again the channels are mixed up - parts of the front are played at the back and vieceverse. So either prologic is not capable of keeping back channels separated or it may need explicit exact phaseshift? :-(
I'll wait for the command you used for creating the files and will then try with that on my inputfiles.
tebasuna51
16th March 2023, 21:17
just tested with:
-i sound5.wav -af "pan=stereo|FL=.3254c0+.2301c2+.2818c3+.1627c4|FR=.3254c1+.2301c2-.1627c3-.2818c4" sound_pan.wav
This is my command line. After I encode it to AC3 with the flag dpl activated to force AVR use the dplII decoder.
again the channels are mixed up - parts of the front are played at the back and vieceverse. So either prologic is not capable of keeping back channels separated or it may need explicit exact phaseshift?
My AVR make a perfect separation with my samples.
How do you play the samples?
mtsonline
16th March 2023, 23:22
>This is my command line. After I encode it to AC3 with the flag dpl activated to force AVR use the dplII decoder.
hm... maybe the encode into ac3 with the flag dpl does the difference ...
could you please give me your complete command from the 5.0 file till the ac3 you posted?
I wuld like to repeat that with my inputs.
and could you create a dpl2 encoded wav from your source to test if this also plays correctly?
I play via my avr in different ways ... either through dlna streaming or direktly from a hdmi connected player - this makes no difference.
Your ac3 files are played correctly with perfectly separated channels.
Only my wav does mix up the channels.
thanks
tebasuna51
17th March 2023, 13:29
With the 5p320.wav normalized to 0 dB peak I do:
ffmpeg -i "5p320.wav" -af "pan=stereo|FL=.3254c0+.2301c2+.2818c3+.1627c4|FR=.3254c1+.2301c2-.1627c3-.2818c4, volumedetect" -f null -
and obtain:
...
[Parsed_volumedetect_1 @ 000001e02a83d840] n_samples: 1152000
[Parsed_volumedetect_1 @ 000001e02a83d840] mean_volume: -31.6 dB
[Parsed_volumedetect_1 @ 000001e02a83d840] max_volume: -9.8 dB
...
and next, to obtain a normalized stereo dpl wav (9,8 dB -> volume= 3.09):
ffmpeg -i "C:\tmp\5p320.wav" -af "pan=stereo|FL=.3254c0+.2301c2+.2818c3+.1627c4|FR=.3254c1+.2301c2-.1627c3-.2818c4, volume=3.09" -acodec pcm_s24le sound_pan.wav
and after I encode it to AC3 with flag dpl activated.
When you send pastrough that AC3 force the AVR to use the dplII decoder, but if you send a stereo wav by HDMI you need activate the dplII manually in the AVR.
I have it activated and the wav play the same than the AC3.
mtsonline
20th March 2023, 16:07
Thank you Tebasuna
* why do you set volume to 3.09?
* and how can I create an ac3 with forced dpl flac activated - I tried a bunch of commands but did not find the right settings until now
may you post the command for this too ?
i will create an ac3 from my wav (as soon as I get your command) and then retry if this makes a difference on my setup. Maybe you are right and my AVR does just not activate dpl when the wav is played through HDMI.
tebasuna51
21st March 2023, 11:22
volume=3.09
is the same than
volume=9.8 dB
because 10^(9.8/20)=3.09 and now the max volume without distort is 0 dB
ffmpeg.exe -i "sound_pan.wav" -b:a 192k -c:a ac3 -dsur_mode on "dplii.ac3"
or 256k
or directly
ffmpeg -i "C:\tmp\5p320.wav" -af "pan=stereo|FL=.3254c0+.2301c2+.2818c3+.1627c4|FR=.3254c1+.2301c2-.1627c3-.2818c4, volume=3.09" -b:a 192k -c:a ac3 -dsur_mode on "dplii.ac3"
mtsonline
21st March 2023, 16:51
ok thanks
I tested your commands with the five wav files as input ... in different ways and also with slightly adoptions.
It does not work for my music files - I guess this only works for files that have one sound per channel and never the same or overlapping parts. :-(
So I still think the missing correct phaseshift could be the problem.
Sadly I could not find any example how hilbert and afir should be used to get +90 and -90 degree phaseshift for the surround channels. and no documentation what aphaseshift does exactly and what -1 - +1 do mean in regards to degrees.
Or do you have any other idea what could be wrong here and what I could try else?
We have 2023 - can it be that hard to get a dplii encoded wav file?!? ;-)
tebasuna51
22nd March 2023, 11:08
So I still think the missing correct phaseshift could be the problem.
You have the tools, make test until obtain your desired output.
We have 2023 - can it be that hard to get a dplii encoded wav file?!? ;-)
In 2023 the storage space is cheap, preserve the 5.1 channels in flac or aac/opus.
mtsonline
22nd March 2023, 11:17
Hi :-)
"You have the tools, make test until obtain your desired output."
I have (maybe) the tools, but not the knolledge and cannot find the answer to the question how to do the correct phaseshift of +/-90° :-(
I did for sure more than 100 tests and where not able to get the correct output. If I do not find someone who knows how to do it I will likely give up and mix down to normal stereo - it makes me sick.
I would love to keep the five discrete channels - but they won't get transmitted through radio stations or streaming ;-) If I fail with dplii I only can distribute stereo.
mtsonline
23rd March 2023, 10:39
ok after talking a while to chat gpt as a last resort ;-) I found the solution. (gpt gave a lot broken code, but it helped to understand the parts)
so here - for all that may ever need to encode dplii wav files - that is the correct way:
# phaseshift
/Applications/ffmpeg -y -i $bl -af aphaseshift=shift=0.5 ${bl}_shift.wav
/Applications/ffmpeg -y -i $br -af aphaseshift=shift=-0.5 ${br}_shift.wav
# create multichannel wav file
/Applications/ffmpeg -report -y -i $fl -i $fr -i $fc -i ${bl}_shift.wav -i ${br}_shift.wav -filter_complex "[0:0][1:0][2:0][3:0][4:0]amerge=inputs=5" surround5_shift.wav
# encode dolby prologic II wav file
/Applications/ffmpeg -report -y -i surround5_shift.wav -ac 5 -af "aresample=matrix_encoding=dplii" -ochl 5.0 surround_DPLII.wav
# create ac3 file
/Applications/ffmpeg -report -y -i surround5_shift.wav -vn -acodec ac3 -ac 6 -ar 48000 -ab 448k -dsur_mode on surround.ac3
some footnotes:
the given pan:stereo examples in the forum are not dplii encoded and do not work for complex files.
the aresample=matrix_encoding=dplii without phaseshift works - but adding the expected phaseshift improves the quality.
the ac3 file does work for dolby digital playback perfectly, but does not work for dplii - I did not try to get this fixed - so if someone wants to add that it would be great.
hope someone finds this helpful
tebasuna51
23rd March 2023, 11:13
Like I say you the phaseshift in needed when the surround channels was generated using the front channels, when they are independent (channel test, recorded with different mic's at proper location) or decoded from a previously shifted sources, apply the phaseshift can be worse.
mtsonline
23rd March 2023, 11:20
thanks Tebasuna
yeah, that is still valid for already shifted and decoded sources and (as Sony also states) for five mic surround recordings.
And it should be noted here for people who did not create the five channels themselves.
But for anyone who makes a five channel production this should be the correct way to encode. ;-)
thanks for all your help!
junh1024
24th March 2023, 06:00
It seems that Chatgpt made a 5-6ch file with the phase shift applied, not 2ch
mtsonline
24th March 2023, 11:23
Hi :-)
chat gpt didn't create any useful output - all commands had errors. But it was helpful to understand some impacts.
I added the 5.0 to be sure it does keep the five channels - you can change the output channe llayout to stereo if you like, it does not matter at all.
Or just leave it out, I had it only for testing included in the command and didn't remove it afterwards.
Also the input channels are corectly determined automatically - so the resample command alone will work.
important is just the phaseshift of the surround channels, if they are not already shifted (e.g. decode from ac3 or any movie source) or a five mic surround recording.
So if you create five indipendent channels in your production and you do not shift the rear channels you will get a slightly distroyed output.
In fact you will hear, that the front channels volume will lower down as soon as the rear channels get active. This is due to the two (respectively four) channels interfearing with eachother, as the decoder has problems to recognize the different channels without the shift.
cheers
SeeMoreDigital
24th March 2023, 12:25
It is not my opinion, see my posts.
But maybe it depend with how was generated the channels:
1) If channels was from a previously encoded 5.1 file (like in pool, AC3, DTS,...) the surround channels there are already phaseshifted and not need another phaseshift.
2) If surround channels was generated from front channels maybe need a phaseshift to avoid interferences.
To listen the output the AVR must have activated the DPLII decoder....
Thanks for supplying the (2-ch) Dolby Prologic 'channel check' samples in Dolby Digital. These are most useful additions to my sample collection :)
I do however have a cheeky request, do you have any (2-ch) Dolby Prologic 'channel check' samples in LPCM.wav?
Cheers
tebasuna51
26th March 2023, 13:48
I do however have a cheeky request, do you have any (2-ch) Dolby Prologic 'channel check' samples in LPCM.wav?
Easy solution: decode the AC3
ffmpeg -i "dplii.ac3" -acodec pcm_s24le "sound_pan.wav"
To decode it to 5.1 you need a dplII decoder (https://forum.doom9.org/showthread.php?p=1920201#post1920201)
mtsonline
22nd July 2023, 12:21
Hi :-)
finally here is the result and a surround dplii encoded song where ffmpeg and the outcome of the discussions where used:
Stream and download Virtuality on ...
Amazon Music:
https://music.amazon.de/albums/B0CBKBSDVQ?marketplaceId=A1PA6795UKMFR9&musicTerritory=DE&ref=dm_sh_YxA0Ftqb8YNagSrnYF7WFD9Z0&trackAsin=B0CBKCRL5D
Apple Music:
https://music.apple.com/us/album/virtuality-single/1696588622
Spotify:
https://open.spotify.com/intl-de/track/1CLvv5msj0wuhRSisR1W4M?si=d8b7ee9d644e4384
cheers
Martin
FranceBB
22nd July 2023, 19:04
finally here is the result and a surround dplii encoded song where ffmpeg and the outcome of the discussions where used
Well, my 5.1 played it correctly with Pipewire/Wireplumber reconstructing the 5.1 from the downmix upon playback.
I couldn't really hear many effects outside of the normal stereo mode until I arrived at around 1 minute and I heard the "tap" coming from the side, so it worked.
(I know this must have a name, but I'm music illiterate, so I have no idea what instrument produced that sound xD)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.