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 的相关文章

  • 【Platform IO编译Hifive1-revB】*** [.pio\build\hifive1-revb\src\setupGPIO.o] Error 1的解决办法

    将小写的s改为大写的S xff0c 比如setupGPIO s改为setupGPIO S 还弹出一条警告platformio riscv64 unknown elf as unrecognized option 39 mcmodel 61
  • 简单解释补码为何需要取反加一

    首先补充基本知识有符号数补码表示为2 s complement xff0c 最高位与无符号数相比为负数 xff0c 补码表示法中全1为 1 xff0c 如1111 61 8 43 4 43 2 43 1 61 1 补码即取反1变为0 xff
  • VitualBox安装增强功能实现无缝模式和拖放功能(踩坑点记录汇总)

    VitualBox也算比较好用的 xff0c 就是安装窗口过小 xff0c 首先可以尝试在设置中更改 xff0c 找到显示Displays xff0c 根据显示器修改分辨路Resolution xff0c 如果字体太小可以缩放Scale选择
  • 【3DoF算法】

    VR 3DoF算法介绍 核心 xff1a 3DoF算法应用场景 xff0c 在VIO应用中 xff0c 当只有测量没有观测的情况下 xff0c 6DoF算法的预测会退化成一个只有测量的3DoF算法 xff0c 这时候需要使用3DoF算法 x
  • 2023 TIOBE 2月编程语言榜:年度语言是TA!

    前言 TIOBE 公布了 2023 年 2 月的编程语言排行榜 总的来说 xff0c 本月 TIOBE 指数变化不大 在获得 2022 年度编程语言之后 xff0c C 43 43 仍然保持着远远领先于其他编程语言的势头 xff0c 目前的
  • 2023!七大最佳Python书籍,入门到精通推荐!

    前言 什么是Python xff1f Python是一种高级编程语言 xff0c 用于使用正确的工具和库文件进行Web开发 xff0c 桌面应用程序 xff0c 人工智能 xff0c OS xff0c 原型 xff0c GUI应用 xff0
  • 电脑知识:Win10系统把系统盘的软件移到D盘的简单方法

    作者主页 xff1a IT技术分享社区 作者简介 xff1a 大家好 我是IT技术分享社区的博主 xff0c 从事C Java开发九年 xff0c 对数据库 C Java 前端 运维 电脑技巧等经验丰富 个人荣誉 xff1a 数据库领域优质
  • 操作系统:Win10的沙盒是什么,如何使用,看完你就懂了

    Win10操作系统新增的windows沙盒是一种安全机制 xff0c 为执行中的程式提供的隔离环境 通常是作为一些来源不可信 具有破坏力或无法判定程序意图的应用程序提供实验之用 很多网友想要通过沙盒运行一些未知的程序 xff0c 但是不知道
  • 收集一些程序员励志经典名言

    1 作为一个真正的程序员 xff0c 首先应该尊重编程 xff0c 热爱你所写下的程序 xff0c 他是你的伙伴 xff0c 而不是工具 2 程序员可以让步 xff0c 却不可以退缩 xff0c 可以羞涩 xff0c 却不可以软弱 xff0
  • 夸克浏览器网页版入口网址分享

    夸克浏览器是一款简约 无广告的浏览器软件 xff0c 致力于带给用户最流畅舒适的使用体验 但是有用户问小编夸克浏览器的网页版入口地址在哪 xff1f 那么小编这里就给大家分享一下夸克浏览器网页版入口 夸克浏览器网页版入口地址分享 夸克浏览器
  • 由于找不到iutils.dll无法继续执行代码?

    电脑缺少某个dll文件是非常常见的系统错误 xff0c 但是如果遇到由于找不到iutils dll无法继续执行代码的问题 xff0c 那就不是简单的缺少文件问题了 xff0c 是中了流氓软件的问题 方法一 xff1a 1 这个问题是由于中了
  • excel制作表格的详细步骤

    excel是办公软件Microsoft office的组件之一 xff0c 很多用户都会使用excel来制作表格 xff0c 快捷方便 xff0c 但是还有不少用户不清楚怎么使用excel制作表格 xff1f 下面就一起来瞧瞧吧 xff01
  • ms-gamingoverlay一直跳出来怎么解决?

    最近有Win11玩家发现自己在玩游戏的时候经常弹出ms gamingoverlay的弹窗 xff0c 非常影响自己的游戏体验感 xff0c 那有什么办法可以解决这一问题吗 xff1f 大家可以按照以下的解决办法操作 xff0c 希望可以帮到
  • 联想电脑黑屏但电源键亮着的解决办法

    最近有联想电脑用户跟小编反应 xff0c 自己的笔记本屏幕黑屏了但是电源键还是亮着的 xff0c 这是怎么回事 xff1f 很多用户遇到这种情况往往不知所措 xff0c 不知道如何处理 xff0c 那么小编这里就给大家分享一下联想电脑黑屏电
  • 【XR】VR手柄设计之LED光点布局

    1 如何设计一台VR手柄 xff08 设计一台VR手柄需要考虑以下几个方面 xff1a xff09 功能 xff1a VR手柄需要具备一定的交互功能 xff0c 例如触摸板 按键 扳机等 xff0c 以及能够感知手部动作和姿态的传感器 舒适
  • Win11怎么彻底卸载Xbox Game Bar?

    Xbox Game Bar是常用于捕捉 记录屏幕并与其他游戏玩家朋友聊天的工具 xff0c 缺点就是运行过程中会占用大量的空间 xff0c 有什么办法可以卸载Xbox Game Bar xff0c 释放空间吗 xff1f 下面就来看看详细的
  • Win11打开本地组策略编辑器的两种方法

    Win11是新推出的操作系统 xff0c 但是用户对很多操作都不熟悉 xff0c 想要通过本地组策略编辑器修改一些配置 xff0c 都找不到本地组策略编辑器 xff0c 那么Win11怎么打开本地组策略编辑器呢 xff1f 一起来看看具体的
  • 介绍一下115sha1链接使用方法

    收到一个115 开头的网盘链接 xff0c 要如何下载呢 xff1f 单纯复制这个链接是没有办法直接下载的 xff0c 复制进去还会显示链接地址错误 xff0c 那么小编这里就给大家分享一下正确的使用方法 xff0c 希望可以帮到你 115

