Owlclip
Home Cheatsheets Blog

Compressing Video for Sharing with FFmpeg

ffmpeg -i input.mp4 -vf "scale=1280:-1" -c:v libx264 -preset slow -crf 24 -c:a aac -b:a 128k compressed.mp4

Parameter Explanation

Parameter Description
-i input.mp4 Specifies the input file
-vf "scale=1280:-1" Video filter to scale width to 1280px while maintaining aspect ratio
-c:v libx264 Sets the video codec to H.264
-preset slow Sets encoding preset (slower = better compression)
-crf 24 Sets quality (higher value = lower quality, smaller file)
-c:a aac Sets audio codec to AAC
-b:a 128k Sets audio bitrate to 128 kbps

Practical Examples

Example 1: Heavy compression for email

ffmpeg -i input.mp4 -vf "scale=640:-1" -c:v libx264 -preset veryslow -crf 28 -c:a aac -b:a 96k email_compressed.mp4

Creates a highly compressed version suitable for email attachments with reduced resolution.

Example 2: Compress for Discord (8MB limit)

ffmpeg -i input.mp4 -vf "scale='min(1280,iw)':-1" -c:v libx264 -preset medium -crf 26 -c:a aac -b:a 96k -fs 8M discord.mp4

Uses the -fs option to limit file size to 8MB maximum for Discord uploads.

Example 3: Compress with reduced framerate

ffmpeg -i input.mp4 -vf "scale=1280:-1,fps=24" -c:v libx264 -preset slow -crf 24 -c:a aac -b:a 128k framerate_reduced.mp4

Reduces framerate to 24fps alongside other compression techniques for smaller file size.