FFMPEG Snippet Collection

Published by Tim on Saturday November 21, 2020

Last modified on January 25th, 2024 at 14:07

FFMPEG is a very small and handy tool for converting and editing media from the command-line. Not only is it ideal for converting to a wide variety of formats, it can also merge image data into video, crop, add filters and even export gif files.

For my own work I can’t imagine my work without this tool. However, the obstacles for getting started are relatively high, because the installation is more or less difficult depending on the operating system. Furthermore, you work with FFMPEG in the command line, which is a daunting task for some people.

I find the technology so helpful because I have to formulate every action with code so that I can reuse it at any time. That saves a lot of work at some point.

In this article I collect FFMPEG snippets that I find especially useful for my work as a designer and creative coder.

Cut video

ffmpeg -ss 00:00:30.0 -i input.wmv -c copy -t 00:00:10.0 output.wmv

Convert one video-format to another

ffmpeg -i in.mov out.mp4

Cut the first 30 seconds of a video

ffmpeg -ss 00:00:30.0 -i input.wmv -c copy -t 00:00:10.0 output.wmv

Merge Audio and Video

ffmpeg -i in.mp4 -i in.wav -c:v copy -c:a aac -shortest output.mp4

Compress Audio

ffmpeg -i input.mp4 -filter_complex "compand=attacks=0:points=-80/-900|-45/-15|-27/-9|-5/-5|20/20" output.mp4

Create images from video

ffmpeg -i input.mp4 -vf fps=1/1 ./thumbs/video%03d.jpg

Concatenate Videos

ffmpeg -i ./input1.mp4 \
	   -i ./input2.mp4 \
       -filter_complex "[0:v] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [v] [a]" \
       -map "[v]" -map "[a]" ./output.mp4

Add padding / white letterbox

ffmpeg -i input.mp4 -vf "pad=width=900:height=900:x=157:y=45:color=white" output.mp4

Scale video while keeping the aspect ratio

ffmpeg -i in.mp4 -vf scale=720:-2 out.mp4

Convert video to gif

ffmpeg -i input.mp4 -f gif output.gif

ffmpeg -i input.mp4 -filter_complex "[0:v] palettegen" palette.png

ffmpeg -i input.mp4 -i palette.png -filter_complex "[0:v][1:v] paletteuse" output.gif

ffmpeg -i input.mp4 -filter_complex "[0:v] fps=15,scale=500:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" output.gif

Desaturate Video

ffmpeg -i input -vf hue=s=0 output

Create a video from a folder of images

ffmpeg -r 30 -i ./%09d.png output.mp4

Reset dimensions

ffmpeg -i in.mp4 -vf scale=800:600,setsar=1:1 out.mp4

Generate a video from an image and a sound-file

ffmpeg -loop 1 -i in.jpg -i in.mp3 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest out.mp4

Compressing / Scaling video

ffmpeg -i for.mp4 -vf scale=-1:720 -c:v libx264 -crf 40 -preset veryslow -c:a copy for_opt.mp4

Related

A custom Mockup Tool, built with Processing (updated)

For my students at Elisava, I have created a new version of my mockup-tool. You need two different files for […]

Marcus Aurelius Meditations

Since the beginning of the Corona crisis, I have been more and more interested in the history of ancient philosophy. […]

Form follows Music: The Bach-Project

Generative visuals made from the "Prelude in C" by Johann Sebastian Bach.

Discoveries in the Public Domain

The internet holds incredible treasures of media, free to use for anyone. This short video-essay gives you insights into the […]