Tube Site Script
Content and encoding

Video encoding settings for the web: H.264 qualities, CRF, presets and audio

Web video encoding settings that play everywhere: H.264 MP4, resolutions from 480p to 4K, CRF and bitrate caps, presets, faststart and AAC audio.

Updated 4 minute read The Tube Site Script team

For web video, encode to H.264 (libx264) in an MP4 container with AAC audio, the yuv420p pixel format and the faststart flag, at a few resolutions such as 480p, 720p and 1080p. Use constant quality (CRF around 20 to 24) with a sensible bitrate cap, and the medium or fast preset unless you have CPU to spare. These settings play in every modern browser and phone and give a good balance of quality, file size and encoding time.

Why H.264 MP4 is still the default

Newer codecs such as H.265, VP9 and AV1 compress better, but support varies by browser and device, and they take far longer to encode. H.264 in MP4 plays everywhere, including older phones and smart TVs, and decodes in hardware on almost every device, which saves battery. For a tube site, where you want every visitor to press play and see video immediately, it remains the safe choice.

Choosing qualities and resolutions

Offer a small ladder of qualities so viewers on slow connections are not stuck buffering and viewers on fast ones get a sharp picture. Never upscale: if the source is 720p, do not create a 1080p version.

QualityResolution (16:9)Typical video bitrateUse
360p640 × 3600.6 to 0.9 MbpsVery slow mobile connections
480p854 × 4801 to 1.5 MbpsDefault for mobile data
720p1280 × 7202.5 to 4 MbpsGood general default
1080p1920 × 10804.5 to 7 MbpsDesktop and large screens
2160p (4K)3840 × 216015 to 25 MbpsOnly for high-quality 4K sources

Most sites do well with 480p, 720p and 1080p. Every extra quality adds encoding time and storage, so add 360p or 4K only if your audience needs them. When scaling, set the height and let ffmpeg calculate an even width that keeps the aspect ratio, with -vf scale=-2:720.

CRF: constant quality

CRF (constant rate factor) tells libx264 to aim for a consistent visual quality and use as many bits as each scene needs. Lower numbers mean higher quality and bigger files. A change of 6 roughly doubles or halves the file size.

  • 18 to 20: very high quality, large files.
  • 21 to 23: a good default for most content.
  • 24 to 26: smaller files, visible softening in detailed scenes.

Pure CRF can produce large spikes on fast motion. For streaming, cap the peak bitrate so files stay playable on modest connections:

-crf 22 -maxrate 4M -bufsize 8M

Presets: speed versus size

The preset controls how hard the encoder works. Slower presets give smaller files at the same quality but take much longer. veryfast can be several times quicker than medium with files perhaps 10 to 20 percent larger. medium is the standard balance; slow is worth it only if storage and bandwidth cost more to you than CPU time. If your encoding queue is always backed up, a faster preset is often the cheapest fix.

Compatibility settings

  • -pix_fmt yuv420p: some sources use 4:2:2 or 4:4:4 colour, which many browsers and phones cannot play.
  • -profile:v high: supported by every current device. Use main only if you must support very old hardware.
  • -movflags +faststart: moves the index (the "moov atom") to the start of the file, so playback can begin before the whole file downloads. Without it, some players wait or seeking fails.
  • Keep the source frame rate, but consider capping very high frame rates at 30 or 60.

Audio

Use AAC at 128 kbps stereo for most content, or 96 kbps for lower qualities. Mix multichannel audio down to stereo with -ac 2, because few web viewers use surround sound. If a source has no audio track, do not add a silent one unless your player needs it.

A complete example

A 720p version from any source:

ffmpeg -i input.mov -vf scale=-2:720 -c:v libx264 -preset medium -crf 22 -maxrate 4M -bufsize 8M -profile:v high -pix_fmt yuv420p -c:a aac -b:a 128k -ac 2 -movflags +faststart output-720.mp4

Repeat with the scale and bitrate cap changed for each quality. If you have not installed the encoder yet, see installing ffmpeg for a video site.

Checking results

Play each output on a desktop browser and a phone, and seek to the middle to confirm faststart works. Run ffprobe on the file to check resolution, codec, pixel format and bitrate. Compare file sizes against your storage and bandwidth plan from the hosting requirements guide. Smaller, well-encoded files also help page speed, as covered in tube site speed and mobile.

How Tube Site Script handles encoding

Tube Site Script uses ffmpeg to encode every uploaded or imported file into H.264 MP4 at the qualities you choose in the admin, up to 4K. Encoding runs in a background worker started by cron, or as a permanent systemd service on busy networks, so uploads never wait on the page. The same pass creates 10 thumbnails, an animated hover preview and timeline thumbnails, and can burn in a watermark.

The Video.js player offers a quality switcher so viewers can pick the version that suits their connection, and you can serve the encoded files from a CDN or behind signed, expiring nginx links. Failed encodes can be retried with reprocess. See the Tube Site Script features and pricing.

Frequently asked questions

What CRF should I use for web video?

A CRF between 21 and 23 suits most content. Go lower for higher quality and bigger files, or higher if storage and bandwidth are tight.

Should I use H.265 or AV1 instead of H.264?

They compress better but are slower to encode and not supported everywhere. H.264 remains the safest choice when every visitor must be able to play the video.

What does faststart do?

It moves the MP4 index to the start of the file, so browsers can begin playing and seeking before the whole file has downloaded.

Get three guides like this every month, plus software update notices.Subscribe →