NUS.SOC.CS5248Ooi Wei Tsang
Media Compression
NUS.SOC.CS5248Ooi Wei Tsang
You are Here
Network
Encoder
Sender
Middlebox
Receiver
Decoder
NUS.SOC.CS5248Ooi Wei Tsang
Why compress?
“Bandwidth Not Enough” “Disk Space Not Enough”
Size of Uncompressed DVD Movie =
NUS.SOC.CS5248Ooi Wei Tsang
Why compress?
“Bandwidth Not Enough” “Disk Space Not Enough”
Size of Uncompressed DVD Movie = 720 x 576 x 3 x 25 x 60 x 120 =208.6GB
NUS.SOC.CS5248Ooi Wei Tsang
JPEG Compression
Original Image (1153KB)
1:1
Original Image (1153KB)
3.5:1
Original Image (1153KB)
17:1
Original Image (1153KB)
27:1
Original Image (1153KB)
72:1
Original Image (1153KB)
192:1
NUS.SOC.CS5248Ooi Wei Tsang
Compression Ratio
Quality Size Ratio
Raw TIFF 1153KB 1:1
Zipped TIFF 982KB 1.2:1
Q=100 331KB 3.5:1
Q=70 67KB 17:1
Q=40 43KB 27:1
Q=10 16KB 72:1
Q=1 6KB 192:1
NUS.SOC.CS5248Ooi Wei Tsang
Magic of JPEG
Throw away information we cannot see Color information “High frequency signals”
Rearrange data for good compression
Use standard compression
NUS.SOC.CS5248Ooi Wei Tsang
Discard color information
Y
V U
NUS.SOC.CS5248Ooi Wei Tsang
Color Sub-sampling
4:4:4
4:2:2
4:2:0
4:1:1
NUS.SOC.CS5248Ooi Wei Tsang
4:2:2 Sub-sampling
Y
V U
Original Image (1153KB)
4:2:0
Original Image (1153KB)
“4:1:0”
NUS.SOC.CS5248Ooi Wei Tsang
Discrete Cosine Transform
Demo
NUS.SOC.CS5248Ooi Wei Tsang
Quantization
242 65
-54 -10
23 5
-4 -2
13 6
2 1
3 5
-1 -2
8 8
8 8
8 8
8 16
8 8
8 16
16 32
32 64
30 8
-6 -1
2 0
0 0
1 0
0 0
0 0
0 0
/ =
QuantizationTable
DC
AC
NUS.SOC.CS5248Ooi Wei Tsang
Differential Coding
30 8
6 -1
2 0
0 0
1 0
0 0
0 0
0 0
25 3
2 1
1 0
0 0
4 0
0 0
1 0
0 0
27 3
2 1
1 0
0 0
4 0
0 0
1 0
0 0
30 8
6 -1
2 0
0 0
1 0
0 0
0 0
0 0
-5 3
2 1
1 0
0 0
4 0
0 0
1 0
0 0
2 3
2 1
1 0
0 0
4 0
0 0
1 0
0 0
NUS.SOC.CS5248Ooi Wei Tsang
Zig-zag ordering
27 3
2 1
1 0
0 0
4 0
0 0
1 0
0 0
27, 3, 2, 4, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0
NUS.SOC.CS5248Ooi Wei Tsang
Run-Length Encoding
27 3
2 1
1 0
0 0
4 0
0 0
1 0
0 0
27, 3, 2, 4, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0
(27, 1) (3, 1) (2, 1), (4, 1), (1, 2), (0, 5), (1, 1), (0, 4)
NUS.SOC.CS5248Ooi Wei Tsang
Idea: Motion JPEG
Compress every frame in a video as JPEG
DVD-quality video = 208.6GB Reduction ratio = 27:1Final size = 7.7GB
NUS.SOC.CS5248Ooi Wei Tsang
Video Compression
NUS.SOC.CS5248Ooi Wei Tsang
Temporal Redundancy
NUS.SOC.CS5248Ooi Wei Tsang
Motion Estimation
NUS.SOC.CS5248Ooi Wei Tsang
Bi-directional Prediction
NUS.SOC.CS5248Ooi Wei Tsang
Watch for Motion Vectors
Demo
NUS.SOC.CS5248Ooi Wei Tsang
H.261
I-Frame
P-Frame
NUS.SOC.CS5248Ooi Wei Tsang
MPEG-1
B-Frame
NUS.SOC.CS5248Ooi Wei Tsang
MPEG Frame Pattern
Example display sequence: IBBPBBP …
Example encoding sequence: IPBBPBB
NUS.SOC.CS5248Ooi Wei Tsang
Compression Ratio
Frame Type Typical Ratio
I 10:1
P 20:1
B 50:1
NUS.SOC.CS5248Ooi Wei Tsang
Sequence
sequence header:• width• height• frame rate• bit rate• :
NUS.SOC.CS5248Ooi Wei Tsang
GOP: Group of Picture
gop header:• time• :
NUS.SOC.CS5248Ooi Wei Tsang
Picture
pic header:• number• type (I,P,B)• :
NUS.SOC.CS5248Ooi Wei Tsang
Picture
NUS.SOC.CS5248Ooi Wei Tsang
Slice
NUS.SOC.CS5248Ooi Wei Tsang
Macroblock
NUS.SOC.CS5248Ooi Wei Tsang
Block
Y Y
Y Y
U
V
1 Macroblock =
NUS.SOC.CS5248Ooi Wei Tsang
For I-Frame
Every macroblock is encoded independently (“I-macroblock”)
NUS.SOC.CS5248Ooi Wei Tsang
For P-Frame
Every macroblock is either I-macroblock a motion vector + error terms wrt a
prev I/P-frame (“P-macroblock”)
NUS.SOC.CS5248Ooi Wei Tsang
For B-Frame
Every macroblock is either I-macroblock P-macroblock a motion vector + error terms wrt a
future I/P-frame 2 motion vectors + error terms wrt
a prev/future I/P-frame
NUS.SOC.CS5248Ooi Wei Tsang
Review: MPEG structure
SequenceGOPPictureSliceMacroblockBlock
NUS.SOC.CS5248Ooi Wei Tsang
MPEG Decoding (I-Frame)
EntropyDecoding
Dequantize
IDCT
101000101
NUS.SOC.CS5248Ooi Wei Tsang
MPEG Decoding (P-Frame)
EntropyDecoding
Dequantize
IDCT
101000101
PrevFrame
+
NUS.SOC.CS5248Ooi Wei Tsang
FutureFrame
MPEG Decoding (B-Frame)
EntropyDecoding
Dequantize
IDCT
101000101
PrevFrame
+
AVG
NUS.SOC.CS5248Ooi Wei Tsang
There are more..
Half-pel Motion PredictionSkipped Macroblocketc.
NUS.SOC.CS5248Ooi Wei Tsang
MPEG in daily life
MPEG Standards
Bit-rate Usage
MPEG-1 1.5Mbps VCD
MPEG-2 10-40 MbpsDVD, SVCD,
HDTV
MPEG-4 ScalableQuickTime,
DivX;)
NUS.SOC.CS5248Ooi Wei Tsang
The Future: H.264
Same quality at half the rateHow:
Variable block size Multiple reference frame ...
NUS.SOC.CS5248Ooi Wei Tsang
Hands-On
Download source code, compile and play with ffmpeg mpeg_stat
Try different MPEG-1 encoding parameter
NUS.SOC.CS5248Ooi Wei Tsang
Impact on Systems Design
How to package data into packets? How to deal with packet loss? How to deal with bursty traffic? How to predict decoding time? : :