Sakura-chan
26th September 2026, 08:04
I have some 4.0 tracks with the non-standard layout of FL FR FC BC. I need to map that back center channel to the more typical home setup of 5.1/7.1, that is upmix it into the surround channels.
I'm not good with ffmpeg so to test I made 4 mono tracks with 30 sec of silence plus 10 sec of random music (same music segment at the same volume) at different intervals. FL plays from 0-10s, FR 10-20s, FC 20-30s and BC 30-40s.
Btw, I only have stereo speakers/headphones to try the result.
First I went with this:
ffmpeg -i FL.wav -i FR.wav -i FC.wav -i BC.wav -filter_complex "[0:a][1:a][2:a][3:a]join=inputs=4:channel_layout=5.0:map=0.0-FL|1.0-FR|2.0-FC|3.0-BL|3.0-BR[a]" -map "[a]" -acodec pcm_s16le join.wav
It worked but the 30-40s segment was too loud. Ofc, the same segment now from two speakers ends up louder. On the other hand the player knows what it's doing and when outputting the center channel to both speakers it lowers the volume somewhat, so it doesn't overpower FL and FR.
So, apparently the pan filter is what I need, like this:
ffmpeg -i FL.wav -i FR.wav -i FC.wav -i BC.wav -filter_complex "[0:a][1:a][2:a][3:a]amerge=inputs=4,pan=5.0|FL=c0|FR=c1|FC=c2|BL=0.5*c3|BR=0.5*c3[a]" -map "[a]" -acodec pcm_s16le output.wav
Logically you multiply the back channel by 0.5, so both together end up at 1. But now they are too low. It seems 0.7 does the trick, making the 4 segments sound at equal levels (as far as I can hear). I'm trying with two players, PotPlayer and foobar.
Am I doing something wrong? Something to improve in the ffmpeg command? The second one gives me a warning but everything seems to work:
[aist#0:0/pcm_s16le @ 000001b9a7a54340] Guessed Channel Layout: mono
Input #0, wav, from 'FL.wav':
Duration: 00:00:40.00, bitrate: 768 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s16, 768 kb/s
[aist#1:0/pcm_s16le @ 000001b9a7a7b840] Guessed Channel Layout: mono
Input #1, wav, from 'FR.wav':
Duration: 00:00:40.00, bitrate: 768 kb/s
Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s16, 768 kb/s
[aist#2:0/pcm_s16le @ 000001b9a7a67900] Guessed Channel Layout: mono
Input #2, wav, from 'FC.wav':
Duration: 00:00:40.00, bitrate: 768 kb/s
Stream #2:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s16, 768 kb/s
[aist#3:0/pcm_s16le @ 000001b9a96c31c0] Guessed Channel Layout: mono
Input #3, wav, from 'BC.wav':
Duration: 00:00:40.00, bitrate: 768 kb/s
Stream #3:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s16, 768 kb/s
Stream mapping:
Stream #0:0 (pcm_s16le) -> amerge
Stream #1:0 (pcm_s16le) -> amerge
Stream #2:0 (pcm_s16le) -> amerge
Stream #3:0 (pcm_s16le) -> amerge
pan:default -> Stream #0:0 (pcm_s16le)
Press [q] to stop, [?] for help
[Parsed_amerge_0 @ 000001b9a97a6180] No channel layout for input 1
[Parsed_amerge_0 @ 000001b9a97a6180] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
Output #0, wav, to 'output.wav':
Metadata:
ISFT : Lavf63.1.102
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, 5.0, s16, 3840 kb/s
Metadata:
encoder : Lavc63.1.102 pcm_s16le
[out#0/wav @ 000001b9a79dcb40] video:0KiB audio:18750KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.000531%
size= 18750KiB time=00:00:40.00 bitrate=3840.0kbits/s speed= 902x elapsed=0:00:00.04
What's the magic number to mix the channels at? Or just trial and error for each track?
I'm not good with ffmpeg so to test I made 4 mono tracks with 30 sec of silence plus 10 sec of random music (same music segment at the same volume) at different intervals. FL plays from 0-10s, FR 10-20s, FC 20-30s and BC 30-40s.
Btw, I only have stereo speakers/headphones to try the result.
First I went with this:
ffmpeg -i FL.wav -i FR.wav -i FC.wav -i BC.wav -filter_complex "[0:a][1:a][2:a][3:a]join=inputs=4:channel_layout=5.0:map=0.0-FL|1.0-FR|2.0-FC|3.0-BL|3.0-BR[a]" -map "[a]" -acodec pcm_s16le join.wav
It worked but the 30-40s segment was too loud. Ofc, the same segment now from two speakers ends up louder. On the other hand the player knows what it's doing and when outputting the center channel to both speakers it lowers the volume somewhat, so it doesn't overpower FL and FR.
So, apparently the pan filter is what I need, like this:
ffmpeg -i FL.wav -i FR.wav -i FC.wav -i BC.wav -filter_complex "[0:a][1:a][2:a][3:a]amerge=inputs=4,pan=5.0|FL=c0|FR=c1|FC=c2|BL=0.5*c3|BR=0.5*c3[a]" -map "[a]" -acodec pcm_s16le output.wav
Logically you multiply the back channel by 0.5, so both together end up at 1. But now they are too low. It seems 0.7 does the trick, making the 4 segments sound at equal levels (as far as I can hear). I'm trying with two players, PotPlayer and foobar.
Am I doing something wrong? Something to improve in the ffmpeg command? The second one gives me a warning but everything seems to work:
[aist#0:0/pcm_s16le @ 000001b9a7a54340] Guessed Channel Layout: mono
Input #0, wav, from 'FL.wav':
Duration: 00:00:40.00, bitrate: 768 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s16, 768 kb/s
[aist#1:0/pcm_s16le @ 000001b9a7a7b840] Guessed Channel Layout: mono
Input #1, wav, from 'FR.wav':
Duration: 00:00:40.00, bitrate: 768 kb/s
Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s16, 768 kb/s
[aist#2:0/pcm_s16le @ 000001b9a7a67900] Guessed Channel Layout: mono
Input #2, wav, from 'FC.wav':
Duration: 00:00:40.00, bitrate: 768 kb/s
Stream #2:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s16, 768 kb/s
[aist#3:0/pcm_s16le @ 000001b9a96c31c0] Guessed Channel Layout: mono
Input #3, wav, from 'BC.wav':
Duration: 00:00:40.00, bitrate: 768 kb/s
Stream #3:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s16, 768 kb/s
Stream mapping:
Stream #0:0 (pcm_s16le) -> amerge
Stream #1:0 (pcm_s16le) -> amerge
Stream #2:0 (pcm_s16le) -> amerge
Stream #3:0 (pcm_s16le) -> amerge
pan:default -> Stream #0:0 (pcm_s16le)
Press [q] to stop, [?] for help
[Parsed_amerge_0 @ 000001b9a97a6180] No channel layout for input 1
[Parsed_amerge_0 @ 000001b9a97a6180] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
Output #0, wav, to 'output.wav':
Metadata:
ISFT : Lavf63.1.102
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, 5.0, s16, 3840 kb/s
Metadata:
encoder : Lavc63.1.102 pcm_s16le
[out#0/wav @ 000001b9a79dcb40] video:0KiB audio:18750KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.000531%
size= 18750KiB time=00:00:40.00 bitrate=3840.0kbits/s speed= 902x elapsed=0:00:00.04
What's the magic number to mix the channels at? Or just trial and error for each track?