Owlclip
Home Cheatsheets Blog

Creating Web-Ready Video with FFmpeg

ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 22 -c:a aac -b:a 128k -movflags +faststart output.mp4

This command uses FFmpeg to convert a video file into a reasonably high-quality H.264 video with AAC audio that's optimized for web streaming.

Parameter Explanation

Parameter Description
-i input.mp4 Specifies the input file
-c:v libx264 Sets the video codec to H.264 (most compatible web format)
-preset medium Sets the encoding speed/compression ratio (options: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow)
-crf 22 Sets the Constant Rate Factor for quality (0-51, lower is better quality, 18-28 is usually good)
-c:a aac Sets the audio codec to AAC (widely supported)
-b:a 128k Sets the audio bitrate to 128 kbps
-movflags +faststart Moves metadata to start of file for faster web loading

Practical Examples

Example 1: Convert a video for YouTube upload

ffmpeg -i source_video.mp4 -c:v libx264 -preset medium -crf 20 -c:a aac -b:a 192k -movflags +faststart youtube_ready.mp4

This uses a slightly higher quality setting (CRF 20) and better audio quality (192k) suitable for YouTube.

Example 2: Convert to web-ready video with scaled resolution

ffmpeg -i input.mp4 -vf "scale=1280:-1" -c:v libx264 -preset medium -crf 22 -c:a aac -b:a 128k -movflags +faststart 720p_web.mp4

Scales the video to 720p width (1280 pixels) while maintaining the aspect ratio.

Example 3: Convert to web-ready with 2-pass encoding for best quality/size

ffmpeg -i input.mp4 -c:v libx264 -preset medium -b:v 1500k -pass 1 -an -f mp4 /dev/null && \
ffmpeg -i input.mp4 -c:v libx264 -preset medium -b:v 1500k -pass 2 -c:a aac -b:a 128k -movflags +faststart output.mp4

Uses 2-pass encoding for a target bitrate of 1500 kbps, providing more consistent quality.