Video and audio
A video is a stack of images shown quickly one after another, with sound alongside. Everything from the last two lessons (pixels, resolution, lossy compression) still applies, multiplied by 30 or 60 pictures every second. This lesson adds the ideas that are new: containers, codecs, bitrate and keyframes.
Container and codec: the box and the language
A video file has two layers, and mixing them up causes most "this file will not play" problems.
- The container is the box: the file format, shown by the extension (
.mp4,.mkv,.mov,.webm). It holds one or more streams (video, audio, subtitles) and keeps them in sync. - The codec (coder-decoder) is the language each stream is compressed in: H.264, H.265, VP9 or AV1 for video; AAC, MP3 or Opus for audio.
clip.mp4 ← the container
┌──────────────────────────────────────────┐
│ video stream H.264, 1920 × 1080, 30 fps │
│ audio stream AAC, 48 kHz, stereo │
│ metadata date, duration, rotation… │
└──────────────────────────────────────────┘Two files can both be .mp4 and still differ: one with H.264 inside plays almost everywhere, one with AV1 inside may not play on an older phone. A player needs to understand both the box and the language.
Common codecs
| Codec | Kind | Notes |
|---|---|---|
| H.264 (AVC) | Video | Plays on nearly every device, browser and site. The safe default |
| H.265 (HEVC) | Video | Similar quality to H.264 at a noticeably lower bitrate; many phones record in it; patchy support in browsers and older PCs |
| VP9 | Video | Google's royalty-free codec, used by YouTube and in WebM files |
| AV1 | Video | Newer royalty-free codec; smaller files again, slower to encode, needs newer hardware to play smoothly |
| AAC | Audio | The usual audio partner of H.264 in MP4 files |
| MP3 | Audio | The old universal music format |
| Opus | Audio | Royalty-free, very good at low bitrates; the usual audio in WebM and in voice calls |
Common pairings: MP4 with H.264 and AAC (the most compatible), and WebM with VP9 or AV1 and Opus (common on the web). The Dhiva Labs apps use the same pairs: CompressX and Creator Toolkit write MP4, MKV and MOV with H.264 and AAC, and WebM with VP9 and Opus. See How formats are encoded.
Changing the container without touching the streams (called remuxing) is quick and loses nothing. Changing the codec means decoding and compressing again (re-encoding), which takes time and, with lossy codecs, loses a little quality.
Resolution and frame rate
Video resolution is named by the height in pixels:
| Name | Dimensions | Pixels per frame |
|---|---|---|
| 480p | 854 × 480 | 0.4 million |
| 720p (HD) | 1280 × 720 | 0.9 million |
| 1080p (Full HD) | 1920 × 1080 | 2.1 million |
| 4K (UHD) | 3840 × 2160 | 8.3 million |
4K has four times the pixels of 1080p, and needs roughly that much more data at the same quality.
Frame rate is pictures per second (fps). Films use 24 fps; most phone and web video is 30 fps; 60 fps looks smoother for sport, games and fast motion, and needs more data.
Why video files are big
Do the sums for one minute of 1080p video at 30 fps, with no compression:
1 frame = 1920 × 1080 pixels × 3 bytes = 6,220,800 bytes ≈ 6.2 MB
1 second = 6.2 MB × 30 frames = 186,624,000 bytes ≈ 187 MB
1 minute = 187 MB × 60 seconds ≈ 11.2 GBA phone stores that minute in tens of megabytes. Two tricks do it:
- Within each frame, lossy compression much like JPEG.
- Between frames, the encoder stores only what changed. In a talking-head video, the wall behind the speaker is the same in frame after frame, so it is stored once.
K = keyframe: a complete picture
· = a frame that stores only the changes since the frames around it
K · · · · · · · · · · · · · · · · · · · · · · · · · · · · · K · · · · · ·
└──────────────── a few seconds ─────────────────────────┘A keyframe is a complete picture, stored every second or few seconds. The frames between depend on it. That is why a scene with constant motion (confetti, rain, a shaky camera) makes a much bigger file than a still interview: almost everything changes in every frame.
Bitrate: data per second
Bitrate is how much data each second of a stream uses, in kilobits or megabits per second (kbps, Mbps). It sets the file size directly:
size in megabytes = bitrate in Mbps × length in seconds ÷ 8Divide by 8 because there are 8 bits in a byte. Some examples:
| Bitrate | One minute | Ten minutes |
|---|---|---|
| 1 Mbps | 7.5 MB | 75 MB |
| 4 Mbps | 30 MB | 300 MB |
| 8 Mbps | 60 MB | 600 MB |
| 20 Mbps | 150 MB | 1.5 GB |
Bitrate is not quality by itself. The same bitrate looks better at a lower resolution, in a newer codec, or on a calm scene.
Worked example: a clip for email
You want a 2-minute clip under 25 MB, with sound.
25 MB × 8 = 200 megabits for the whole file
200 megabits ÷ 120 s ≈ 1.67 Mbps in total
1.67 − 0.128 for sound ≈ 1.54 Mbps left for the pictureAbout 1.5 Mbps is enough for a fair-looking 720p clip, and thin for 1080p. That is the sum CompressX does when you choose Target size 25 MB (email) in Video Compressor: it reads the video's length, works out the bitrate, and sets aside 128 kbps for the sound unless Remove audio is on. Its guide also suggests lowering Resolution for long videos with small targets. See Target size.
CRF: aim for quality instead
Instead of a bitrate, you can ask the encoder for a steady quality and let the size be whatever it needs. That setting is CRF (constant rate factor). Lower CRF means better quality and a bigger file. For H.264, a change of about 6 roughly doubles or halves the size.
CompressX's Quality slider runs from CRF 18 to CRF 40, default 26. Creator Toolkit's Compress tab offers High quality (CRF 20), Balanced (CRF 26), Smaller (CRF 30) and Smallest (CRF 34). Use CRF when quality matters and size is flexible; use a target size when there is a hard limit.
Lower the resolution first
The same rule as for photos: fewer pixels saves the most. A 4K phone video usually looks the same on a phone screen or social feed at 1080p, at a fraction of the size.
Trimming: with and without re-encoding
Cutting a piece out of a video can be done two ways.
| Method | How | Speed | Quality | Where the cut lands |
|---|---|---|---|---|
| Stream copy (no re-encoding) | Copies the compressed frames as they are | Seconds, even for long videos | Unchanged | At a keyframe near the time you asked for |
| Re-encode | Decodes, cuts, compresses again | Slow, like compressing the whole piece | A little loss | Exactly where you asked |
The stream copy cannot start between keyframes, because the frames there only store changes from a keyframe it would be leaving out. So the cut snaps to the nearest keyframe, which can be a second or two off.
Creator Toolkit's Trim tab offers both: with Frame-accurate cut (re-encode) off, the cut is instant and keeps the original quality and format but starts at the nearest keyframe; with it on, the cut is exact, takes longer, and gives an MP4. See Trim.
Use the quick cut for rough trims such as dropping the first ten seconds of a recording. Use the exact cut when a word or a moment must start on time.
Audio: sample rate, bit depth and bitrate
Sound is a wave. To store it, the recorder measures the wave many thousands of times a second.
- Sample rate: measurements per second. 44.1 kHz (44,100 a second) is the CD and music standard; 48 kHz is the video standard. Both cover everything people can hear.
- Bit depth: how precise each measurement is. 16-bit is CD quality; 24-bit is used while recording and editing.
- Channels: 1 for mono, 2 for stereo.
Uncompressed audio (WAV) at CD quality:
44,100 samples × 16 bits × 2 channels = 1,411,200 bits per second ≈ 1,411 kbps
1 minute = 1,411,200 × 60 ÷ 8 bytes ≈ 10.6 MBThe same minute as MP3 at 128 kbps is 128,000 × 60 ÷ 8 = 0.96 MB, about a tenth.
| Format | Kind | Typical use |
|---|---|---|
| WAV | Uncompressed | Recording and editing |
| FLAC | Lossless | Archiving music without loss, often around half the size of WAV |
MP3, AAC (.m4a), Opus, OGG Vorbis | Lossy | Listening, sharing, streaming |
CompressX's guide puts it plainly: 128 kbps is fine for speech and most music on phones; 192 kbps or more suits music on good speakers. Converting from one lossy format to another (AAC to MP3, say) loses a little more each time, and converting a lossy file to FLAC or WAV makes it bigger without bringing anything back. See Compress audio.
Stay safe
- Keep the original recording. Every re-encode loses a little. Make all your versions from the original, as with photos.
- Videos carry metadata too. Phone videos can record the date and the location, like photos. Re-encoding often drops it, but do not count on that for a video you post publicly.
- Screen recordings show everything on screen: notifications, email previews, passwords being typed, other open tabs. Turn on do-not-disturb and close what you do not want seen before you record, and watch the result before you share it.
- Ask before you record or post other people. Many places have laws about recording people without consent, and filming someone in a private moment can hurt them even when it is legal.
- Large files fill phones. Videos are usually the biggest files on a phone. SpaceSweep lists every file over 10, 50, 100 or 500 MB on an Android phone. Copy videos to a computer, check the copy plays, and only then delete them: files SpaceSweep deletes cannot be recovered.
Check yourself
Question 1 of 6
Two files are both called clip.mp4. One plays on an old laptop, the other does not. What is the most likely difference?
What you learned
- The container (MP4, MKV, WebM) is the box; the codec (H.264, AV1, AAC, Opus) is how each stream is compressed.
- Resolution and frame rate set how many pixels per second must be stored; uncompressed 1080p30 is about 187 MB a second.
- Video compresses well because most frames store only changes since a keyframe.
- Size = bitrate × time ÷ 8. CRF aims for quality; a target size aims for a bitrate.
- A trim without re-encoding is instant and lossless but snaps to keyframes; a re-encoded trim is exact but slow.
- Audio is samples per second × bits × channels; MP3 or AAC at 128 kbps is about a tenth of WAV.