ffmpeg: audio visualization tricks

Often one wants to share audio online, but it seems like video as a format has many more options: mastodon, twitter, facebook, youtube, all allow to upload video, but not only audio. Here are some ffmpeg tricks, how to add interesting video to your audio file, often autogenerated visuals. All the code is supposed to be used as one line without line-breaks.


Audio Vector Scope

The code above creates a mp4 video file with a vectorscope nicely centered inside a 854×480 (480p) video. If you need a 1:1 video, just exclude the pad part:

Documentation on ‘avectorscope’ filter is here: https://ffmpeg.org/ffmpeg-filters.html#avectorscope. One can play with zoom and other options to produce desired form.


Show waves

more options: http://www.ffmpeg.org/ffmpeg-filters.html#showwaves


Above code will create almost completely desaturated spectrum of the audio sliding from right to left. Again, there are various options to tweak, see here: https://ffmpeg.org/ffmpeg-filters.html#showspectrum-1



Documentation: https://ffmpeg.org/ffmpeg-filters.html#ahistogram


Static spectrogram

Sometimes you want to just create a static image.

Above one is in two steps. More info here: http://www.ffmpeg.org/ffmpeg-filters.html#showspectrumpic



Add text to any of the above with a “drawtext” filter. More options here: http://www.ffmpeg.org/ffmpeg-filters.html#drawtext-1

jpeg-LS glitching with FFmpeg

In an older version of FFmpeg it was possible to glitch the image with JPEG-LS codec. Newer versions of FFmpeg don’t work anymore in this way, so one must download an old version and compile it (keep it local) – here 2.0.7 is used.

This script takes a video file as an argument, extracts frames, glitches them, and gathers frames back into a video file.



timelapse aka speeding up with ffmpeg

These days I’m recording my work in the studio using a timelapse function in my Panasonic TM700 HD camera. So it happened that I forgot to turn on the the function (needs to be turned on everytime you start recording) which usually records one frame every 10 seconds, so I ended up with a “normal” recording and wanted to convert that to what camera usually does. Ffmpeg to the rescue! To do some frame manipulation a video filter “setpts” is what one needs. Gathering knowledge online with help of two pages:

https://trac.ffmpeg.org/wiki/How to speed up / slow down a video

So, supposedly, the right way to change video speed using ffmpeg is by adjusting the “presentation time stamp” (PTS). This adjusts frames’ metadata related to how long each is displayed—exactly what you want.

this is the crucial piece of code that needs to be passed to ffmpeg:

-filter:v "setpts=2.0*PTS"

Or a more practical example using fraction – if original framerate is 25 frames per second I only need evert 250th one:

$ ffmpeg -i INPUTFILE.mkv -filter:v "setpts=(1/250)*PTS" OUTPUTFILE.mkv

My final conversion was from full-HD .mts to 720p .webm and to mp4:

$ ffmpeg -i INPUT.mts -filter:v "setpts=(1/250)*PTS" -s 1280x720 -c:v libvpx -crf 5 -b:v 8M -an OUTPUT.webm
$ ffmpeg -i INPUT.mts -filter:v "setpts=(1/250)*PTS" -s 1280x720 -c:v libx264 -preset slow -crf 10 -an OUTPUT.mp4

Prepare audio for YouTube with avconv

How to create a video file from a single image and audio track using avconv:

Thanks to a question/recipe from SuperUser: