FFmpeg - Audio Channel Layout: Difference between revisions
From PiRho Knowledgebase
Jump to navigationJump to search
Created page with "Category:Software Category:FFmpeg Category:Multimedia Reference: https://superuser.com/questions/852400/properly-downmix-5-1-to-stereo-using-ffmpeg superuser: Properly downmix 5.1 to stereo using ffmpeg<br/> Reference: https://trac.ffmpeg.org/wiki/AudioChannelManipulation FFmpeg: Manipulating audio channels" |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 2: | Line 2: | ||
[[Category:FFmpeg]] | [[Category:FFmpeg]] | ||
[[Category:Multimedia]] | [[Category:Multimedia]] | ||
'''References:''' | |||
* https://superuser.com/questions/852400/properly-downmix-5-1-to-stereo-using-ffmpeg | |||
* https://trac.ffmpeg.org/wiki/AudioChannelManipulation | |||
== Summary == | |||
This article explains how FFmpeg understands, manipulates, converts, and remaps audio channels (e.g., Stereo, 5.1, 7.1). It covers layouts, downmixing, upmixing, channel mapping, and how to explicitly control audio routing using FFmpeg filters such as ''pan'', ''channelmap'', and ''aresample''. | |||
== Why Channel Layout Matters == | |||
Modern multimedia workflows often involve a mixture of devices and formats: | |||
* Surround sound sources (5.1 / 7.1) | |||
* Stereo-only playback systems | |||
* Mobile devices with mono speakers | |||
* Incorrectly labelled or inconsistently ordered tracks | |||
* Broadcast, film, and online workflows requiring predictable channel order | |||
A correct channel layout ensures voices remain centred, surround effects are preserved, LFE is handled appropriately, and no channels are lost or duplicated. | |||
== Understanding FFmpeg’s Channel Layouts == | |||
FFmpeg recognises channel layouts by both name and bitmask. | |||
=== Common Layout Names === | |||
* mono | |||
* stereo (FL, FR) | |||
* 3.0 (L, R, C) | |||
* 4.0 (L, R, SL, SR) | |||
* 5.0 (L, R, C, SL, SR) | |||
* 5.1 (L, R, C, LFE, SL, SR) | |||
* 7.1 (L, R, C, LFE, SL, SR, BL, BR) | |||
=== Inspecting an Input File === | |||
ffmpeg -i input.mkv | |||
== Downmixing Surround to Stereo == | |||
=== Default Downmix === | |||
ffmpeg -i input.mkv -ac 2 output.mp4 | |||
=== Custom Downmix Matrix === | |||
ffmpeg -i input-5.1.wav -filter_complex "pan=stereo|FL = 0.90*FL + 0.32*FC + 0.22*SL + 0.22*BL|FR = 0.90*FR + 0.32*FC + 0.22*SR + 0.22*BR" output.wav | |||
== Upmixing Stereo to Surround == | |||
=== Basic Upmix === | |||
ffmpeg -i stereo.wav -af "channelmap=channel_layout=5.1" output.wav | |||
=== Enhanced Upmix === | |||
ffmpeg -i stereo.wav -filter_complex "pan=5.1|FL=FL|FR=FR|C=0.5*FL+0.5*FR|SL=FL|SR=FR|LFE=0" output.wav | |||
== Reordering Channels (channelmap) == | |||
ffmpeg -i wrong-order.wav -filter_complex "channelmap=map=0|1|4|5|2|3:channel_layout=5.1" fixed.wav | |||
== Extracting Individual Channels == | |||
ffmpeg -i input.wav -map_channel 0.0.0 FL.wav | |||
ffmpeg -i input.wav -map_channel 0.0.1 FR.wav | |||
ffmpeg -i input.wav -map_channel 0.0.2 FC.wav | |||
ffmpeg -i input.wav -map_channel 0.0.3 LFE.wav | |||
== Creating Silent Placeholder Channels == | |||
ffmpeg -f lavfi -i anullsrc=channel_layout=5.1:sample_rate=48000 silence.wav | |||
== Common Pitfalls == | |||
=== Invalid Layouts === | |||
Occurs when channel count mismatches layout. | |||
=== LFE Issues === | |||
LFE may be discarded or reduced in downmixes. | |||
=== Wrong Surround Ordering === | |||
Rear vs side channels may be swapped. | |||
== Design & Architecture Considerations == | |||
* Always explicitly declare layouts. | |||
* Avoid relying on defaults. | |||
* Document downmix matrices. | |||
* Test with both headphones and speakers. | |||
== Troubleshooting Checklist == | |||
ffprobe -show_streams input.wav | |||
== Related Topics == | |||
* FFmpeg – Resampling & Formats | |||
* FFmpeg – Filter Graph Basics | |||
* Audio Fundamentals – Channel Concepts | |||
Latest revision as of 14:40, 14 March 2026
References:
- https://superuser.com/questions/852400/properly-downmix-5-1-to-stereo-using-ffmpeg
- https://trac.ffmpeg.org/wiki/AudioChannelManipulation
Summary
This article explains how FFmpeg understands, manipulates, converts, and remaps audio channels (e.g., Stereo, 5.1, 7.1). It covers layouts, downmixing, upmixing, channel mapping, and how to explicitly control audio routing using FFmpeg filters such as pan, channelmap, and aresample.
Why Channel Layout Matters
Modern multimedia workflows often involve a mixture of devices and formats:
- Surround sound sources (5.1 / 7.1)
- Stereo-only playback systems
- Mobile devices with mono speakers
- Incorrectly labelled or inconsistently ordered tracks
- Broadcast, film, and online workflows requiring predictable channel order
A correct channel layout ensures voices remain centred, surround effects are preserved, LFE is handled appropriately, and no channels are lost or duplicated.
Understanding FFmpeg’s Channel Layouts
FFmpeg recognises channel layouts by both name and bitmask.
Common Layout Names
- mono
- stereo (FL, FR)
- 3.0 (L, R, C)
- 4.0 (L, R, SL, SR)
- 5.0 (L, R, C, SL, SR)
- 5.1 (L, R, C, LFE, SL, SR)
- 7.1 (L, R, C, LFE, SL, SR, BL, BR)
Inspecting an Input File
ffmpeg -i input.mkv
Downmixing Surround to Stereo
Default Downmix
ffmpeg -i input.mkv -ac 2 output.mp4
Custom Downmix Matrix
ffmpeg -i input-5.1.wav -filter_complex "pan=stereo|FL = 0.90*FL + 0.32*FC + 0.22*SL + 0.22*BL|FR = 0.90*FR + 0.32*FC + 0.22*SR + 0.22*BR" output.wav
Upmixing Stereo to Surround
Basic Upmix
ffmpeg -i stereo.wav -af "channelmap=channel_layout=5.1" output.wav
Enhanced Upmix
ffmpeg -i stereo.wav -filter_complex "pan=5.1|FL=FL|FR=FR|C=0.5*FL+0.5*FR|SL=FL|SR=FR|LFE=0" output.wav
Reordering Channels (channelmap)
ffmpeg -i wrong-order.wav -filter_complex "channelmap=map=0|1|4|5|2|3:channel_layout=5.1" fixed.wav
Extracting Individual Channels
ffmpeg -i input.wav -map_channel 0.0.0 FL.wav ffmpeg -i input.wav -map_channel 0.0.1 FR.wav ffmpeg -i input.wav -map_channel 0.0.2 FC.wav ffmpeg -i input.wav -map_channel 0.0.3 LFE.wav
Creating Silent Placeholder Channels
ffmpeg -f lavfi -i anullsrc=channel_layout=5.1:sample_rate=48000 silence.wav
Common Pitfalls
Invalid Layouts
Occurs when channel count mismatches layout.
LFE Issues
LFE may be discarded or reduced in downmixes.
Wrong Surround Ordering
Rear vs side channels may be swapped.
Design & Architecture Considerations
- Always explicitly declare layouts.
- Avoid relying on defaults.
- Document downmix matrices.
- Test with both headphones and speakers.
Troubleshooting Checklist
ffprobe -show_streams input.wav
Related Topics
- FFmpeg – Resampling & Formats
- FFmpeg – Filter Graph Basics
- Audio Fundamentals – Channel Concepts