Skip to content

Instantly share code, notes, and snippets.

@fraguada
Created September 22, 2021 18:26
Show Gist options
  • Save fraguada/3018b9db41b91e083046bf79b8c959b0 to your computer and use it in GitHub Desktop.
Save fraguada/3018b9db41b91e083046bf79b8c959b0 to your computer and use it in GitHub Desktop.
ffmpeg cheat sheet
.png sequence to mp4
ffmpeg -r 30 -i Frame_%05d.png -pix_fmt yuv420p out.mp4
-intra flag useful for seekable mp4, but higher file size
concatenate mp4s
https://stackoverflow.com/questions/7333232/how-to-concatenate-two-mp4-files-using-ffmpeg
:: Create File List
echo file file1.mp4 > mylist.txt
echo file file2.mp4 >> mylist.txt
echo file file3.mp4 >> mylist.txt
:: Concatenate Files
ffmpeg -f concat -i mylist.txt -c copy output.mp4
crop
ffmpeg -i in.mp4 -filter:v "crop=out_w:out_h:x:y" out.mp4
#800x80
ffmpeg -i output960x540.mp4 -filter:v "crop=in_w-160:in_h-460" -c:a copy out800x80_2.gif
trim length
https://stackoverflow.com/questions/18444194/cutting-the-videos-based-on-start-and-end-time-using-ffmpeg
ffmpeg -ss 00:00:00 -i in.mp4 -to 00:00:09 -c copy out.mp4
scale
ffmpeg -i out.mp4 -vf scale="3840:2160" output.mp4
reduce size/compress
https://unix.stackexchange.com/questions/28803/how-can-i-reduce-a-videos-size-with-ffmpeg
ffmpeg -i input.mp4 -vcodec libx264 -crf 20 output.mp4
https://superuser.com/questions/933264/getting-the-smallest-video-with-same-quality-how-to-with-ffmpeg
ffmpeg -i input.avi -c:v libx264 -crf 18 -preset veryslow -c:a copy out.mp4
add audio to video
https://stackoverflow.com/questions/11779490/how-to-add-a-new-audio-not-mixing-into-a-video-using-ffmpeg
ffmpeg -i out.mp4 -i sin.wav -map 0:v -map 1:a -c:v copy -shortest output.mp4
add metadata to video
https://wiki.multimedia.cx/index.php/FFmpeg_Metadata
ffmpeg -i output.mp4 -metadata title="My title" -metadata year="2021" -metadata author="Luis E. Fraguada" -metadata copyright="© 2021 Luis E. Fraguada. All rights reserved." -metadata description="Some description" -c:v copy output_md.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment