AudioChannelManipulation

来源:互联网 发布:java代码坐标转平面 编辑:程序博客网 时间:2024/05/16 14:14

Manipulating audio channels with ffmpeg

Contents

  1. stereo → mono stream
  2. stereo → 2 × mono files
  3. stereo → 2 × mono streams
  4. mono → stereo
  5. 2 × mono → stereo
  6. 6 × mono → 5.1
  7. 5.1 → 6 × mono
  8. 5.1 → stereo
  9. 2 × stereo → stereo
  10. Mix both stereo channels to stereo
  11. Switch stereo channels
  12. Virtual Binaural Acoustics
  13. Mute a channel
  14. Statistics
  15. Layouts

stereo → mono stream

stereo to mono diagram

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

Note: Any out of phase stereo will cancel out.

stereo → 2 × mono files

stereo to 2 mono outputs diagram

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=1c|c0=c0[left];[0:0]pan=1c|c0=c1[right]" -map "[left]" left.wav -map "[right]" right.wav

stereo → 2 × mono streams

stereo to 2 mono streams diagram

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=channel_layout=stereo 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

mono to stereo diagram

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=inputs=2[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

2 mono files to stereo diagram

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=inputs=2[aout]" -map "[aout]" output.mka

6 × mono → 5.1

6 mono inputs to 5.1 output

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

5.1 to individual channels

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

5.1 to stereo diagram

To downmix you can simply use -ac 2:

ffmpeg -i 6channels.wav -ac 2 stereo.wav

Notes:

  • By default when using -ac 2 the LFE channel is omitted. See "Digital Audio Compression Standard (Document A/52:2012)", sections 6.1.12 and 7.8 for more downmixing info.
  • ffmpeg integrates a default down-mix (and up-mix) system that should be preferred (the -ac option) 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

2 stereo inputs to 1 stereo output diagram

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=inputs=2,pan=stereo|c0<c0+c2|c1<c1+c3[aout]" -map "[aout]" output.mp3

Or use -ac 2 instead of the pan audio filter:

ffmpeg -i input1.wav -i input2.wav -filter_complex "[0:a][1:a]amerge=inputs=2[aout]" -map "[aout]" -ac 2 output.mp3

Note: The output produced with the pan audio filter may not be identical to the output produced with -ac 2, so you'll have to listen to your outputs or view audio statistics to determine which output suits you.

2 stereo inputs to 1 stereo output diagram, alt

A similar situation as above, but instead use the left and right channels from the first input to make the left channel out the output, and use the left and right channels of the second input to make the right channel of the output.

Just change the channel specifications in the pan filter:

ffmpeg -i input1.wav -i input2.wav -filter_complex "[0:a][1:a]amerge=inputs=2,pan=stereo|c0<c0+c1|c1<c2+c3[aout]" -map "[aout]" output.mp3

The pan audio filter has to be used in this situation instead of -ac 2 unlike the previous example.

Mix both stereo channels to stereo

stereo to stereo mix diagram

The left and right channels of the output will each contain both the left and right channels of the input:

ffmpeg -i input.mp3 -af "pan=stereo|c0<c0+c1|c1<c0+c1" output.ogg

Switch stereo channels

switch stereo channels diagram

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

Virtual Binaural Acoustics

FFmpeg can produce virtual binaural acoustics files using sofalizer filter, most known channel layouts are supported for input, output is always stereo.

ffmpeg -i input.wav -af sofalizer=/path/to/sofa/file output.flac

SOFA files can be found on http://sofacoustics.org/data/database/ari/


Mute a channel

mute a stereo channel diagram

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

Statistics

The astats audio filter can display information including length, DC offset, min/max levels, peak/RMS level dB:

$ ffmpeg -i input.wav -af astats -f null -…[Parsed_astats_0 @ 0x168a260] Channel: 1[Parsed_astats_0 @ 0x168a260] DC offset: -0.001829[Parsed_astats_0 @ 0x168a260] Min level: -0.605072[Parsed_astats_0 @ 0x168a260] Max level: 0.607056[Parsed_astats_0 @ 0x168a260] Peak level dB: -4.335430[Parsed_astats_0 @ 0x168a260] RMS level dB: -20.298984[Parsed_astats_0 @ 0x168a260] RMS peak dB: -12.303891[Parsed_astats_0 @ 0x168a260] RMS trough dB: -35.352893[Parsed_astats_0 @ 0x168a260] Crest factor: 6.283154[Parsed_astats_0 @ 0x168a260] Flat factor: 0.000000[Parsed_astats_0 @ 0x168a260] Peak count: 2[Parsed_astats_0 @ 0x168a260] Channel: 2[Parsed_astats_0 @ 0x168a260] DC offset: -0.001826[Parsed_astats_0 @ 0x168a260] Min level: -0.585999[Parsed_astats_0 @ 0x168a260] Max level: 0.608490[Parsed_astats_0 @ 0x168a260] Peak level dB: -4.314931[Parsed_astats_0 @ 0x168a260] RMS level dB: -20.519969[Parsed_astats_0 @ 0x168a260] RMS peak dB: -12.056472[Parsed_astats_0 @ 0x168a260] RMS trough dB: -36.784681[Parsed_astats_0 @ 0x168a260] Crest factor: 6.460288[Parsed_astats_0 @ 0x168a260] Flat factor: 0.000000[Parsed_astats_0 @ 0x168a260] Peak count: 2[Parsed_astats_0 @ 0x168a260] Overall[Parsed_astats_0 @ 0x168a260] DC offset: -0.001829[Parsed_astats_0 @ 0x168a260] Min level: -0.605072[Parsed_astats_0 @ 0x168a260] Max level: 0.608490[Parsed_astats_0 @ 0x168a260] Peak level dB: -4.314931[Parsed_astats_0 @ 0x168a260] RMS level dB: -20.408071[Parsed_astats_0 @ 0x168a260] RMS peak dB: -12.056472[Parsed_astats_0 @ 0x168a260] RMS trough dB: -36.784681[Parsed_astats_0 @ 0x168a260] Flat factor: 0.000000[Parsed_astats_0 @ 0x168a260] Peak count: 2.000000[Parsed_astats_0 @ 0x168a260] Number of samples: 1440706

Layouts

Output from ffmpeg -layouts:

Individual channels:NAME        DESCRIPTIONFL          front leftFR          front rightFC          front centerLFE         low frequencyBL          back leftBR          back rightFLC         front left-of-centerFRC         front right-of-centerBC          back centerSL          side leftSR          side rightTC          top centerTFL         top front leftTFC         top front centerTFR         top front rightTBL         top back leftTBC         top back centerTBR         top back rightDL          downmix leftDR          downmix rightWL          wide leftWR          wide rightSDL         surround direct leftSDR         surround direct rightLFE2        low frequency 2Standard channel layouts:NAME           DECOMPOSITIONmono           FCstereo         FL+FR2.1            FL+FR+LFE3.0            FL+FR+FC3.0(back)      FL+FR+BC4.0            FL+FR+FC+BCquad           FL+FR+BL+BRquad(side)     FL+FR+SL+SR3.1            FL+FR+FC+LFE5.0            FL+FR+FC+BL+BR5.0(side)      FL+FR+FC+SL+SR4.1            FL+FR+FC+LFE+BC5.1            FL+FR+FC+LFE+BL+BR5.1(side)      FL+FR+FC+LFE+SL+SR6.0            FL+FR+FC+BC+SL+SR6.0(front)     FL+FR+FLC+FRC+SL+SRhexagonal      FL+FR+FC+BL+BR+BC6.1            FL+FR+FC+LFE+BC+SL+SR6.1(back)      FL+FR+FC+LFE+BL+BR+BC6.1(front)     FL+FR+LFE+FLC+FRC+SL+SR7.0            FL+FR+FC+BL+BR+SL+SR7.0(front)     FL+FR+FC+FLC+FRC+SL+SR7.1            FL+FR+FC+LFE+BL+BR+SL+SR7.1(wide)      FL+FR+FC+LFE+BL+BR+FLC+FRC7.1(wide-side) FL+FR+FC+LFE+FLC+FRC+SL+SRoctagonal      FL+FR+FC+BL+BR+BC+SL+SRhexadecagonal  FL+FR+FC+BL+BR+BC+SL+SR+TFL+TFC+TFR+TBL+TBC+TBR+WL+WRdownmix        DL+DR
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 香水喷到眼睛里怎么办 萍果平板锁机怎么办? 苹果6开机卡死怎么办 辐射4发夹用完了怎么办 辐射4多的武器怎么办 大姨妈恶心想吐怎么办 玩完游戏想吐怎么办 玩完了海盗船想吐怎么办 戴眼镜恶心想吐怎么办 玩电脑恶心想吐怎么办 玩游戏玩的头疼怎么办 玩游戏头疼想吐怎么办 游戏玩久了头疼怎么办 有3d眩晕症怎么办 玩游戏晕3d怎么办 梦幻西游亏的钱怎么办 普惠卡销户了钱存进去了怎么办 梦幻西游现金变储备了怎么办 孩子挣了钱存不下怎么办 电脑显示副本不是正版怎么办 斗战神师徒一个人删除角色怎么办 起业kx5防盗器不响怎么办 灌浆记录仪存盘满了怎么办 自首后发现无罪证据怎么办 中国劲酒过期了怎么办 玻尿酸流到眼皮怎么办 手指被胶带缠紫了怎么办 打玻尿酸不平整怎么办 孩子被老师体罚我该怎么办 孩子妈妈入狱了我该怎么办 机顶盒电视收不到台怎么办 跳芭蕾舞下面硬起来了怎么办 深情密码结局赵深深怎么办 宝宝头着地摔了怎么办 小孩头着地摔了怎么办 头朝下墩了脖子怎么办 两岁摔倒头着地怎么办 马桶大便冲不下去怎么办 脚丫吧里起泡痒怎么办 脚受伤后肿了怎么办 摔到了腿受伤了怎么办