如何在 Linux 中创建 MP3 的波形图像?
给定一个 MP3,我想将文件中的波形提取到图像 (.png) 中,
是否有一个包可以满足我的需要?
Given an MP3 I would like to extract the waveform from the file into an image (.png)
Is there a package that can do what I need ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用
sox
和gnuplot
您可以创建基本波形图像:东西,请使用以下 GNU Plot 文件作为模板(将其另存为 audio.gpi):
然后运行:
基于此答案对类似问题在文件格式方面更通用,但在使用的软件方面不太通用。
Using
sox
andgnuplot
you can create basic waveform images:To create something simpler/prettier, use the following GNU Plot file as a template (save it as audio.gpi):
and just run:
Based on this answer to a similar question that is more general regarding file format but less general in regards to software used.
FFmpeg
showwavespic
FFmpeg 可以像往常一样在单个命令中完成此操作:
示例命令:
您还可以在 RGB 中设置
颜色
colors=0x0088FF: 在 ffmpeg 的 showwaves 中使用十六进制颜色
我说的示例测试数据“你好,我的名字是 Ciro Santilli”,有两个相同的立体声通道:
输出:
背景颜色
默认情况下背景是透明的,但是:
,这样我们就可以达到:
现在已添加到 Wiki ;-)
对于新手来说,该 CLI 创建了一个处理图:
其中,例如,
overlay
过滤器采用两个图像输入并生成所需的输出,而fg
只是分配给中间节点的名称。分割通道
本教程还介绍了其他选项,例如使用
-filter_complex "showwavespic=s=640x480:colors=black:split_channels=1"
分割通道:带轴的 gnuplot 图
好吧,我承认,FFmpeg 还不能单独做到这一点(还!)。但 Wiki 已经提供了一种有效的 gnuplot 数据导出方法:
视频表示
请参阅:https://superuser.com/questions/843774/create-a-video-file-from-an-音频文件和从音频添加可视化
在 Ubuntu 20.04、FFmpeg 4.2.4 上测试。
FFmpeg
showwavespic
FFmpeg can do it in a single command as usual:
Sample command:
You can also set
colors
in RGBcolors=0x0088FF
: Using hex colors with ffmpeg's showwavesSample test data of me saying "Hello my name is Ciro Santilli" with two identical stereo channels:
Output:
Background color
The background is transparent by default, but:
and so we reach:
Added to the Wiki now ;-)
For the uninitiated, that CLI creates a processing graph:
where e.g. the
overlay
filter takes two image inputs and produces the desired output, andfg
is just a name assigned to an intermediate node.Split channels
The tutorial also covers other options such as split channels with
-filter_complex "showwavespic=s=640x480:colors=black:split_channels=1"
:gnuplot plot with axes
OK, I'll admit it, FFmpeg can't do this alone (yet!). But the Wiki already provides a data export method to gnuplot that works:
Video representations
See: https://superuser.com/questions/843774/create-a-video-file-from-an-audio-file-and-add-visualizations-from-audio
Tested on Ubuntu 20.04, FFmpeg 4.2.4.
如果您有 GUI 环境,则可以使用 audacity 音频编辑器加载 mp3,然后使用打印命令生成波形的 pdf。然后将pdf转换为png。
If you have a GUI environment you can use the audacity audio editor to load the mp3 and then use the print command to generate a pdf of the waveform. Then convert the pdf to png.
我会做这样的事情:
找到一个工具将 mp3 转换为 PCM,即具有一个 8 或 16 位值的二进制数据
每个样品。我猜 mplayer 可以做到这一点
将结果通过管道传输到将二进制数据转换为 ascii 的实用程序
以十进制格式表示数字
使用 gnuplot 将此值列表转换为 png 图形。
瞧,Unix 工具之间管道的力量。现在,如果 gnuplot 能够从二进制格式读取数据,则此列表中的步骤 2 可能是可选的。
I would do something like this :
find a tool to convert mp3 to PCM, ie binary data with one 8 or 16 bit value
per sample. I guess mplayer can do that
pipe the result to a utility converting binary data to an ascii
representation of the numbers in decimal format
use gnuplot to transform this list of value into a png graph.
And voilà, the power of piping between unix tools. Now Step 2 in this list might be optionnal if gnuplot is able to read it's data from a binary format.
您可能需要考虑 BBC 的音频波形。
https://github.com/bbcrd/audiowaveform
You might want to consider audiowaveform from the BBC.
https://github.com/bbcrd/audiowaveform
这是 SoX(用于声音、Windows 和 Linux 的命令行工具)中的标准函数
功能
检查 http://sox.sourceforge.net/sox.html 上的“频谱图” 频谱图以便携式网络图形 (PNG) 文件形式呈现,X 轴显示时间,Y 轴显示频率,Z 轴显示音频信号幅度,值由颜色 ( 表示)。如果音频信号包含多个通道,则从通道 1(立体声音频的左通道)开始从上到下显示这些通道。
This is a standard function in SoX (command line tool for sound, Windows & Linux)
Check the 'spectrogram' function on http://sox.sourceforge.net/sox.html
"The spectrogram is rendered in a Portable Network Graphic (PNG) file, and shows time in the X-axis, frequency in the Y-axis, and audio signal magnitude in the Z-axis. Z-axis values are represented by the colour (or optionally the intensity) of the pixels in the X-Y plane. If the audio signal contains multiple channels then these are shown from top to bottom starting from channel 1 (which is the left channel for stereo audio)."
基于 qubodup 的答案,
您还可以在配置文件中注释“设置输出...”行,然后执行
配置文件在本例中为 audio.gpi,其内部有
生成如下所示的图像
< /a>
我想要没有轴,没有图例,png(比 svg 小得多)。
Building on the answer of qubodup
You can also comment the "set output ..." line in the configuration file and do
The configuration file is audio.gpi in this case and inside it has
Which produces images like the following
I wanted no axis, no legend, png (much smaller than svg).