How to Generate Audio Spectrum Videos from MP3 songs with FFmpeg

Sometimes I need a simple way to convert an MP3 file into a video suitable for YouTube. Instead of using a static image.

I created a small Bash script that generates an animated frequency spectrum using FFmpeg.

The script uses FFmpeg’s showfreqs filter to generate an animated frequency spectrum from the audio.

How to use the script?

Step 1 : Download the script from gist

wget -c https://gist.githubusercontent.com/mypapit/37817eab6988fe05b87c64025409a894/raw/c04a917e12e9b89e6784783d19061dc771dbed99/spectrum.sh


Step 2: make it executable chmod +x spectrum.sh

Step 3: Use the script – ./spectrum.sh song.mp3

Alternatively you can also convert/export multiple mp3 files : ./spectrum.sh *.mp3

Why Use This Script?

The main advantage is simplicity. There is no video editor, GUI application, or complicated workflow involved. FFmpeg handles the audio analysis, visualization, video encoding, and audio encoding in a single operation.

It is also easy to modify the showfreqs parameters if you want different spectrum sizes, positions, frame rates, scaling methods, or visual styles.

For batch processing MP3 files into simple spectrum videos, this small Bash script provides a practical solution.

Sample Videos

yt-dlp – a verstatile video downloader tool

yt-dlp is a command-line tool for which allows a user to download audio/video from thousands of sites. The project is a fork of youtube-dl, which is based on the now inactive youtube-dlc.

yt-dlp can be installed using official releases or via package manager.

Unix-like operating system

curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o ~/.local/bin/yt-dlp
chmod a+rx ~/.local/bin/yt-dlp  # Make executable

To update yt-dlp in Unix-like operating system

yt-dlp -U

Homebrew MacOS

brew install yt-dlp

Ubuntu

sudo add-apt-repository ppa:tomtomtom/yt-dlp # Add ppa repo to apt
sudo apt update # Update package list
sudo apt install yt-dlp # Install yt-dlp

Snap

sudo snap install --edge yt-dlp

Windows operating system

yt-dlp is also available for Windows operating system by using, winget:

winget install yt-dlp

Microsoft Windows binary package

The binary package for Microsoft Windows binary package can be downloaded from yt-dlp GitHub release page

Note that yt-dlp requires ffmpeg windows binaries which can be obtained from gyan.dev’s Codex FFMPEG Build

Please refer to this post for more information on the tips and tricks on using yt-dlp.

How to extract Audio from Youtube Flash Video (FLV) in Ubuntu Linux

First you need youtube-dl tool or ‘cclive’ to download the Youtube .FLV file.

Then, download the Youtube stream.
python youtube-dl http://www.youtube.com/watch?v=lee7a55401e

Alternatively, you can use ‘cclive’ to download the youtube stream.
cclive http://www.youtube.com/watch?v=lee7a55401e

After that, use ffmpeg to extract the audio and encode it to MP3
ffmpeg -i lee7a55401e.flv vn -acodec libmp3lame -ab 128000 -ar 44100 lee7a55401e.mp3

Note: You need to install the restricted codecs in order to extract MP3 audio files.

Thanks Mohammad Bahathir Hashim for the tip!

FFMpeg based FLV to 3gp batch converter scripts

A friend from #fakap asks me to create a dead simple FLV to 3gp batch converter for him to port youtube clips to mobile phone.

As a result I complied, and created flvto3gp bash script for the job.

Usage
Using it is simple, just run this script inside a directory full of FLV (or any video files supported by ffmpeg) and execute it using this command :

sh flvto3gp.sh *

The script will convert all video files to 3gp file format one by one. The script requires
ffmpeg in order to run.

Ubuntu users might have to refer to this post before using this utility : Enable mp3 and amr support in ffmpeg ( Ubuntu )

[tags]ubuntu,flv,linux,ffmpeg,open source[/tags]