CrashCourse · @crashcourse
Compression: Crash Course Computer Science #21
Uploaded June 8, 2018 · Length 12:48
Summary
This video explains data compression, covering lossless techniques like Run-Length Encoding and Huffman coding, and introduces the concept of lossy compression.
- data compression explained
- lossless compression
- run-length encoding
- huffman coding
- lossy compression
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:03
This episode is brought to you by Curiosity Stream.
- 0:05
Hi, I'm Carrie Anne, and welcome to Crash Course Computer Science!
- 0:09
Last episode we talked about Files, bundles of data, stored on a computer, that are formatted
- 0:13
and arranged to encode information, like text, sound or images.
- 0:17
We even discussed some basic file formats, like text, wave, and bitmap.
- 0:20
While these formats are perfectly fine and still used today, their simplicity also means
- 0:24
they’re not very efficient.
- 0:26
Ideally, we want files to be as small as possible, so we can store lots of them without filling
- 0:30
up our hard drives, and also transmit them more quickly.
- 0:33
Nothing is more frustrating than waiting for an email attachment to download. Ugh!
- 0:37
The answer is compression, which literally squeezes data into a smaller size.
- 0:41
To do this, we have to encode data using fewer bits than the original representation.
- 0:46
That might sound like magic, but it’s actually computer science!
- 0:49
INTRO
- 0:58
Lets return to our old friend from last episode, Mr. Pac-man!
- 1:01
This image is 4 pixels by 4 pixels.
- 1:04
As we discussed, image data is typically stored as a list of pixel values.
- 1:08
To know where rows end, image files have metadata, which defines properties like dimensions.
- 1:12
But, to keep it simple today, we’re not going to worry about it.
- 1:15
Each pixel’s color is a combination of three additive primary colors: red, green and blue.
- 1:20
We store each of those values in one byte, giving us a range of 0 to 255 for each color.
- 1:26
If you mix full intensity red, green and blue - that’s 255 for all three values - you
- 1:31
get the color white.
- 1:32
If you mix full intensity red and green, but no blue (it’s 0), you get yellow.
- 1:36
We have 16 pixels in our image, and each of those needs 3 bytes of color data.
- 1:41
That means this image’s data will consume 48 bytes of storage.
- 1:44
But, we can compress the data and pack it into a smaller number of bytes than 48!
- 1:48
One way to compress data is to reduce repeated or redundant information.
- 1:52
The most straightforward way to do this is called Run-Length Encoding.
- 1:55
This takes advantage of the fact that there are often runs of identical values in files.
- 1:59
For example, in our pac-man image, there are 7 yellow pixels in a row.


