AudioChannelManipulation

2023-05-16

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        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(back)      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
hexadecagonal  FL+FR+FC+BL+BR+BC+SL+SR+TFL+TFC+TFR+TBL+TBC+TBR+WL+WR
downmix        DL+DR  
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AudioChannelManipulation 的相关文章

随机推荐

  • 谷歌打响全面反击战!官宣AI重构搜索、新模型比肩GPT-4,朝着ChatGPT微软开炮

    夕小瑶科技说 分享 来源 量子位 作者 明敏 丰色 万众瞩目 xff0c 谷歌的反击来了 现在 xff0c 谷歌搜索终于要加入AI对话功能了 xff0c 排队通道已经开放 当然这还只是第一步 大的还在后面 xff1a 全新大语言模型PaLM
  • eclipse解决中文乱码

    eclipse解决中文乱码 xff08 注释乱码 xff09 第一种 点击window gt perference gt general gt workspace里面的text file encoding改成other gt utf 8 步
  • Dynamic Web Module 4.0 requires Java 1.8 or newer.

    Dynamic Web Module 4 0 requires Java 1 8 or newer java代码没错 xff0c 但项目上有个红叉新建Dynamic Web项目 xff0c 报 Dynamic Web Module 4 0
  • 08-Linux账号管理学习

    Linux账号管理学习 账号管理 简介 Linux系统是一个多用户多任务的分时操作系统 xff0c 任何一个要使用系统资源的用户 xff0c 都必须首先向系统管理员申请一个账号 xff0c 然后以这个账号的身份进入系统 用户的账号一方面可以
  • 06-springboot集成ES详解

    springboot集成ES详解 1 new springboot项目 xff08 看项目记得配环境 xff0c 如jdk xff09 问题 xff1a 一定要保证我们导入的依赖和我们es版本一致 编写config配置类 span clas
  • 07-DockerFile

    文章目录 DockerFileDockerFile构建过程 DockerFile的指令 实战 构建自己的centosCMD 和 ENTRYPOINT 的区别实战 xff1a DockerFile制作tomcat镜像发布镜像发布镜像到阿里云镜
  • 23种设计模式

    此笔记从B站狂神说Java 获取 什么是设计模式 学习设计模式的意义 GoF23 oop七大原则 xff08 1 xff09 开闭原则 一个软件的实体应当对扩展开放 xff0c 对修改关闭 xff1b xff08 2 xff09 里氏替换原
  • springboot上传-下载文件-Hutool

    springboot上传 下载文件 Hutool 1 导入依赖 span class token tag span class token tag span class token punctuation lt span dependenc
  • springsecurity复习

    springsecurity 新建springboot项目 1 导入依赖 span class token tag span class token tag span class token punctuation lt span depe
  • Keras输出Tensor具体值

    Keras输出Tensor具体值 在Tensorflow中 xff0c 如果直接打印Tensor的值 xff0c 一般只会输出其格式 xff0c 例如 tf Tensor 但是有些时候就需要在程序中 xff0c 将具体的内容输出 xff1b
  • jenkins学习

    文章目录 jenkinsGitLab安装使用在ssh下安装gitlab1 安装依赖2 配置镜像3 开始安装gitlab常用命令 在docker下安装gitlab安装docker使用容器安装gitlab访问管理员账号登录 Jenkins安装安
  • java中操作redis

    对Hashmap的操作 span class token annotation punctuation 64 Autowired span span class token keyword private span span class t
  • C++ 网络编程 TCP 用select实现的并发 异步

    C 43 43 TCP网络编程 服务器端多线程处理会话连接 xiyangxiaoguo的博客 CSDN博客 上一篇采用的是建立新的线程的方法去处理一个新的客户端到服务器的TCP连接 xff0c 对于少量的客户端连接到服务器这种方法不存在问题
  • FFmpeg 命令常见操作

    1 转码 ffmpeg i source mp4 ss 20 t 10 c copy my mp4 ffmpeg ss 10 t 15 accurate seek i test mp4 c a copy c v copy tt mp4 i
  • FFprobe查看&统计视频信息

    1 查看音视频信息 1 1 查看基本信息 ffprobe span class token number 1280 span x720 h264 8mbps 30fps span class token punctuation span m
  • 百度2014校园招聘研发工程师笔试题+答案

    一 xff0c 简答题 30分 1 xff0c 当前计算机系统一般会采用层次结构存储数据 xff0c 请介绍下典型计算机存储系统一般分为哪几个层次 xff0c 为什么采用分层存储数据能有效提高程序的执行效率 xff1f 10分 xff08
  • Linux 查看文件夹大小,磁盘剩余空间(du/df)

    1 简介 du查看目录大小 xff0c df查看磁盘使用情况 2 du disk usage xff08 1 xff09 基本功能 递归查看文件夹下所有文件的大小 xff08 2 xff09 常用参数 xff1a h human reada
  • Python matplotlib高级绘图详解

    1 前言 前面我们介绍了使用matplotlib简单的绘图方法 xff08 见 xff1a Python应用matplotlib绘图简介 xff09 但是想要完全控制你的图形 xff0c 以及更高级的用法 xff0c 就需要使用 pyplo
  • ffmpeg视频精准剪切

    1 导言 ffmepg剪切视频 xff0c 很方便 xff0c 但是也有很大缺陷 xff1a xff08 1 xff09 剪切时间点不精确 xff08 2 xff09 有时剪切的视频开头有黑屏 造成这些问题的原因是ffmpeg无法seek到
  • AudioChannelManipulation

    Manipulating audio channels with ffmpeg Contents stereo mono streamstereo 2 mono filesstereo 2 mono streamsmono stereo2