I often forget the commands to do conversion of video or audio files. While bigger conversion I would use Handbrake, more specific or surgical changes I would use the great ffmpeg tool.

Installing

Since I usually work on Linux Ubuntu, it is simply installed by

sudo apt install -y ffmpeg

Popular commands

Converting a video to animated gif

ffmpeg -i input.mp4 -vf "fps=20,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif

-vf: video format
fps: frame per second
scale:width:height (-1 for one of the two dimension to preserve ratio)
-loop: how many time to loop. 0 for forever loop.

Converting image stack to GIF

ffmpeg -pattern_type glob -r 1 -i '*.png' out.gif

-pattern_type glob: to select all matching images

-r 1: rate 1 image per second

-i: input images

Trim a video

ffmpeg -i input.mp4 -ss 00:02:30 -to 00:03:30 -c:v copy -c:a copy output.mp4

-ss: start from in hh:mm:ss format
-to: end of the video
-c:v / -c:a : video and audio conversion: no conversion (just copy)
Alternative:

ffmpeg -i input.mp4 -ss 00:02:30 -t 00:01:00 -c:v copy -c:a copy output.mp4


-t: duration

Removing sound from a video

ffmpeg -i input.mp4 -c copy -an output.mp4

Resizing a video

ffmpeg -i input.mp4 -vf scale=640:360 output.mp4
# or by ratio
ffmpeg -i input.mp4 -vf scale=w=iw/2:h=ih/2 output.mp4