为具有大量通道的音频文件生成波形

Generate waveforms for audio files with large amount of channels

我想使用 FFmpeg 库生成显示交错音频 .wav 文件波形的 .png 文件。 http://ffmpeg.org/documentation.html

如果交错的音频文件包含最多 8 个通道,我设法使用以下命令行成功实现:

ffmpeg -i 8_channels_input.wav -y -filter_complex "showwavespic=s=1920x1200:split_channels=1" -frames:v 1 8_channels_waveform_output.png

但是,如果交错的音频文件包含超过 8 个声道,FFmpeg 给出以下内容:

Input #0, wav, from '30_channels_input.wav': Duration: 00:00:02.08, bitrate: 31752 kb/s Stream #0:0: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, 30 channels, s32 (24 bit), 31752 kb/s Stream mapping: Stream #0:0 (pcm_s24le) -> showwavespic showwavespic -> Stream #0:0 (png) Press [q] to stop, [?] for help [auto_resampler_0 @ 0x7faf5d60a3c0] Cannot select channel layout for the link between filters auto_resampler_0 and Parsed_showwavespic_0. [auto_resampler_0 @ 0x7faf5d60a3c0] Unknown channel layouts not supported, try specifying a channel layout using 'aformat=channel_layouts=something'. Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0 Conversion failed!

这是相关文档(c.f。页面底部): https://trac.ffmpeg.org/wiki/AudioChannelManipulation

我的问题是: 我需要生成包含多达 30 个通道的音频文件的可视化波形。 到目前为止,我所有的尝试都没有成功(我正在尝试定义自定义频道布局,但我不确定我是否在正确的轨道上)。

为了简化,我需要complete/modify以下命令使其工作:

ffmpeg -i 30_channels_input.wav -y -filter_complex "showwavespic=s=1920x1200:split_channels=1" -frames:v 1 30_channels_waveform_output.png 

[编辑] 备注:

我设法通过组合现有布局生成 10 个通道输入的波形:

ffmpeg -i 10_channels_input.wav -y -filter_complex "aformat=channel_layouts=7.1+downmix, showwavespic=s=1920x1200:split_channels=1" -frames:v 1 10_channels_waveform_output.png

但是,如果您尝试通过组合 5x 6.0 布局为 30 个通道输入执行此操作:

ffmpeg -i 30_channels_input.wav -y -filter_complex "aformat=channel_layouts=6.0+6.0+6.0+6.0+6.0, showwavespic=s=1920x1200:split_channels=1" -frames:v 1 30_channels_waveform_output.png

FFmpeg 给出以下内容:

[auto_resampler_0 @ 0x7ffd7002a480] [SWR @ 0x7ffd7013a000] Rematrix is needed between 30 channels and 6.0 but there is not enough information to do it [auto_resampler_0 @ 0x7ffd7002a480] Failed to configure output pad on auto_resampler_0 Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0

我的假设是我需要使用 30 个唯一的频道 ID(c.f。https://trac.ffmpeg.org/wiki/AudioChannelManipulation 页面底部)创建自定义布局,而不是组合现有布局。

不过似乎只有 25 个频道 ID 可用。创建具有 30 个频道的自定义布局可能根本不可能...

[编辑 2] 备注:

我终于找到了我要找的文档。但是生成30个通道的波形好像还是有难度。

创建自定义布局的方法如下: https://ffmpeg.org/ffmpeg-utils.html

A custom channel layout can be specified as a sequence of terms, separated by ’+’ or ’|’. Each term can be:

the name of a standard channel layout (e.g. ‘mono’, ‘stereo’, ‘4.0’, ‘quad’, ‘5.0’, etc.) the name of a single channel (e.g. ‘FL’, ‘FR’, ‘FC’, ‘LFE’, etc.) a number of channels, in decimal, followed by ’c’, yielding the default channel layout for that number of channels (see the function av_get_default_channel_layout). Note that not all channel counts have a default layout. a number of channels, in decimal, followed by ’C’, yielding an unknown channel layout with the specified number of channels. Note that not all channel layout specification strings support unknown channel layouts. a channel layout mask, in hexadecimal starting with "0x" (see the AV_CH_* macros in libavutil/channel_layout.h. Before libavutil version 53 the trailing character "c" to specify a number of channels was optional, but now it is required, while a channel layout mask can also be specified as a decimal number (if and only if not followed by "c" or "C").

See also the function av_get_channel_layout defined in libavutil/channel_layout.h.

例如

因此,对于 11 个通道输入:

ffmpeg -i 11_channels_input.wav -y -filter_complex "aformat=channel_layouts=FL+FR+FC+BL+BR+BC+SL+SR+WL+WR+TBL, showwavespic=s=1920x1200:split_channels=1" -frames:v 1 11_waveform_output.png

--> 为我工作

同时:

ffmpeg -i 11_channels_input.wav -y -filter_complex "aformat=channel_layouts=11c, showwavespic=s=1920x1200:split_channels=1" -frames:v 1 11_waveform_output.png

--> 不起作用

但是:

ffmpeg -i 24_channels_input.wav -y -filter_complex "aformat=channel_layouts=24c, showwavespic=s=1920x1200:split_channels=1" -frames:v 1 24_waveform_output.png

--> 有效

最后,我仍在努力实现的目标:

ffmpeg -i 30_channels_input.wav -y -filter_complex "aformat=channel_layouts=30c, showwavespic=s=1920x1200:split_channels=1" -frames:v 1 30_waveform_output.png

--> 不起作用

p.s.

未经测试的解决方法是使用 pan 选择每个通道,每个通道一个 showwavespic,然后使用 vstack 堆叠它们:

ffmpeg -i input.wav -filter_complex
  "[0:a]pan=mono|c0=c0,showwavespic=s=1920x40[a0];
   [0:a]pan=mono|c0=c1,showwavespic=s=1920x40[a1];
   ...
   [0:a]pan=mono|c0=c29,showwavespic=s=1920x40[a29];
   [a0][a1]...[a29]vstack=inputs=30" output.png