- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在处理多声道音频文件(高阶立体声),通常至少 16 个声道。
有时我只对音频 channel 的一个子集感兴趣(例如,包含更多 channel 的文件的前 25 个 channel )。
为此,我有一个如下所示的脚本,它需要一个多 channel 输入文件、一个输出文件和我要提取的 channel 数:
#!/bin/sh
infile=$1
outfile=$2
channels=$3
channelmap=$(seq -s"|" 0 $((channels-1)))
ffmpeg -y -hide_banner \
-i "${infile}" \
-filter_complex "[0:a]channelmap=${channelmap}" \
-c:a libopus -mapping_family 255 -b:a 160k -sample_fmt s16 -vn -f webm -dash 1 \
"${outfile}"
实际的 channel 提取是通过 channelmap filter 完成的,它是用 -filter:complex "[0:a]channelmap=0|1|2|3"
这适用于 1、2、4 或 16 个 channel 。
但是,它在 9 个 channel 、25 channel 和 17 个 channel (以及通常有 >>16 个 channel 的任何 channel )时失败。
我得到的错误是:
$ ffmpeg -y -hide_banner -i input.wav -filter_complex "[0:a]channelmap=0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16" -c:a libopus -mapping_family 255 -b:a 160k -sample_fmt s16 -vn -f webm -dash 1 output.webm
Input #0, wav, from 'input.wav':
Duration: 00:00:09.99, bitrate: 17649 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 25 channels, s16, 17640 kb/s
[Parsed_channelmap_0 @ 0x5568874ffbc0] Output channel layout is not set and cannot be guessed from the maps.
[AVFilterGraph @ 0x5568874fff40] Error initializing filter 'channelmap' with args '0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16'
Error initializing complex filters.
Invalid argument
所以 ffmpeg 无法猜测 17 channel 文件的 channel 布局。ffmpeg -layouts
仅列出具有 1、2、3、4、5、6、7、8 和 16 的 channel 布局。
不过,我真的不在乎 channel 布局。 “ channel 布局”的整个概念都围绕着这样一个想法,即每个音频 channel 都应该连接到不同的扬声器。但我的音频 channel 根本不是扬声器馈送。
所以我尝试提供明确的 channel 布局,比如 -filter_complex "[0:a]channelmap=map=0|1|2|3|4|5|6|7|8|9|10 |11|12|13|14|15|16:channel_layout=unknown"
,但这会导致解析 channel 布局时出错:
$ ffmpeg -y -hide_banner -i input.wav -filter_complex "[0:a]channelmap=map=0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16:channel_layout=unknown" -c:a libopus -mapping_family 255 -b:a 160k -sample_fmt s16 -vn -f webm -dash 1 output.webm
Input #0, wav, from 'input.wav':
Duration: 00:00:09.99, bitrate: 17649 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 25 channels, s16, 17640 kb/s
[Parsed_channelmap_0 @ 0x55b60492bf80] Error parsing channel layout: 'unknown'.
[AVFilterGraph @ 0x55b604916d00] Error initializing filter 'channelmap' with args 'map=0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16:channel_layout=unknown'
Error initializing complex filters.
Invalid argument
我还尝试了 any
、all
、none
、0x0
和 0xFF
具有相同的结果。我尝试使用 mono
(因为 channel 有点独立),但是 ffmpeg
试图变得聪明并告诉我 mono 布局不能有 17 个 channel 。
我知道 ffmpeg
可以处理没有布局的多 channel 文件。例如。转换一个没有 -filter_complex "..."
的 25 channel 文件没有问题,ffprobe
给我一个 unknown
channel 布局。
那么:在创建仅包含输入 channel 子集的输出文件时,我如何告诉 ffmpeg
不关心 channel_layout?
最佳答案
基于 Audio Channel Manipulation您可以尝试拆分成 n
个单独的流,然后将它们amerge
重新组合在一起:
-filter_complex "\
[0:a]pan=mono|c0=c0[a0];\
[0:a]pan=mono|c0=c1[a1];\
[0:a]pan=mono|c0=c2[a2];\
[0:a]pan=mono|c0=c3[a3];\
[0:a]pan=mono|c0=c4[a4];\
[0:a]pan=mono|c0=c5[a5];\
[0:a]pan=mono|c0=c6[a6];\
[0:a]pan=mono|c0=c7[a7];\
[0:a]pan=mono|c0=c8[a8];\
[0:a]pan=mono|c0=c9[a9];\
[0:a]pan=mono|c0=c10[a10];\
[0:a]pan=mono|c0=c11[a11];\
[0:a]pan=mono|c0=c12[a12];\
[0:a]pan=mono|c0=c13[a13];\
[0:a]pan=mono|c0=c14[a14];\
[0:a]pan=mono|c0=c15[a15];\
[0:a]pan=mono|c0=c16[a16];\
[a0][a1][a2][a3][a4][a5][a6][a7][a8][a9][a10][a11][a12][a13][a14][a15][a16]amerge=inputs=17"
关于ffmpeg - 在 ffmpeg 中处理多声道音频时忽略 "channel_layout",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65109784/
我是一名优秀的程序员,十分优秀!