Skip to content

Instantly share code, notes, and snippets.

@dmertl
Last active February 1, 2025 21:33
Show Gist options
  • Save dmertl/8504eb826c10d68d573ae59c0f7979f2 to your computer and use it in GitHub Desktop.
Save dmertl/8504eb826c10d68d573ae59c0f7979f2 to your computer and use it in GitHub Desktop.
FFmpeg Cheatsheet

15 second clip

ffmpeg -i in.mp4 -t 00:00:15 in_15s.mp4

clip to exact frames

ffmpeg.exe -i in.mp4 -vf "select=between(n\,100\,395),setpts=PTS-STARTPTS" -an out.mp4

resize 640 width, keep aspect ratio

ffmpeg -i in.mp4 -vf "scale=640:-1" in_640w.mp4

convert to mp4

ffmpeg -i in.avi -c:v libx264 in.mp4

convert to mp4 high quality

ffmpeg -i in.avi -c:v libx264 -crf 18 in_hq.mp4

create loop by playing video backwards at end

ffmpeg -i in.mp4 -filter_complex "[0]reverse[r];[0][r]concat=n=2:v=1:a=0" in_rev_loop.mp4

reverse video

ffmpeg -i in.mp4 -vf reverse in_rev.mp4

512x512 crop center

ffmpeg -i in.mp4 -vf "scale='if(lte(iw,ih),512,-1)':'if(lte(ih,iw),512,-1)',crop=512:512" in_512w_512h.mp4

video to image sequence

ffmpeg.exe -i in.mp4 "out_%d.png"

convert to mp3

ffmpeg -i in.wav -n -codec:a libmp3lame -q:a 1 in.mp3

remove audio

ffmpeg -i in.mp4 -c copy -an in_silent.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment