Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > General > Audio encoding

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd December 2024, 10:01   #1  |  Link
GrandAdmiralThrawn
Registered User
 
GrandAdmiralThrawn's Avatar
 
Join Date: Feb 2011
Posts: 51
Help with channel up- & downmixing using ffmpeg

Hello,

I'm trying to remix some channels, e.g. layout "L R C LFE Ls Rs" 5.1 as well as "L R" 2.0 to the 5.1 channel layout "C L R Ls Rs LFE". On top of that, I need to remix "L R C LFE Ls Rs" 5.1 to "L R" stereo. I will also have to resample some parts.

The reason is that I need to stitch some audio tracks with different sample sizes and channel layouts together to match multiple main feature audio tracks. All files are PCM/Wav64 audio, which I intend to just concatenate. But for that to work, the layouts and sample sizes need to match. Resampling is super easy, but remixing is royally confusing me.

With one of the sources which comes in the layout "L R C LFE Ls Rs" I tried this for instance:

Code:
ffmpeg -i input.w64 -filter_complex "pan=5.1|c0=c2|c1=c0|c2=c1|c3=c4|c4=c5|c5=c3[a]" -map "[a]" -ac 6 -acodec pcm_s24le output.w64
Essentially, I'm trying to tell ffmpeg to do this: "Take channel 2 and put it on channel 0 (center), take channel 0 and put it on channel 1 (left)" and so on and so forth.

The result is confusing me, however, as mediainfo now claims the resulting file has the layout "L R C LFE Lb Rb". Huh?

And I haven't even started upmixing the stereo parts or downmixing the surround parts yet...

So in my helplessness, I ran to the great machine god (ChatGPT) and asked it to fix my mess, but it didn't produce anything that would've worked either. Most commands it gave me only produced errors.

So here I am, asking for help.

Inputs that require remixing:

1.) 2.0: Layout "L R", sample size 16 bits
2.) 5.1: Layout "L R C LFE Ls Rs", sample size 24 bits

My desired outputs:

a.) 2.0: Layout "L R", sample size 16 bits
b.) 5.1: Layout "C L R Ls Rs LFE", sample size 24 bits

All files come with a 48 kHz sampling frequency. Every single input file needs to be remixed and partially resampled to match each given output format. So "1." needs to be converted to both "a." and "b." and "2." needs the same.

If possible, I'd like not to throw channels away entirely, so that the resulting streams lose as little audio information as possible.

For getting the channel layouts I use mediainfo, as mentioned, in the hope that it produces correct information.

It would be really nice if you could give me the correct commands for this, and even nicer if you could explain them to me as well, so I can finally understand this stuff.

Thanks a lot!
__________________

Proud owner of a 3dfx Voodoo5 6000 AGP HiNT Rev.A-3700 prototype
No RISC, no fun!
GrandAdmiralThrawn is offline   Reply With Quote
Old 3rd December 2024, 01:37   #2  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 7,160
Quote:
Originally Posted by GrandAdmiralThrawn View Post
I'm trying to remix some channels, e.g. layout "L R C LFE Ls Rs" 5.1... to the 5.1 channel layout "C L R Ls Rs LFE".
The channel layout "C L R Ls Rs LFE" does not exist in w64 format.

For what do you need that channel order?
Please don't mistake the internal order in any codec format with the order in wav/w64 format. Any encoder must translate the order in wav/w64 source to the internal codec order.
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 4th December 2024, 09:59   #3  |  Link
GrandAdmiralThrawn
Registered User
 
GrandAdmiralThrawn's Avatar
 
Join Date: Feb 2011
Posts: 51
Quote:
Originally Posted by tebasuna51 View Post
The channel layout "C L R Ls Rs LFE" does not exist in w64 format.

For what do you need that channel order?
Please don't mistake the internal order in any codec format with the order in wav/w64 format. Any encoder must translate the order in wav/w64 source to the internal codec order.
Like I said, when I run mediainfo on my main feature audio, it shows "C L R Ls Rs LFE". That file is a .w64 one. It was originally some DTS audio and was encoded to .w64 with ffmpeg without specifying a channel layout. Basically just DTS in, W64 out, nothing else. Running mediainfo on the DTS source also shows "C L R Ls Rs LFE".

