FFMPEG,如何创建自定义波形
FFMPEG, how to create custom waveform
我已经进行了研究,试图用 FFMPEG 创建一个波形,目前我能够创建一个透明的白色 png 波形。目标是生成像下面的平滑波浪一样的波浪,并使灰色透明。
这是我当前的 FFMPEG 波形发生器和输出。
ffmpeg -i ./_test.mp3 -filter_complex \
"[0:a]aformat=channel_layouts=mono,compand=gain=-6, \
showwavespic=s=450x46:colors=white,negate[a]; \
color=white:450x46[c]; \
[c][a]alphamerge" -vframes 1 _test.png
您将无法在 FFmpeg 中执行此操作,一是因为波形不是用线绘制的,而是用填充的多边形绘制的,二是因为 FFmpeg 似乎无法处理毫秒持续时间的音频。
使用更高级的 math/plotting 软件(如 R、Octave 或 matplotlib)可能可以做到这一点,但我的第一个想法是使用三个更小、更专业的命令行实用程序:
- SoX 到 trim,重新采样音频文件并将其保存为可解析的 .dat 格式
- (grep/sed清理.dat文件)
- Gnuplot 根据该 .dat 文件绘制绘图并另存为 .png
- Imagemagick 修改 .png 使绘制的线条透明
最后我的示例脚本变成了这样
# create example file
sox -n -r 32k -b 16 pnoise.wav synth 10 pinknoise norm -0.1
# trim/convert
sox --norm=-1 pnoise.wav test.dat remix 1 trim 5 0.002 rate 200k
grep -v "^;" test.dat |\
sed -e "s/^[[:space:]]*//" -e "s/[[:space:]]*$//" > test.txt
# draw plot
gnuplot
set term png size 600,200 background "#BBBBBB"
set output "test.png"
unset key
unset border
unset xtics
unset ytics
set margins 0, 0, 0, 0
set yrange [-1:1]
plot "test.txt" with lines lt rgb "#FF0000" lw 3
exit
# replace red opaque with fully transparent
mogrify -channel rgba -matte -fill "#FF000000" -opaque "#FF0000" test.png
我已经进行了研究,试图用 FFMPEG 创建一个波形,目前我能够创建一个透明的白色 png 波形。目标是生成像下面的平滑波浪一样的波浪,并使灰色透明。
这是我当前的 FFMPEG 波形发生器和输出。
ffmpeg -i ./_test.mp3 -filter_complex \
"[0:a]aformat=channel_layouts=mono,compand=gain=-6, \
showwavespic=s=450x46:colors=white,negate[a]; \
color=white:450x46[c]; \
[c][a]alphamerge" -vframes 1 _test.png
您将无法在 FFmpeg 中执行此操作,一是因为波形不是用线绘制的,而是用填充的多边形绘制的,二是因为 FFmpeg 似乎无法处理毫秒持续时间的音频。
使用更高级的 math/plotting 软件(如 R、Octave 或 matplotlib)可能可以做到这一点,但我的第一个想法是使用三个更小、更专业的命令行实用程序:
- SoX 到 trim,重新采样音频文件并将其保存为可解析的 .dat 格式
- (grep/sed清理.dat文件)
- Gnuplot 根据该 .dat 文件绘制绘图并另存为 .png
- Imagemagick 修改 .png 使绘制的线条透明
最后我的示例脚本变成了这样
# create example file
sox -n -r 32k -b 16 pnoise.wav synth 10 pinknoise norm -0.1
# trim/convert
sox --norm=-1 pnoise.wav test.dat remix 1 trim 5 0.002 rate 200k
grep -v "^;" test.dat |\
sed -e "s/^[[:space:]]*//" -e "s/[[:space:]]*$//" > test.txt
# draw plot
gnuplot
set term png size 600,200 background "#BBBBBB"
set output "test.png"
unset key
unset border
unset xtics
unset ytics
set margins 0, 0, 0, 0
set yrange [-1:1]
plot "test.txt" with lines lt rgb "#FF0000" lw 3
exit
# replace red opaque with fully transparent
mogrify -channel rgba -matte -fill "#FF000000" -opaque "#FF0000" test.png