随机推荐

  • 夸克网盘的文件怎么保存到百度网盘?

    我们经常将自己的文件 视频等等都传到网盘上储存 xff0c 大大减少电脑和手机的占用 xff0c 其中百度网盘和夸克网盘是非常受欢迎的两款软件 xff0c 拥有超大的云储存空间 xff0c 用户想存什么就存什么 那夸克网盘的文件能存到百度网
  • Furmark如何进行正确的烤机?

    Furmark是一款非常不错的显卡性能以及稳定度测试软件 xff0c 通过这款软件可以快速测试出显卡的性能以及显卡是否稳定 xff0c 下面小编就来教教大家Furmark如何进行正确的烤机吧 1 打开Furmark xff0c 可以看到如图
  • WinRAR一直自动关闭怎么回事

    很多用户都习惯使用WinRAR来压缩解压文件 xff0c 但是有小伙伴跟小编反映自己的WinRAR老是一直闪退 xff0c 这是怎么回事 xff1f 下面就来看看WinRAR软件闪退的解决办法吧 Win10纯净版 Win10 64位纯净版
  • win11共享文件夹需要用户名和密码?

    在共享文件夹时提示需要用户名和密码 xff0c 这是怎么回事 xff1f 不少win11用户跟小编反映了这个问题 xff0c 我们要如何解决呢 xff1f 下面就来看看具体的win11共享文件夹需要用户名和密码的解决办法吧 win11共享文
  • win11桌面文件在哪个文件夹?

    很多win10系统用户应该都知道 xff0c 桌面文件默认存储在C xff1a Users Username Desktop文件夹中 xff0c 那升级win11之后 xff0c 桌面文件在哪个文件夹呢 xff1f 有没有改动呢 xff1f
  • win7时间总是不对怎么办?

    一般用户的主机中的主板会有一个电池 xff0c 这个电池可以给主板供电 xff0c 但是主板电池没电了的话就会将原本的时间设置清空 xff0c 因此这个时候时间就是不对的 xff0c 下面就是关于win7时间总是不对的解决方法 xff0c
  • Win10无法连接打印机怎么办?不能使用打印机的解决方法

    在我们平常的办公中 xff0c 经常会需要使用到打印机打印文件 想要使用打印机是需要先将电脑与打印机连接的 xff0c 但是有部分Win10用户遇到了无法连接打印机的情况 xff0c 对于这种情况应该如何解决呢 xff1f 下面来看看详细的
  • 【python】6DOF analyse tool

    1 result show 1 1 note 图1为3D位置 xff0c 图2 xff0c 3 xff0c 4分别表示yaw pitch xff0c roll角随着时间的变化的波动 2 code span class token comme
  • Spring入门预备知识(上)

    Spring入门主要使用了下面几个技术 xff1a 工厂模式 单例模式 动态代理模式 面向接口编程 xff0c 下面分几部分详细分析 一 xff09 工厂模式 1 定义 xff1a 定义一个用于创建对象的接口 xff0c 让子类决定实例化哪
  • 电脑丢失dll文件能一键修复吗,哪种修复方法靠谱?

    Dll文件的丢失其实是一件挺常见的事情的 xff0c 最近就有网友问小编 xff0c 关于dll文件丢失的相关问题 xff0c 他问电脑丢失dll文件能一键修复吗 xff1f 这里小编告诉你 xff0c 有方法一键修复 xff0c 但是需要
  • vcruntime140_1.dll无法继续执行代码,怎么解决这种问题?

    经常使用电脑的人 xff0c 可能对于这个弹出框应该不陌生 xff0c vcruntime140 1 dll无法继续执行代码 xff0c 其实会出现这种情况 xff0c 主要是因为缺少一个动态链接库 DLL 文件导致的 这个文件是 Visu
  • 这可能是最简单又有效的自监督学习方法了

    文 王珣 64 知乎 本文已获作者授权 xff0c 禁止二次转载 从Kaiming的MoCo和Hinton组Chen Ting的SimCLR开始 xff0c 自监督学习 xff08 SSL xff09 成了计算机视觉的热潮显学 凡是大佬大组
  • idea 2022.1 创建maven卡死解决

    1 关闭项目 2 新建maven项目 创建成功
  • 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
  • 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到
  • 【python】6DOF analyse tool2

    result show 1 1 note 图1为3D X Y Z combination位置 xff0c 图4 xff0c 5 xff0c 6分别表示yaw pitch xff0c roll角随着时间的变化的波动 span class to
  • AudioChannelManipulation

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