Most posts under miscellaneous are for personal purposes. But if you find this useful, that’s great!
Here are a few helpful and frequently used FFMPEG commands.
Trim video
ffmpeg -ss [HH:]MM:SS[.ms] -t [HH:]MM:SS[.ms] -i input_file.mp4 -c copy output_file.mp4
Convert video to GIF
ffmpeg -i input_file.mp4 -filter_complex "[0:v] fps=5,scale=300:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" output_file.gif
Convert image sequence to GIF
ffmpeg -f image2 -framerate X -i images_%d.png output.gif
If needed, a filter for palette can also be added as in above example
Convert image sequence to MP4 (H264)
ffmpeg -r 60 -f image2 -i img_%04d.png -c:v libx264 -crf 21 -preset slow -pix_fmt yuv420p output.mp4
Input frames are read at 60 fps, and then encoded to H.264 codec with a constant rate factor of 21 (lower, the better), and a slow encoding preset. The pixel format is set to yuv420p, which is supported by most “dumb” players.
Convert MKV to MP4
ffmpeg -i input_file.mkv -c copy output_file.mp4
Compress MP4 (H264)
ffmpeg -i input_file.mp4 -c:v libx264 -crf XX -preset slow -c:a copy output_file.mp4
XX = 0-51, lower number is higher quality: 0 is lossless and 51 is worst quality. 17–28 is considered sane range.
Change video speed
Note, sacrifices audio.
Example double speed:
ffmpeg -t 00:13 -i input_file.mp4 -an -filter:v "setpts=0.5*PTS" output_file.mp4
Reuse
https://creativecommons.org/publicdomain/zero/1.0/