| Version 12 (modified by , 12 years ago) ( diff ) |
|---|
Manipulating audio channels with ffmpeg
Contents
stereo → mono stream
Mix a single stereo stream down to a mono stream. Both channels of the stereo stream will be downmixed into the stream:
ffmpeg -i stereo.flac -ac 1 mono.flac
stereo → 2 × mono files
Output each channel in stereo input to individual mono files:
ffmpeg -i stereo.wav -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wav
or with the pan audio filer:
ffmpeg -i stereo.wav -filter_complex "[0:0]pan=1:c0=c0[left];[0:0]pan=1:c0=c1[right]" -map "[left]" left.wav -map "[right]" right.wav
stereo → 2 × mono streams
Output each channel in stereo input to individual mono streams in one output file with the channelsplit audio filter:
ffmpeg -i in.mp3 -filter_complex channelsplit out.mka
Note: Your player will likely play the first stream by default unless your player allows you to select the desired stream.
mono → stereo
Create a stereo output from one mono input:
ffmpeg -i input.mp3 -ac 2 output.m4a
or with the amerge audio filter:
ffmpeg -i input.mp3 -filter_complex "[0:a][0:a]amerge[aout]" -map "[aout]" output.m4a
Note: These examples will not magically create a "true" stereo output from the mono input, but simply place the same audio into both the left and right channels of the output (both channels will be identical).
2 × mono → stereo
Create a stereo output from two mono inputs with the amerge audio filter:
ffmpeg -i left.mp3 -i right.mp3 -filter_complex "[0:a][1:a]amerge[aout]" -map "[aout]" output.mka
6 × mono → 5.1
Combine 6 mono inputs into one 5.1 (6 channel) output with the amerge audio filter:
ffmpeg -i front_left.wav -i front_right.wav -i front_center.wav -i lfe.wav -i back_left.wav -i back_right.wav \ -filter_complex "[0:a][1:a][2:a][3:a][4:a][5:a]amerge=inputs=6[aout]" -map "[aout]" output.wav
All inputs must have the same sample rate and format. If inputs do not have the same duration the output will stop with the shortest.
5.1 → 6 × mono
Split a 5.1 channel input into individual per-channel files:
ffmpeg -i in.wav \ -filter_complex "channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR]" \ -map "[FL]" front_left.wav \ -map "[FR]" front_right.wav \ -map "[FC]" front_center.wav \ -map "[LFE]" lfe.wav \ -map "[BL]" back_left.wav \ -map "[BR]" back_right.wav
5.1 → stereo
To downmix you can simply use -ac 2:
ffmpeg -i 6channels.wav -ac 2 stereo.wav
Notes:
- By default when using
-ac 2the LFE channel is omitted. See "Digital Audio Compression Standard (Document A/52:2010)" for more downmixing info involving LFE. ffmpegintegrates a default down-mix (and up-mix) system that should be preferred (the-acoption) over the pan filter unless you have very specific needs.
If you want to map specific channels and drop the rest you can use the pan audio filter. This will map the FL (Front Left) of the input to the FL of the output, and the FR (Front Right) of the input to the FR of the output:
ffmpeg -i 6channels.wav -af "pan=stereo:c0=FL:c1=FR" stereo.wav
You can also map specific channels by number. This example will map the first and third channels of the input to the first and second channels of the output.
ffmpeg -i 6channels.wav -af "pan=stereo:c0=c0:c1=c2" output.wav
If the = in a channel specification is replaced by <, then the gains for that specification will be renormalized so that the total is 1, thus avoiding clipping noise. See the pan audio filter documentation for additional information and examples.
2 × stereo → stereo
Combine two stereo inputs into one stereo output with the amerge and pan audio filters:
ffmpeg -i input1.wav -i input2.wav -filter_complex "[0:a][1:a]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[aout]" -map "[aout]" output.mp3
Mix both stereo channels to stereo
The left channel and right channel will each contain both the left and right channels (like "mono as stereo"):
ffmpeg -i input.mp3 -af "pan=stereo:c0<c0+c1:c1<c0+c1" output.ogg
Switch stereo channels
Switch left channel to right and right channel to left:
ffmpeg -i stereo.ogg -map_channel 0.0.1 -map_channel 0.0.0 output.wav
or with the pan audio filer:
ffmpeg -i stereo.ogg -af pan=stereo:c0=c1:c1=c0 output.wav
Mute a channel
This example will mute the first channel (the left channel) but keep the second channel as is:
ffmpeg -i stereo.wav -map_channel -1 -map_channel 0.0.1 output.wav
Layouts
Output from ffmpeg -layouts:
Individual channels: NAME DESCRIPTION FL front left FR front right FC front center LFE low frequency BL back left BR back right FLC front left-of-center FRC front right-of-center BC back center SL side left SR side right TC top center TFL top front left TFC top front center TFR top front right TBL top back left TBC top back center TBR top back right DL downmix left DR downmix right WL wide left WR wide right SDL surround direct left SDR surround direct right LFE2 low frequency 2 Standard channel layouts: NAME DECOMPOSITION mono FC stereo FL+FR 2.1 FL+FR+LFE 3.0 FL+FR+FC 3.0(back) FL+FR+BC 4.0 FL+FR+FC+BC quad FL+FR+BL+BR quad(side) FL+FR+SL+SR 3.1 FL+FR+FC+LFE 5.0 FL+FR+FC+BL+BR 5.0(side) FL+FR+FC+SL+SR 4.1 FL+FR+FC+LFE+BC 5.1 FL+FR+FC+LFE+BL+BR 5.1(side) FL+FR+FC+LFE+SL+SR 6.0 FL+FR+FC+BC+SL+SR 6.0(front) FL+FR+FLC+FRC+SL+SR hexagonal FL+FR+FC+BL+BR+BC 6.1 FL+FR+FC+LFE+BC+SL+SR 6.1 FL+FR+FC+LFE+BL+BR+BC 6.1(front) FL+FR+LFE+FLC+FRC+SL+SR 7.0 FL+FR+FC+BL+BR+SL+SR 7.0(front) FL+FR+FC+FLC+FRC+SL+SR 7.1 FL+FR+FC+LFE+BL+BR+SL+SR 7.1(wide) FL+FR+FC+LFE+BL+BR+FLC+FRC 7.1(wide-side)FL+FR+FC+LFE+FLC+FRC+SL+SR octagonal FL+FR+FC+BL+BR+BC+SL+SR downmix DL+DR
Attachments (15)
-
2mono_stereo.png
(10.4 KB
) - added by 12 years ago.
2 mono files to stereo diagram
-
5point1_stereo.png
(16.0 KB
) - added by 12 years ago.
5.1 to stereo diagram
-
mono_stereo.png
(8.5 KB
) - added by 12 years ago.
mono to stereo diagram
-
mute_stereo_channel.png
(8.4 KB
) - added by 12 years ago.
mute a stereo channel diagram
-
stereo_2mono_outputs.png
(11.4 KB
) - added by 12 years ago.
stereo to 2 mono outputs diagram
-
stereo_2mono_streams.png
(11.1 KB
) - added by 12 years ago.
stereo to 2 mono streams diagram
-
stereo_mono.png
(9.3 KB
) - added by 12 years ago.
stereo to mono diagram
-
stereo_stereo_mix.png
(10.1 KB
) - added by 12 years ago.
stereo to stereo mix diagram
-
switch_stereo_channels.png
(9.5 KB
) - added by 12 years ago.
switch stereo channels diagram
-
2stereo_stereo.png
(15.4 KB
) - added by 12 years ago.
2 stereo inputs to 1 stereo output diagram
-
6mono_5point1.png
(29.3 KB
) - added by 12 years ago.
6 mono inputs to 5.1 output
-
5point1_6mono.png
(29.2 KB
) - added by 12 years ago.
5.1 to individual channels
-
diagrams.tar.gz
(32.9 KB
) - added by 12 years ago.
.dia files for AudioChannelManipulation in case changes are wanted
-
2stereo_stereob.png
(15.3 KB
) - added by 12 years ago.
2 stereo inputs to 1 stereo output diagram, alt
- stereo_mono_exclude.png (9.1 KB ) - added by 9 years ago.
Download all attachments as: .zip