Additionally, there are some logos, notices and some epilogue for this feature, but they come as separate files (it's a community project). I think it's either linked MKVs, or the viewer was expected to just watch them one after another. Those additional files have either no audio, or audio that does not match the main features audio.

I want to stitch that all together doing simple concatenation. So the idea was:
  • Create audio paddings with correct runtimes for those smaller videos (notices, logos) with no audio streams, essentially just patches of silent audio, 5.1 and 2.0
  • Up / downsample and remix existing audio parts so that they match the main feature audio streams exactly to enable safe concatenation
  • Simply use "cat" to stitch the 5.1 .w64 files together in the correct order, same for the 2.0 ones
  • Take those single files containing all desired, original streams in the correct order with the correct, matching channel layouts and encode them to a single, lossy stream (AAC-LC, Opus, whichever)
  • Replace those six (in this case) existing MKVs with just one containing the entire content

I'm worried that concatenating multiple .w64 streams with different channel layouts ("L R C LFE Ls Rs" & "C L R Ls Rs LFE") will quite likely mess the resulting stream up.

Thank you very much!
__________________

Proud owner of a 3dfx Voodoo5 6000 AGP HiNT Rev.A-3700 prototype
No RISC, no fun!

Last edited by GrandAdmiralThrawn; 4th December 2024 at 14:31.
GrandAdmiralThrawn is offline   Reply With Quote
Old 4th December 2024, 11:34   #4  |  Link
junh1024
Registered User
 
Join Date: Mar 2011
Posts: 63
1. As Teba said, "C L R Ls Rs LFE" is an internal order useful mainly to developers, not editors. "L R C LFE Ls Rs" is used for editing & playback.

ED: If you're encoding to DTS, most encoders accept the latter input, or single channels as input. Please perform a full workflow test including listening to see what happens.

2. If you're upmixing, chances are you're going to mess it up (ruin balance, image, downmix compatibility) if you don't know what youre doing. Just pad 2ch to 5.1ch with silence on other channels.

3. cat may or may not work, audio files have headers at the start/end to tell the specifications. At best, you will end up with small glitches & playable files. At worst, you may end up with broken files. Best to use a media or audio app to join.

Last edited by junh1024; 4th December 2024 at 12:06.
junh1024 is offline   Reply With Quote
Old 6th December 2024, 09:24   #5  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 7,160
Quote:
Originally Posted by GrandAdmiralThrawn View Post
Like I said, when I run mediainfo on my main feature audio, it shows "C L R Ls Rs LFE". That file is a .w64 one.
Then your MediaInfo software have a bug. The channel order in a wav/w64/rf64 file must be always: FL,FR,FC,LFE,BL,BR,FLC,FRC,BC,SL,SR,...
Read also about dwChannelMask in that link.

I put the channel names in Microsoft wav style, see here the equivalences with MediaInfo or other names.

Quote:
Running mediainfo on the DTS source also shows "C L R Ls Rs LFE".
Thats can be correct but must be ignored at all, because you want work with sources wav/w64

Quote:
I want to stitch that all together doing simple concatenation.
The Unix command 'cat' can't be used because w64 headers.
Use ffmpeg:

ffmpeg -i 01.w64 -i 02.w64 -filter_complex "concat=n=2:v=0:a=1" output.w64

To convert parts 2.0 to the main audio 5.1 you can use also:

ffmpeg -i 20.w64 -af "surround=lfe_out=0" 51.w64

Quote:
I'm worried that concatenating multiple .w64 streams with different channel layouts ("L R C LFE Ls Rs" & "C L R Ls Rs LFE") will quite likely mess the resulting stream up.
Like I say the wav/w64 5.1 always are FL,FR,FC,LFE,BL,BR or FL,FR,FC,LFE,SL,SR (the BackL,BR or SideL,SR pairs can be equivalents to Lsurround,Rs in 5.1 configuration)
__________________
BeHappy, AviSynth audio transcoder.

Last edited by tebasuna51; 6th December 2024 at 09:28.
tebasuna51 is offline   Reply With Quote
Old 6th December 2024, 13:07   #6  |  Link
GrandAdmiralThrawn
Registered User
 
GrandAdmiralThrawn's Avatar
 
Join Date: Feb 2011
Posts: 51
Thank you very much, I will just try it out and listen to my output before progressing further, especially at the positions where streams intersect.

Also thanks for the tip about padding the 5.1 stream with silent audio!

I was just assuming I could cat wav/w64 together because I tried this before and it just worked without any glitches. It may depend on the decoder I guess. I will follow your suggestion about doing this with ffmpeg instead though, better safe than sorry.
__________________

Proud owner of a 3dfx Voodoo5 6000 AGP HiNT Rev.A-3700 prototype
No RISC, no fun!
GrandAdmiralThrawn is offline   Reply With Quote
Reply

Tags
ffmpeg, remixing

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 00:46.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.