CrashCourse · @crashcourse

Compression: Crash Course Computer Science #21

Uploaded June 8, 2018 · Length 12:48

Compression: Crash Course Computer Science #21

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.

  1. 0:03

    This episode is brought to you by Curiosity Stream.

  2. 0:05

    Hi, I'm Carrie Anne, and welcome to Crash Course Computer Science!

  3. 0:09

    Last episode we talked about Files, bundles of data, stored on a computer, that are formatted

  4. 0:13

    and arranged to encode information, like text, sound or images.

  5. 0:17

    We even discussed some basic file formats, like text, wave, and bitmap.

  6. 0:20

    While these formats are perfectly fine and still used today, their simplicity also means

  7. 0:24

    they’re not very efficient.

  8. 0:26

    Ideally, we want files to be as small as possible, so we can store lots of them without filling

  9. 0:30

    up our hard drives, and also transmit them more quickly.

  10. 0:33

    Nothing is more frustrating than waiting for an email attachment to download. Ugh!

  11. 0:37

    The answer is compression, which literally squeezes data into a smaller size.

  12. 0:41

    To do this, we have to encode data using fewer bits than the original representation.

  13. 0:46

    That might sound like magic, but it’s actually computer science!

  14. 0:49

    INTRO

  15. 0:58

    Lets return to our old friend from last episode, Mr. Pac-man!

  16. 1:01

    This image is 4 pixels by 4 pixels.

  17. 1:04

    As we discussed, image data is typically stored as a list of pixel values.

  18. 1:08

    To know where rows end, image files have metadata, which defines properties like dimensions.

  19. 1:12

    But, to keep it simple today, we’re not going to worry about it.

  20. 1:15

    Each pixel’s color is a combination of three additive primary colors: red, green and blue.

  21. 1:20

    We store each of those values in one byte, giving us a range of 0 to 255 for each color.

  22. 1:26

    If you mix full intensity red, green and blue - that’s 255 for all three values - you

  23. 1:31

    get the color white.

  24. 1:32

    If you mix full intensity red and green, but no blue (it’s 0), you get yellow.

  25. 1:36

    We have 16 pixels in our image, and each of those needs 3 bytes of color data.

  26. 1:41

    That means this image’s data will consume 48 bytes of storage.

  27. 1:44

    But, we can compress the data and pack it into a smaller number of bytes than 48!

  28. 1:48

    One way to compress data is to reduce repeated or redundant information.

  29. 1:52

    The most straightforward way to do this is called Run-Length Encoding.

  30. 1:55

    This takes advantage of the fact that there are often runs of identical values in files.

  31. 1:59

    For example, in our pac-man image, there are 7 yellow pixels in a row.