Generate a spectrogram-scrolling video of an audio file

 

This demo,

was created using this script:


# This is a simplified script of https://gist.github.com/keunwoochoi/f0ea2c49355fc21e93dad88d210efcdd
# Usage: 1. Modify the font path in the line with [ss].
# In my case, I copied and pasted CircularSpAraTTBlack.ttf to the same folder.
# 2. Put the wav file in the same folder, say, audio_file.wav
# 3. run $./spectrogram_scrolling_video.sh audio_file.wav
# 4. You'll see audio_file.mkv in the same folder!
#
# Based on example here https://trac.ffmpeg.org/wiki/Encode/YouTube
text=$(basename $1 .wav)
ffmpeg -i $1 -filter_complex \
"[0:a]showspectrum=mode=combined:color=intensity:scale=log:s=1280×720,pad=1280:720[ss]; \
[ss]drawtext=fontfile=CircularSpAraTTBlack.ttf:fontcolor=white:x=10:y=10:text=$text[out]" \
-map "[out]" -map 0:a -c:v libx264 -preset fast -crf 18 -c:a copy $text.mkv

To add a bit more explanation to this intuitive 🙄 ffmpeg command,

  • Line 11
    • [0:a]means the audio stream of the input would go through the following script
    • showspectrum is a filter of ffmpeg. Documentation is here
    • The result of showspectrum is streamed to [ss]
  • Line 12
    • [ss] is applied with drawtext filter.
    • fontfile=$FONTPATH is the argument. In my case, the font was in the same folder of the script.
    • The x, y positions originate from the top left.

 

Leave a Comment