Back to Glossary
Video

Video Codec

What Is a Video Codec?

A video codec compresses video into a much smaller stream for storing and sending, then decodes that stream back into pictures for playback. The name joins its two halves, the coder and the decoder.

Names such as H.264 and AV1 refer to standards. A standard fixes the format of the stream and the steps for decoding it, so every player rebuilds the same picture, but it leaves each encoder free to decide how to compress. That is why x264 and OpenH264, two encoders for H.264, can make different files from the same video.

The codec’s output is only part of the file. A container such as MP4 or WebM holds it together with the audio, which has its own codec, and a little metadata. In the two CE.SDK exports drawn here, an H.264 MP4 and a VP9 WebM, the video track took 87% and 93% of the file.

What Is the Difference Between a Codec and a Container?

The codec is the method that compresses a track, and the container is the file format that stores the compressed tracks. MP4 and WebM are containers, not codecs.

The codec compresses each track

Video codecs such as H.264, H.265, VP8, VP9 and AV1 compress the picture, and audio codecs such as AAC and Opus compress the sound. A player needs the matching decoder for each track to play the file.

The container stores the tracks in one file

Next to the tracks, a container keeps metadata such as the duration and the index a player uses to find each frame. An MP4 can hold H.264, H.265, AV1 or VP9, and WebM, built on Matroska, takes VP8, VP9 or AV1 with Opus or Vorbis audio, one reason WebM and MP4 suit different jobs.

Which Video Codec Should You Use?

Where the video will play decides the codec. A course platform, for example, might give students an H.264 MP4 to download and stream the same lesson as AV1 in WebM inside its own web player. When the choice is between H.264 and H.265, the H.264 vs H.265 entry compares their file sizes, encoding work and playback support, and AV1 vs HEVC does the same for AV1 and H.265.

Use H.264 in MP4 for

  • Files people download or send on

    MDN notes that every major browser plays an MP4 file holding H.264 and AAC.

  • Uploads to video platforms

    YouTube's recommended upload settings ask for H.264 in an MP4 container.

  • Sharing with devices you know nothing about

    Apple's own devices may share their H.265 clips as H.264 when the receiving device can't play the newer format.

Use AV1 or VP9 in WebM for

  • Video in your own web player

    MDN's first pick for video on a website is AV1 with Opus audio in WebM, well supported apart from Safari on older Apple devices.

  • Video with a transparent background

    VP9 in WebM can carry an alpha channel, though Safari does not support transparency in it. CE.SDK can keep that transparency in WebM exports made on iOS, macOS and Android or with its native Node.js package.

Use H.265 in MP4 for

  • Video for Apple devices

    Apple builds H.265 support into its devices and says the format keeps the same visual quality as H.264 in less storage.

  • Smaller files that have to stay MP4

    Apps and services that accept only MP4 can still get the smaller H.265 file, as long as their players decode it.

How Video Codecs Work in CE.SDK

Your users can work with H.264 and H.265 video from MP4 or MOV files in CE.SDK video editing, along with VP9 and AV1, on Web, iOS, Android and Server. On export, your app decides which container and codec each video gets.

01

Check which encoders the device has

In the browser, CE.SDK encodes with the browser’s own video encoders, so what the browser supports decides what your users can export. Call checkCapabilities() once, then read the state of the codec you want, such as av1Encode. CE.SDK never falls back to another codec: one the browser cannot encode fails the export.

02

Pick the container, then the codec

In CE.SDK, an MP4 export takes H.264 or H.265 and a WebM export takes VP8, VP9 or AV1, and any other pair fails. Left on Auto, CE.SDK writes H.264 into MP4 and VP9 into WebM. H.265 works only on browsers and mobile platforms that support it, and the native Node.js package exports H.264 MP4 or WebM.

03

Expect audio and a cover to match the container

MP4 exports carry AAC audio, or Opus in a browser that can encode Opus but not AAC, such as Firefox. WebM exports carry Opus. Every MP4 also embeds a PNG cover image up to 512 × 512 pixels, 190 KB in the export shown above, and your app chooses the frame it shows.

FAQs

Usually the app can open the container but has no decoder for the codec inside it. Two .mp4 files can hold different codecs, so a player that handles H.264 may still fail on H.265 or AV1, and MDN's container guide notes that support for a container says nothing about the codecs in it. When a video won't play, check the codec first.

No, the audio track has a codec of its own, such as AAC or Opus, and each container accepts only some of them. In the two exports in the diagram above, the sound took 5% to 7% of each file, so the video codec accounts for most of the size.

The encoder and the footage change the result as well. Two encoders for the same codec make different choices, and the amount of detail and motion in a scene decides how far a bitrate stretches.

Open it in a tool that reads the file's track headers, such as FFmpeg's ffprobe. Each track stores a short code for its codec. The CE.SDK MP4 exports we checked labeled their tracks avc1 for H.264, hvc1 for H.265 and mp4a for AAC, and the WebM files used V_VP9, V_AV1 and A_OPUS. The file extension only tells you the container.

Yes. HEVC, short for High Efficiency Video Coding, is the standard that ITU publishes as H.265, in the same way that H.264 is also called AVC, for Advanced Video Coding. Apple uses the HEVC name on its devices, and so does CE.SDK's export API.