For web embedding, compatibility and start-up speed (faststart, fallbacks) drive the decisions; for messenger sharing, the size limit does. For limit-driven jobs, calculate the bitrate first and accept that quality depends on how hard the video is.
For video played directly on your own site, the key constraint is that you can't control who is watching. So take the most widely playable combination as the base, and add efficient codecs on top of it as an option.
yuv420p. It is widely used as the most conservative choice for compatibility.ffmpeg -i input.mov \
-c:v libx264 -preset medium -crf 23 -pix_fmt yuv420p \
-c:a aac -movflags +faststart web.mp4<video controls playsinline preload="metadata" width="960">
<source src="clip-av1.mp4" type='video/mp4; codecs="av01.0.08M.08"'>
<source src="clip-h264.mp4" type='video/mp4; codecs="avc1.640028"'>
</video>The codecs values inside type are examples. If they don't match the file's actual profile, level, and bit depth, the browser may misjudge the source. Before you deploy, check with the codec support checker or by playing the file in several browsers. You can see the file's actual codec and resolution in the video file info inspector.
A video to send in a messenger usually has a 'no more than X MB' limit. Limits change by service and over time, so this site does not state any particular service's number. The mere fact that there is a limit settles the recipe: rate control is a fixed bitrate (2-pass), and you leave the calculation to a calculator.
If calculating by hand is a hassle, enter the duration and target size into the video size and bitrate calculator. That tool also shows which VMAF that bitrate reached in the measured data. You can continue building the command in the FFmpeg command builder.
ffmpeg -y -i input.mp4 -c:v libx264 -preset medium -b:v 2400k -pass 1 -an -f null /dev/null
ffmpeg -i input.mp4 -c:v libx264 -preset medium -b:v 2400k -pass 2 -c:a aac -b:a 128k -movflags +faststart share.mp4Fixing the size leaves the quality open. In this site's measurements, even at the same size the results can diverge widely. In crf-sweep, the 1080p25 10 s video at x264 medium CRF 28 was 2,490 kbps for blue_sky and 11,623 kbps for riverbed. If you set 2,400 kbps as above, blue_sky is close to the bitrate CRF 28 used (2,490 kbps), but riverbed gets only about 21% of the bitrate CRF 28 used (2,400 ÷ 11,623). It means that at 1080p, a video like riverbed can lose a lot of quality (the exact VMAF can't be known from this calculation), and the ways to handle that are as follows.
In most cases you don't know whether the recipient will watch on a phone or a PC, or which codecs their app plays. The default for sharing is the conservative combination of H.264 + AAC + MP4 + yuv420p, and when the size runs short, cutting resolution and duration first carries less risk than changing the codec.
A setup where several <source> elements are listed in order inside <video>, so a browser that can't play the earlier codec uses the next source.
A setting that puts the MP4's moov at the front of the file so playback can begin during the download (-movflags +faststart).
A string like avc1.640028 written in a type attribute or in HLS CODECS. It carries the codec and values such as profile and level, so the browser can judge in advance whether it can play the file. The tool 'Codec String Decoder' shows how to read one.
The codecs-string prefix for H.264. In avc1.640028, the six characters after the dot are split into pairs: profile 0x64 (High), constraint flags 00, and level 0x28 (= 40, i.e. 4.0).
The codecs-string prefix for HEVC. hvc1.1.6.L123.B0 reads as profile 1 (Main), tier L (Main tier), and level 123 ÷ 30 = 4.1. The two prefixes differ in whether the parameter sets sit in the file header or may also appear inside the samples.
The codecs-string prefix for AV1. av01.0.08M.08 reads as profile 0 (Main), level number 08 (= 4.0), tier M, and 8-bit.
A further split inside each HEVC or AV1 level, with Main and High variants. In a codecs string HEVC writes it as L or H, and AV1 as M or H.
A method that asks a browser's media element whether it can play a given format. It returns only "probably", "maybe", or an empty string, and an empty string means it cannot play it.
A browser API where you pass a codec, resolution, fps and bitrate and get back whether it is supported, smooth, and power efficient. A power-efficient 'yes' is usually a sign that a hardware decoder handles it.
To fit a 30-second video into 10 MB (= 80,000,000 bit), what is the approximate upper limit of the overall (video + audio) average bitrate?
Why use -movflags +faststart on an MP4 for web embedding?