Skip to content

Instantly share code, notes, and snippets.

@magnusbae
Last active May 23, 2022 07:50
Show Gist options
  • Save magnusbae/ee44456bb90b4b601837c82c773f1410 to your computer and use it in GitHub Desktop.
Save magnusbae/ee44456bb90b4b601837c82c773f1410 to your computer and use it in GitHub Desktop.
FFmpeg goodies - useful FFmpeg commands with examples

Various useful FF-MPEG commands

Export keyframes from video at intervals

Seconds: time for i in {0..42} ; do ffmpeg -accurate_seek -ss `echo $i.0 | bc` -i input.mp4 -frames:v 1 period_down_$i.jpg ; done

Minutes: time for i in {0..42} ; do ffmpeg -accurate_seek -ss `echo $i*60.0 | bc` -i input.mp4 -frames:v 1 period_down_$i.jpg ; done

Compress video to smallest size possible ffmpeg -i input.mp4 -c:v libx264 -preset veryslow -qp 25 compressed output.mp4

The range of the CRF scale is 0–51, where 0 is lossless (for 8 bit only, for 10 bit use -qp 0), 23 is the default, and 51 is worst quality possible. A lower value generally leads to higher quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be visually lossless or nearly so; it should look the same or nearly the same as the input but it isn't technically lossless. The range is exponential, so increasing the CRF value +6 results in roughly half the bitrate / file size, while -6 leads to roughly twice the bitrate. Choose the highest CRF value that still provides an acceptable quality. If the output looks good, then try a higher value. If it looks bad, choose a lower value.

https://trac.ffmpeg.org/wiki/Encode/H.264

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment