These are the basics of the video processing tool “ffmpeg”.

  • Encode a video (using x264 codec) quickly.
    ffmpeg -i input.mp4 -c:v libx264 -preset veryfast -crf 22 output.mp4
    • -preset has several possible values, faster encoding means less CPU load and less compression.
    • -crf stands for “Constant Rate Factor” and this is the recommended rate control mode for most uses. A lower value generally leads to higher quality, and a subjectively sane range is 17–28 (23 is the default).
  • Overwrite output file if exists.
    ffmpeg -y -i input.mp4 output.mp4
  • Extract audio from video.
    ffmpeg -i video.mp4 -vn sound.mp3
  • Cut a video from mm:ss to mm2:ss2 (without re-encoding)
    ffmpeg -ss mm:ss -to mm2:ss2 -i video.mp4 -codec copy output.mp4
  • Capture a video frame (at mm:ss) and change its resolution
    ffmpeg -ss mm:ss -i video.mp4 -frames 1 -s 1280x720 -f image2 image.png
  • Capture one frame per second of the video
    ffmpeg -i video.mp4 -r 1 -f image2 image%d.png
  • Capture a frame from a video device (webcam, etc.)
    ffmpeg -i /dev/video0 -frames 1 -f image2 image.png
Test with this online terminal: