Useful ffmpeg Tricks

Extract a piece of audio from a video (at 3m5s for 45s into high-quality mp3):

ffmpeg -i sample.avi -ss 00:03:05 -t 00:00:45.0 -q:a 0 -map a sample.mp3

Convert a video to an animated GIF (see here for more information on GIF palettes):

# Generate palette.
ffmpeg -i video.mov -vf "fps=15,scale=320:-1:flags=lanczos,palettegen" -y palette.png
# Convert video to GIF using palette.
ffmpeg -i video.mov -pix_fmt rgb24 -i palette.png -lavfi "fps=8,scale=640:-1:flags=lanczos [x]; [x][1:v] paletteuse" -f gif -y video.gif

Crop an MP3 at 20 seconds in for a duration of 30 seconds:

ffmpeg -ss 20 -t 30 -i input.mp3 -acodec copy output.mp3