Video Compression as Fast As Possible
Techquickie
·Techquickie
·2015-05-07
·
1,178 words · ~5 min read
0:00
video compression is a very important aspect of how video streaming websites
0:03
like youtube netflix and hulu work without it you wouldn't be able to
0:07
stream such high quality high frame videos like this one first some math
0:11
let's say you're watching a video with a resolution of
0:15
pixels that's like 2 million pixels per frame and in this case you've got 30
0:20
frames per second that's a whopping 62
0:23
million pixels per second if each pixel needs 24 bits or three bytes of
0:28
information you're looking at 178 megabytes of data per second completely
0:34
uncompressed that would be 51 gigabytes of information for a single five minute
0:39
video we've got pretty fast internet here at the office but even we can only
0:43
download like two and a half gigabytes in five minutes
0:46
that's a long ways away from 51. fortunately a five minute high
0:50
definition youtube video is not 51 gigabytes it's in fact more like 72
0:55
megabytes that's like 700 times smaller
0:58
how did they do that that's the magic of video compression which works mostly by
1:03
minimizing redundancy in the video data
1:07
now there are all sorts of different ways to compress video and lots of
1:10
different video containers and codecs but i won't go into detail about that
1:14
because last already covered it in this episode and frankly i still don't really
1:18
understand it all even though i am employed as a video editor so don't tell
1:22
Linus so here's what you need to know there are two ways to compress video
1:27
spatial compression and temporal compression also known as intra-frame
1:32
and interframe respectively seriously who names this stuff
1:36
anyway i'm going to describe each of these in terms of the jpeg image format
1:40
and the mpeg video format spatial or
1:43
intra-frame compression is applied only to individual video frames to compress a
1:48
video frame you can use the same process that's used to compress a still image
1:52
like a jpeg when a jpeg is created color
1:55
information of the image is reduced in a process called chroma sub sampling and
1:59
then the image is split into sections of 8x8 pixels called macroblocks then all
2:04
of this fancy stuff is done to these blocks to further reduce the file size
2:08
it's easy to see this effect on an image that has been saved with a high amount
2:12
of compression all those ugly looking squares are known as compression
2:16
artifacts some images like this red square can be compressed more than
2:20
others like this complicated photograph because the red square is very simple
2:24
with a lot more redundancy so that's how a jpeg uses spatial compression now for
2:29
an mpeg sometimes called a motion jpeg
2:32
things are a bit more complicated than just lining up a whole bunch of jpegs
2:36
one after the other to be used as video frames doing it that way would not allow
2:40
for inter frame or temporal compression
2:44
temporal compression works again by reducing redundancy if you go through a
2:49
video like this one frame by frame you'll notice that many frames are
2:52
almost completely identical that's redundancy which can be easily
2:56
compressed for example for all the parts of this video that don't need to change
3:00
from one frame to the next like all this whiteness around me all we need is an
3:04
instruction for those parts of the frame which says don't change anything like
3:08
jpeg the mpeg standard breaks a video frame into 8x8 pixel macro blocks and
3:14
each macro block receives instructions on what to do with the pixels they
3:17
already have there are instructions for staying exactly the same for moving
3:22
rotating changing color changing completely and so on video frames with
3:27
instructions like this are called p frames and they use about half as much
3:31
data as an iframe which is pretty much just a jpeg
3:35
there are also b frames which are predictions or interpolations between i
3:40
and p frames b frames use a quarter as much data as an iframe so they really
3:44
save a lot of space this is all pretty easy to see on a video file that has
3:48
been saved in an extremely low quality setting like what you're seeing right
3:52
now again all these awful square thingies are called compression
3:56
artifacts furthermore sometimes a video file will be corrupted or missing some
4:00
data when that happens you get an effect like this one
4:04
this particular effect is caused by a missing iframe which would have cleared
4:08
away the old image to make room for a new one without the iframe the list of
4:12
changes in the following b and p frames are applied to the wrong image so now
4:17
you know why a video sometimes looks weird or gets all blocky those artifacts
4:21
are a result of the video compression being either too high or else some kind
4:26
of error in the coding or transmission of the video data now listen if none of
4:30
that made any sense everything i've said can be broken down to one thing
4:35
bit rate the bit rate is the amount of data or bits that are being used every
4:40
second if a video has a low bid rate it will be low resolution and or low
4:44
quality with lots of compression artifacts if a video has a high bitrate
4:49
it will be high quality and or high resolution so the more bits you have to
4:54
work with the better the video will look there's just no getting around that even
4:58
with the best compression methods video compression is a balancing act between a
5:02
good looking video or a small file size you can't have both but if compromise is
5:07
not your style maybe you'll like fractal design now i'm sure you've all grown
5:12
accustomed to embarrassing torturous events happening to line us in these
5:15
spots let's look at them now
5:20
behind in this manner
5:24
speaking of mean fractal design is that buying up all of my advertising
5:27
inventory so i was a little nervous about doing this ad i am however
5:32
relieved to say that josh has granted me a reprieve i guess Linus is the one he
5:36
wants to torture so we're using this spot to thank all of you the viewers who
5:40
went to the survey page and responded so positively to our previous fractal
5:44
design ads as fast as possible that they've decided to continue sponsoring
5:48
this show so thanks to you guys and thanks to fractal design the company
5:52
whose cases power supplies and fans bring all of the boys to all of the
5:56
yards be sure to check back over the next few weeks to learn just what that
6:00
reference might mean thanks for watching this episode of fastest possible give us
6:04
a like or a dislike leave a comment subscribe do it subscribe and we'll see
6:09
you next time