Interesting ffmpeg commands and scripts

January 30, 2020 written by @phlhar

I had serveral occasions, where I wanted something weird done in ffmpeg. The following ffmpeg commands and scripts are things I tried out, experimented with and also used. I might add onto the list in the future, as I stumble upon other interesting tasks done with ffmpeg.

The first script is to use ffmpeg as an audio dsp with multiband equalizer in MacOS. You could add other audio filters if you want, though that might increase the latency which is already quite high. For me the input is the built in microphone, though you can adjust that accordingly. I wrote the script to make it easier to configure the equalizer.


# range is from 0 to 20
# 1b: Set 65Hz band gain.
# 2b: Set 92Hz band gain.
# 3b: Set 131Hz band gain.
# 4b: Set 185Hz band gain.
# 5b: Set 262Hz band gain.
# 6b: Set 370Hz band gain.
# 7b: Set 523Hz band gain.
# 8b: Set 740Hz band gain.
# 9b: Set 1047Hz band gain.
# 10b: Set 1480Hz band gain.
# 11b: Set 2093Hz band gain.
# 12b: Set 2960Hz band gain.
# 13b: Set 4186Hz band gain.
# 14b: Set 5920Hz band gain.
# 15b: Set 8372Hz band gain.
# 16b: Set 11840Hz band gain.
# 17b: Set 16744Hz band gain.
# 18b: Set 20000Hz band gain.

ffmpeg -f avfoundation -i ":0" -filter_complex superequalizer=1b=$f1b:2b=$f2b:3b=$f3b:4b=$f4b:5b=$f5b:6b=$f6b:7b=$f7b:8b=$f7b:9b=$f9b:10b=$f10b:11b=$f11b:12b=$f12b:13b=$f13b:14b=$f14b:15b=$f15b:16b=$f16b:17b=$f17b:18b=$f18b -f f32le - | ffplay -f f32le -ar 44.1k -ac 2 -

The next command merges several .mp3 files into one file.

cat *.mp3 | ffmpeg -i pipe:0 -acodec libmp3lame -map_metadata -1 "output.mp3"

It is possible to just do cat *.mp3 > output.mp3. This should work in most players, but the problem is that between the encoded audio data are the headers of the mp3 files. By reencoding the audio with ffmpeg, the length of the audio and the metadata are stored at the beginning of the mp3 file as it should be. I use -map_metadata -1 to remove any metadata of the mp3 files. Otherwise ffmpeg would copy the ID3 tags and other metadata of the first file to output.mp3.

I got one more command. This one is to make the video of a usb webcam or built in camera available on the network. It takes /dev/video0 as an input, and opens a tcp server on the specified IP address and port. You can access it by ffplay tcp://ip:port for example, but you can also use it as a OBS source or access it with vlc. By using -c:v copy the video is not reencoded, and thus this command has very little cpu consumption and there is less delay. This command is linux only, as it uses the video4linux2 input device.

ffmpeg -f v4l2 -framerate 30 -video_size 1920x1080 -vcodec h264 -i /dev/video0 -c:v copy -f h264 tcp://ip:port?listen