ffmpeg cheatsheet
I use cheatsheets to remember commands I use frequently.
Batch convert:
$ for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; doneConvert formats:
$ ffmpeg -i input.mkv output.mp4Extract audio:
$ ffmpeg -i input.mp4 -vn audio_only.m4aRemove audio:
$ ffmpeg -i input.mp4 -c copy -an input-nosound.mp4Be quiet:
$ ffmpeg -hide_banner -loglevel warningFire and forget (redirect stdin):
$ nohup ffmpeg ... </dev/null &Find the size:
$ ffprobe -v error -show_entries stream=width,height \
-select_streams v:0 -of json input.mp4 \
| jq '.streams[0]|.width,.height' | paste - -Change size:
$ ffmpeg -i input.mp4 -s 1280x720 -c:a copy resized.mp4Add postal image to audio:
$ ffmpeg -loop 1 -i inputimage.jpg -i inputaudio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4Join video files:
$ ffmpeg -f concat -i join.txt -c copy output.mp4Extract a portion:
$ ffmpeg -ss 00:00:05 -i input.mp4 -t 00:00:03 -c:v copy -c:a copy excerpt.mp4Trim a video:
$ ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4Burn subtitles:
$ ffmpeg -i sub.srt sub.ass
$ ffmpeg -i in.mp4 -vf ass=sub.ass out.mp4Rotate a video:
$ ffmpeg -i in.mov -vf "transpose=1" out.mov
0 = 90 CounterCLockwise and Vertical Flip (default)
1 = 90 Clockwise
2 = 90 CounterClockwise
3 = 90 Clockwise and Vertical FlipDownload transport stream:
$ ffmpeg -protocol_whitelist "file,http,https,tcp,tls" -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4Also: