ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 22 -c:a aac -b:a 128k -movflags +faststart output.mp4
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 |
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.
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.
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.