r/C_Programming • u/Loud_Ask_3408 • Jun 21 '26
What are audio and video codecs?
I’ve watched some videos on YouTube, but I still haven’t managed to fully understand the topic.
Could someone please explain to me what audio and video codecs are, why they are useful, and what would happen if they didn’t exist?
0
Upvotes
39
u/goose_on_fire Jun 21 '26
In the same way a modem is a MODulator/DEModulator, or a serdes is a SERializer/DESerializer, a codec is a CODer/DECoder.
There are lots of different ways to represent data, and these sorts of things are all just responsible for correctly transforming data from one representation to another. For example, from a format suitable for storing on your hard drive to a format suitable for playing on a monitor or speaker.
That's all.
11
u/ByMeno Jun 21 '26
First the topic is kinda unrelated to C
Second this a googlable question but okay
And Answer:
Raw audio = a huge list of sound samples.
Raw video = a huge sequence of images (frames/bitmaps).
So basicly codes are kinda zip/tar files but for videos or audio
These files are enormous. Codecs make them much smaller so they can be stored and transmitted efficiently.
Without codecs:
> Movies would require massive storage.
> Streaming services would need enormous bandwidth.
> View calls would be impractical.
>Downloading media would take much longer.
> Your phone would fill up extremely quickly.
A 2-hour movie that might be 2–5 GB with compression could be hundreds of gigabytes uncompressed.
3
u/frisky_5 Jun 21 '26
A picture is a matrix of numbers, assume for simplicity each number is 4 bytes, and each number represents a pixel, assume a full HD image which is 1920 by 1080 pixels, that means each image is 1920x1080x4 bytes= 8.2 Mega Bytes. A video is a sequence of images (images are also named frames), for the video to look smooth you need 30 frames (images) per second to appear on your monitor, lets say a video of length 1 minute of 30 frames per second, each frame is the same Full HD image above, that equals 60 seconds x 30 frames per second x 8.2 MB = 14.3 Giga Bytes. But when you download a video from the internet you do not download 14 gigabytes for each one minute of a video right? You download maybe 30 mega bytes? How come? That is what the codec did, it compressed the 13GB into the 30MB, the main job for codec is to compress digital media. There are many codec types for each digital medium (video, audio, etc.). For example you have a codec (comoression) named HEVC for video, and another codec named Opus for Audio. Hope that helps
2
u/ab_do20_75 Jun 21 '26
think of it like a zip file for video. raw video takes up a huge amount of space, a codec compresses it when saving and decompresses it when playing. without codecs a 2 hour movie would be hundreds of gbs and streaming would be impossible
1
u/SmokeMuch7356 Jun 22 '26
"Codec" is a mashup of the terms "coder" and "decoder"; it's software that compresses audio/video data for transmission or storage and decompresses it for playback.
Without codecs of some sort digital audio and video basically wouldn't exist, or would have obscene storage and bandwidth requirements.
0
u/tajetaje Jun 21 '26
Let’s simplify, let’s say we have a four pixel video with 2-bit monochrome color (2 bits per pixel)
Imagine a pixel moving from one corner to another. In raw format it looks like
11 00
00 00
11 00
00 00
10 00
00 01
01 00
00 10
00 00
00 11
00 00
00 11
You can see there’s a lot of wasted data here, the top right and bottom left pixels are 00 the whole time. And there are frames that are totally identical to the previous frame. A very simple video codec might be something like
11 00
00 00
(This is usually called a key frame, it has enough info to construct a full frame directly)
*same as last
10
01
…etc
Scale this up to 8, 10, 12 bit color and high res video, and you can see how the space savings help. As a side note, this why rain, snow, confetti, etc. make video encoding perform poorly, they have to constantly update the whole video.
And I’m not even talking about compression or anything like that (other comments do a better job)