简体   繁体   English

使用 FFMPEG 从音频生成波形视频

[英]Produce waveform video from audio using FFMPEG

I am trying to create a waveform video from audio.我正在尝试从音频创建波形视频。 My goal is to produce a video that looks something like this我的目标是制作一个看起来像这样的视频

在此处输入图像描述

For my test I have an mp3 that plays a short clipped sound.对于我的测试,我有一个 mp3 播放短的剪辑声音。 There are 4 bars of 1/4 notes and 4 bars of 1/8 notes played at 120bpm.有 4 小节 1/4 音符和 4 小节 1/8 音符以 120bpm 播放。 I am having some trouble coming up with the right combination of preprocessing and filtering to produce a video that looks like the image.我在想出预处理和过滤的正确组合以生成看起来像图像的视频时遇到了一些麻烦。 The colors dont have to be exact, I am more concerned with the shape of the beats.颜色不必精确,我更关心节拍的形状。 I tried a couple of different approaches using showwaves and showspectrum.我使用 showwaves 和 showspectrum 尝试了几种不同的方法。 I cant quite wrap my head around why when using showwaves the beats go past so quickly, but using showspectrum produces a video where I can see each individual beat.我无法完全理解为什么在使用 showwaves 时节拍过得如此之快,但使用 showspectrum 会生成一个视频,我可以在其中看到每个单独的节拍。

ShowWaves秀波

ffmpeg -i beat_test.mp3 -filter_complex "[0:a]showwaves=s=1280x100:mode=cline:rate=25:scale=sqrt,format=yuv420p[v]" -map "[v]" -map 0:a output_wav.mp4

This link will download the output of that command.链接将下载该命令的输出。

ShowSpectrum显示频谱

ffmpeg -i beat_test.mp3 -filter_complex "[0:a]showspectrum=s=1280x100:mode=combined:color=intensity:saturation=5:slide=1:scale=cbrt,format=yuv420p[v]" -map "[v]" -an -map 0:a output_spec.mp4

This link will download the output of that command.链接将下载该命令的输出。

I posted the simple examples because I didn't want to confuse the issue by adding all the variations I have tried.我发布了简单的示例,因为我不想通过添加我尝试过的所有变体来混淆问题。

In practice I suppose I can get away with the output from showspectrum but I'd like to understand where/how I am thinking about this incorrectly.在实践中,我想我可以摆脱 showspectrum 的输出,但我想了解我在哪里/如何错误地考虑这个问题。 Thanks for any advice.感谢您的任何建议。

Here is a link to the source audio file.这是源音频文件的链接

What showwaves does is show the waveform in realtime, and the display window is 1/framerate ie if the video output is 25 fps, then each frame shows the waveform of 40 ms of audio. showwaves做的是实时显示波形,显示窗口是1/framerate,即如果视频输出是25fps,那么每帧显示40ms音频的波形。 There's no 'history' or 'memory' so you can't (directly) get a scrolling output like it seems your reference video shows.没有“历史”或“记忆”,因此您无法(直接)获得滚动输出,就像您的参考视频节目一样。

The workaround for this is to use the showwavespic filter to produce a single frame showing the entire waveform at a high enough horizontal resolution.解决方法是使用showwavespic过滤器生成单帧,以足够高的水平分辨率显示整个波形。 Then do a scrolling overlay of that picture over a desired background, at a speed such that the scroll lasts as long as the audio.然后在所需背景上滚动覆盖该图片,滚动速度与音频持续时间一样长。

Basic command template would be:基本命令模板为:

ffmpeg -loop 1 -i bg.png -loop 1 -i wavespic.png -i audio.mp3
 -filter_complex "[0][1]overlay=W-w*t/mp3dur:y=SOMEFIXEDVALUE" -shortest waves.mp4

mp3dur above should be replaced with the duration of the audio file.上面的mp3dur应该替换为音频文件的持续时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM