Video Compression Fundamentals: Pamela C. Cosman
Video Compression Fundamentals: Pamela C. Cosman
Video Compression Fundamentals: Pamela C. Cosman
FUNDAMENTALS
Pamela C. Cosman
1
Compressing Digital Video
Exploit spatial redundancy within frames (like JPEG:
transforming, quantizing, variable length coding)
Exploit temporal redundancy between frames
Only the sun has changed position between these 2 frames
2
Simplest Temporal Coding - DPCM
Frame 0 (still image)
Difference frame 1 = Frame 1
– Frame 0
Difference frame 2 = Frame 2
– Frame 1
If no movement in the scene,
all difference frames are 0.
Can be greatly compressed! 0 1 2 3
If movement, can see it in the
difference images
3
Difference Frames
4
Difference Frames
5
6
7
8
Types of Motion
Frame n
Translation: simple
movement of typically
rigid objects Frame n+1 Frame n+2
(Rotation) (Zoom)
Camera pans vs.
movement of objects Rotation: spinning
about an axis
Camera versus object
rotation
Zooms –in/out
Camera zoom vs. object
Frame n Frame n+1
zoom (movement in/out)
9
Describing Motion
Translational
Move (object) from (x,y) to (x+dx,y+dy)
Rotational
Rotate (object) by (r rads) (counter/clockwise)
Zoom
Move (in/out) from (object) to increase its size by
(t times)
12
Block-based Motion Estimation
1 3 1 2 3 4
2 4
5 6 7 8
6 7 8
5
9 10 11 12
10
9 12
11
14 13 14 15 16
13 15 16
16
Motion Vector Search
Logarithmic Search: First examine
Full search: Evaluate positions marked 1.
every position in the Choose best of these (lowest error
search window measure) and examine positions
marked 2 surrounding it
Choose the best of these, and
examine the positions marked 3
Final result = best of these
17
Hierarchical Motion Estimation
18
Motion Compensation
20
Motion Compensation Example
21
Objects versus Macroblocks
Real moving objects will not coincide with
boundaries of macroblocks
23
Motion Compensated Difference
Frames
Suppose we are doing lossless coding
Encoder has sequence of frames: …, F(n-2), F(n-1)
Next: encode F(n)
Past frames have been losslessly encoded, so the
decoder knows F(n-1) perfectly already
Encoder sends the motion vectors for frame F(n)
relative to frame F(n-1), to form motion
compensated frame M(n)
Encoder knows M(n), Decoder knows M(n)
24
Motion Compensation Example
F(n-1) F(n)
M(n)
25
Encoding Difference Frames
Encoder forms motion With no motion compensation
compensated diff frame: encoder could do frame diff:
MCD(n) = F(n) – M(n) FD(n) = F(n) – F(n-1)
Encoder losslessly Encoder losslessly
encodes MCD(n) encodes FD(n)
Decoder can then do Decoder can then do
F(n) = MCD(n) + M(n) F(n) = FD(n) + F(n-1)
→ knows F(n) exactly → knows F(n) exactly
Send Motion
Vectors Send MCD(n)
Motion compensated Motion compensated
frame M(n) difference image
MCD(n) =F(n) – M(n)
27
Motion Compensated Difference
Frames
But we are NOT doing lossless coding
Encoder has sequence of frames: …, F(n-2), F(n-1)
Next: encode F(n)
Past frames have been lossy encoded, so the
decoder has versions …, G(n-2), G(n-1)
Encoder knows …, G(n-2), G(n-1) also
Encoder sends the motion vectors for frame F(n)
relative to frame G(n-1), to form motion
compensated frame M(n)
28
Encoding Difference Frames
Encoder forms motion compensated
difference frame: MCD(n) = F(n) – M(n)
Encoder lossy encodes MCD(n)
Call the decoder version MCD*(n)
If the decoder received MCD(n) exactly,
could do: F(n) = MCD(n) + M(n)
But with MCD*(n), decoder can do
G(n) = MCD*(n) + M(n)
→ knows F(n) approximately
29
Motion estimation philosophy
30
Motion Compensation for Chrominance
31
Motion Estimation/Compensation
Summary
At the encoder:
For each block in the frame being coded, examine
the search window(s) in the reference frame to
find the best match block (do this for luminance
only)
Form the MC difference image = original image
minus motion compensated image
Scale the motion vectors for the chrominance,
form the motion compensated chrominance
frames, and form chrominance difference image
32
Motion Estimation/Compensation
Summary
At the decoder:
Decode the reference frames (Y,Cr,Cb)
For each block in a temporally coded Y frame, use
the motion vector to select a block from the
reference frame and glue it in place
Add the Y difference image
For each block in temporally coded Cr,Cb frames,
first scale the motion vector, then do the previous
2 steps with Cr and Cb data
33
Progress of Video Compression
34
Progress of Video Compression
35
Progress of Video Compression
36
Temporal Location of Reference
37
Flavors of Motion Estimation
38
MPEG Frame Types
39
MPEG Frame Types
40
MPEG Frame Types
Motion Compensated interpolated (B) pictures –
forward, backward, and interpolatively motion
compensated from previous/next I/P frames
41
Motion Vector Coding
42
MPEG Frame Structure Terminology
43
MPEG Frame Structure Terminology
44
MPEG GOP Structure
45
Frame Ordering
B B I B B P B B P B B P B B P B B I
-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
I B B P B B P B B P B B P B B I B B
1 -1 0 4 2 3 7 5 6 10 8 9 13 11 12 16 14 15
46
Types of Coding Modes
47
Coding Mode I (Inter-Coding)
Macro
Block
Previous Current
Frame Frame
Motion Vector
48
Coding Mode II (Intra-Coding)
Macro
Block
Previous Current
Frame Frame
49
I-Picture Coding
50
I-Picture Coding
51
P-Picture Coding: many coding modes
52
How to choose a coding mode?
MPEG does not specify how to choose mode
Full search = try everything…the different
possibilities will lead to different rate/distortion
outcomes for that macroblock
distortion
•
• MV, no difference
•
•
• MV, plus difference
• • Intra
•
rate
53
How to choose a coding mode?
54
B-Picture Coding
55
Group of Pictures
56
Group of Pictures
57