Sunday, January 21, 2024

FFmpeg Quick Reference

FFmpeg is a powerful command-line editing tool, but sometimes it can be hard to track down how to perform certain operations. The list below is a quick command reference for common tasks:

Convert video to MP4

ffmpeg -i $INPUT_PATH -vcodec h264 -acodec mp2 $OUTPUT_PATH

Crop video

ffmpeg -i $INPUT_PATH -filter:v "crop=$WIDTH:$HEIGHT:$X:$Y" $OUTPUT_PATH

Remove audio

ffmpeg -i $INPUT_PATH -c copy -an $OUTPUT_PATH

Cut video

ffmpeg -i $INPUT_PATH -ss $START_TIMESTAMP -t $DURATION -c:v libx264 $OUTPUT_PATH

Where $START_TIMESTAMP and $DURATION are strings in the hh:mm:ss.s format.

Scale video proportionally by width

ffmpeg -i $INPUT_PATH -filter:v scale=$WIDTH:-1 -c:a copy $OUTPUT_PATH

Where $WIDTH is the output video width.

Scale video proportionally to 1080p, add black bands as appropriate to fill dimensions

ffmpeg -i $INPUT_PATH \
  "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1" \
  -c:a copy $OUTPUT_PATH

Scale video proportionally to 800 pixels width, set 15 FPS and average bit rate of 2 Mb

ffmpeg -i $INPUT_PATH -b:v 2M -maxrate 2M -bufsize 1M -vf "fps=15,scale=800:-1" $OUTPUT_PATH

No comments:

Post a Comment