Back to Glossary
Video

Video Compression

What Is Video Compression?

Video compression makes a video smaller by storing a full picture only now and then and, for the frames in between, only what changed, then rounding off detail that viewers are unlikely to miss. A codec does the work: its encoder compresses the video, and the decoder in a player or browser rebuilds each frame for playback.

Uncompressed, 1080p video at 30 frames per second runs to about 746 Mbps in 8-bit 4:2:0 color, while CE.SDK’s Auto setting exports it at a bitrate of 8 Mbps, about 1% of that. The diagram shows six frames from one of our test exports, where the keyframe takes 210 KB and each frame after it a fraction of that.

How Do You Calculate Video File Size?

Take the bitrate in Mbps, multiply it by the length in seconds and divide by 8 to get megabytes, then add the audio, which at 128 kbps, CE.SDK’s default, comes to about 1 MB a minute.

When we exported one 9.7-second CE.SDK edit at bitrates from 2 to 50 Mbps, every file landed within half a percent of that sum. Below 2 Mbps the files came out larger: asking for 0.5 Mbps gave 1.46 MB instead of 0.77 MB, because the browser’s encoder did not go that low for this edit.

Bitrate × seconds ÷ 8 = megabytes

At 8 Mbps with 128 kbps audio, one minute of video comes to about 61 MB.

Estimated file size

61 MB

Video 60 MB, audio 0.96 MB

Add a size limit to see the highest bitrate that fits.

Which Bitrate Should You Use?

Start from where the video is going. In our test edit, each halving of the bitrate cost about 3 dB of PSNR, a standard score for how closely frames match a reference, here a 50 Mbps export of the same edit. The moving water in the edit went soft long before the title text and flat shapes did.

  Video bitrate Example
Fit under a size limit Limit × 8 ÷ seconds, minus the audio A 30-second clip under 25 MB can use up to 6.5 Mbps
Web or social clip 1 to 2 Mbps (CE.SDK compress guide) Our test edit at 2 Mbps: 2.6 MB, with the moving water visibly softer
HD video to download 8 to 12 Mbps (CE.SDK compress guide) The same edit at 8 Mbps: 9.9 MB, with the water crisp
Upload to YouTube at 1080p 8 Mbps at 30 fps, 12 Mbps at 60 fps (YouTube) CE.SDK's Auto setting uses the same 8 Mbps for 1080p at 30 fps

How Does Video Compression Work?

An encoder such as H.264 takes every frame through four steps, and only one of them throws information away.

01
Between frames

Predict each frame from the ones around it

The encoder looks for blocks that already appeared in an earlier frame, perhaps shifted a little, and records a motion vector instead of the pixels. Frames built this way are P-frames, and B-frames may also borrow from a later frame. Every so often it stores a whole frame on its own, an I-frame, so a player has a place to start.

02
Within a frame

Turn blocks of pixels into frequencies

Whatever prediction could not explain is cut into small blocks, and a transform, usually a discrete cosine transform, rewrites each block as a few values for broad shapes and many for fine detail. In natural images most of the energy sits in the broad ones.

03
The lossy step

Round off the fine detail

Quantization stores those values with less precision and drops many of the fine ones to zero. A lower bitrate means coarser rounding, which is where blocky, smeared or banded video comes from. Lossless codecs skip this rounding, so their files come out several times larger.

04
Packing

Give common values the shortest codes

Entropy coding, such as the CABAC method in H.264, writes the most frequent values with the fewest bits. Nothing is lost here; the data is only packed more tightly.

How Do H.264, H.265 and AV1 Compare?

All three follow the steps above. The newer ones predict and code more elaborately, so they reach the same quality at a lower bitrate but need more computing to encode.

CE.SDK imports and exports

H.264 (AVC)

Published by the ITU in 2003, it plays in every major browser and many devices decode it in hardware, so it remains the safe choice for web and social video. Commercial use is licensed through a patent pool.

CE.SDK imports

H.265 (HEVC)

Published in 2013, it reaches the same quality as H.264 with 25% to 50% less data, at the cost of heavier encoding. Its patents are split across more than one licensing pool.

CE.SDK imports on the web

AV1

The Alliance for Open Media released it in 2018 as an open, royalty-free format. In a 2018 Facebook test it needed about half the bitrate of H.264 for similar quality, with much slower encoding. Safari plays it only on recent Apple hardware.

How Video Compression Works in CE.SDK

CE.SDK video editing exports H.264 video in an MP4 file on Web, iOS, Android and Server. Your app sets each export’s size, frame rate and bitrate, and in the browser the encoding runs through the browser’s own video encoder.

Step 01

Pick a bitrate, or let Auto pick one

Each export sets its bitrate either as a number of bits per second or as one of two modes. Auto chooses a bounded rate from the size and frame rate: 5 Mbps at 720p, 8 at 1080p and 40 at 4K, all at 30 fps, and 12 at 1080p and 60 fps. The default, System, leaves the choice to the browser, which can pick a near-lossless rate that runs long exports out of memory. In our Chrome test, Auto at 1080p produced a file byte for byte identical to an 8 Mbps export, while System settled on about 4 Mbps. To see the size and frame rate choices Auto works from, open the Video Export Options demo.

Step 02

Show users the file size before they export

CE.SDK’s compress guide recommends showing an estimated size before export, so users can weigh quality against upload time and storage. The formula above is enough for it, since our exports from 2 to 50 Mbps matched it within half a percent. For a bitrate under 2 Mbps, leave a margin or raise the bitrate.

Step 03

Accept H.265 and AV1, deliver H.264

Users can bring in H.264 and H.265 footage on every platform, and AV1 and VP9 in the browser. Exports come out as H.264 MP4 with the Main profile by default, with Baseline for mobile-friendly playback and High for desktop and professional work. In our Chrome export, the browser’s encoder placed a keyframe every 150 frames, which is 5 seconds at 30 fps, and used no B-frames.

FAQs

No. Lossless codecs rebuild every frame exactly, but they typically shrink video only 5 to 12 times, against 20 to 200 times for lossy H.264. That is why video streamed on the web and in apps is lossy, while lossless files stay in editing and archives.

It depends on where the video goes. YouTube recommends uploading at 8 Mbps for 24 to 30 fps and 12 Mbps for 48 to 60 fps. The CE.SDK compress guide suggests 8 to 12 Mbps for HD downloads and 1 to 2 Mbps for web or social clips, and CE.SDK picks 8 Mbps when its Auto setting exports 1080p at 30 fps.

Check the audio first: a 128 kbps track adds about 1 MB a minute. At very low bitrates the encoder may also stop short of the target, and in our test of a CE.SDK export in Chrome, asking for 0.5 Mbps produced a file almost twice the estimate.

At the same quality, yes: H.265 needs 25% to 50% less data. It takes more processing to encode, and not every device plays it. CE.SDK reads H.265 files on all its platforms but writes H.264, the codec every major browser plays.

A keyframe, or I-frame, is a frame stored as a whole picture, so it can be decoded without any other frame. Players start and seek from keyframes, and the frames after one are stored as changes from it, so more keyframes make a video easier to seek and edit but cost more data. Animation keyframes are a different idea, covered in the keyframe entry.