SlideShare a Scribd company logo
HOW VIDEO
CODEC WORKS
I'm not a runway but I don't have
either twitter or FB
But you still can ask questions
using #qacodec on twitter
PS: I do have a github leandromoreira
#qacodec
MISSION: IMPOSSIBLE
OUR GOAL
To learn the whys, whats and hows about
digital video compression.
WHY DO WE NEED
COMPRESSION?
#qacodec
IN THE BEGINNING A SINGLE PIXEL
(PICTURE ELEMENT)
#qacodec
HOW CAN WE ENCODE THIS PIXEL?
1B = 8 bits
1 bit
2 bits
#qacodec
LET'S DEFINE AN IMAGE
(2D IS ON)
4 x 4 x 1 = 16B
width
height
#qacodec
LET'S COLORIZE IT
(RGB PRIMARY COLORS)
X
#qacodec
https://lumeniquessl.com/2012/03/01/12-in-12-for-2012-the-flicker-indicator-machine/
https://lightingstudio.wordpress.com/2012/03/27/week5-light-object-shadow-contrast/
#qacodec
NOW WE'RE DEALING WITH COLOR
(3D IS ON)
width
height
color
#qacodec
THE COLOR COST
4 x 4 x 3 = 48B
BEFORE WE MOVE ON...
#qacodec
#qacodec
MATRIX OF NUMBERS
25 14
0
0
14 14
16 13 13 13
15 0
15 15
20 10
20 10
0 0
15 15
0 0
10 10
#qacodec
BEHOLD, THE 4TH DIMENSION
4 x 4 x 3 x 30 = 1440B
time
A SINGLE TV SHOW
EPISODE
#qacodec
30 x 60 x 24 x 3 x 1080 x 1920 = 250.28GB
1080p 24 fps 30 min long
time in sec colorfps resolution
#qacodec
24 x 3 x 1080 x 1920 x 8 = 1.11Gbps
colorfps resolution bits
WHAT CAN
WE DO?
#qacodec
reduce
repetitions in
space
exploit our
vision
reduce
repetitions in
time
#qacodec
EXPLOITING OUR VISION
#qacodec
OUR EYES: AN OVERSIMPLIFICATION
The eye contains about 120M rod cells and 6M cone cells.
#qacodec
WE'RE BETTER TO SEE LUMA THAN COLOR
#qacodec
AN ALTERNATIVE TO RGB
#qacodec
From RGB to YCbCr
Y = 0.299R + 0.587G + 0.114B
Cb
= 0.564(B - Y) | Cr
= 0.713(R - Y)
From YCbCr to RGB
R = Y + 1.402Cr
| B = Y + 1.772Cb
| G = Y - 0.344Cb
- 0.714Cr
*ITU-R BT.601-7
#qacodec
COLOR MODEL YUV
(YCBCR, YPBPR)
Y (luma) U (chroma blue) V (chroma red)
#qacodec
CHROMA SUBSAMPLING
1280
720
180
320
#qacodec
24 bits per
pixel
12 bits per
pixel
#qacodec
30 x 60 x 24 x 3 x 1080 x 1920 = 250.28GB
time in sec colorfps resolution
#qacodec
30 x 60 x 24 x 3 x 1080 x 1920 = 250.28GB
time in sec colorfps resolution
30 x 60 x 24 x 1.5 x 1080 x 1920 = 125.14GB
time in sec colorfps resolution
#qacodec
CORRELATIONS IN TIME
#qacodec
TEMPORAL REDUNDANCY
frame 0 frame 1 frame 2 frame 3
#qacodec
ORIGINAL FRAMES
|||||||||| (103Kb) || (4Kb)
#qacodec
FRAME DIFFERENCE
#qacodec
FRAME DIFFERENCE COST
#qacodec
WHAT IS THE COST?
frame 0 frame 1
diff + reference
CAN WE DO BETTER?
#qacodec
DESCRIBE THE MOTION
(ESTIMATION)
frame 1 frame 2
x=34, y=26x=12, y=25
#qacodec
FRAME DIFFERENCE VS MOTION ESTIMATION
ffmpeg -flags2 +export_mvs -i in.mp4 -vf codecview=mv=pf+bf+bb out.mp4
#qacodec
SO, CAN WE JUST LINK ALL THE FRAMES?
#qacodec
TEMPORAL REDUNDANCY
(INTER PREDICTION)
× ✔ ✔ ✔ ×
FRAMES THAT CAN'T BE
EASILY EXPLOITED BY
TEMPORAL REDUNDANCY
#qacodec
CORRELATIONS IN SPACE
LOTS OF
SIMILARITIES
PATTERNS /
DIRECTIONS
How video codec work
SPATIAL REDUNDANCY
(INTRA PREDICTION)
100 100 100 200
100 ??? ??? ???
100 ??? ??? ???
100 ??? ??? ???
100 100 100 200
100 100 100 200
100 100 100 200
100 100 100 200
100 100 100 200
100 100 100 200
100 100 100 200
100 100 120 210
100 100 100 200
100 0 0 0
100 0 0 0
100 0 20 10
unknown values direction of the
prediction
real values difference
highly compressible
WHAT IS THE COST OF INTRA PREDICTION?
100 100 100 200
100 0 0 0
100 0 0 0
100 0 20 10
direction of the
prediction
residual
values
SOME PREDICTION DIRECTIONS
PIED PIPER
OUR IMAGINARY VIDEO CODEC
* Pied Piper is a startup company focused on "multi-platform technology based on a proprietary universal compression algorithm" featured in the HBO series Silicon Valley
CODEC
“A codec is a device or computer program
for encoding or decoding a digital data
stream or signal.”
CODEC
*Vcodex: Introduction to Video Coding
Compress
(enCOde)
Decompress
(DECode)
Video Source
Compressed
Video Display
CODEC
*Vcodex: Introduction to Video Coding
Compress
(enCOde)
Decompress
(DECode)
Video Source
Compressed
Video Display
ENCODER BLOCKS
picture
partitioning
predictions transform quantization
entropy
coding
redundancy removal
entropy
reduction
lossless
compression
dct, dwt, intra-prediction,
inter-prediction, motion
estimation / compensation
linear,
logarithm
huffman, lzw
...
technique
implementation
picture
partitioning
predictions transform quantization
entropy
coding
redundancy removal
entropy
reduction
lossless
compression
dct, dwt, intra-prediction,
inter-prediction, motion
estimation / compensation
linear,
logarithm
huffman, lzw
...
ENCODER
technique
implementation
FRAME PARTITIONING
ENCODER
picture
partitioning
predictions transform quantization
entropy
coding
redundancy removal
entropy
reduction
lossless
compression
dct, dwt, intra-prediction,
inter-prediction, motion
estimation / compensation
linear,
logarithm
huffman, lzw
...
technique
implementation
(INTRA|INTER)-PREDICTION
(SPACE AND TIME)
direction of the
prediction
100 100 100 200
100 100 100 200
100 100 100 200
100 100 100 200
ENCODER
picture
partitioning
predictions transform quantization
entropy
coding
redundancy removal
entropy
reduction
lossless
compression
dct, dwt, intra-prediction,
inter-prediction, motion
estimation / compensation
linear,
logarithm
huffman, lzw
...
technique
implementation
TRANSFORM
Double [3] f(x): x + x => [ 6]
Plus10 [3] f(x): x + 10 => [ 13]
Divide2 [3] f(x): x / 2 => [1.5]
TRANSFORM
(DCT)
https://www.iem.thm.de/telekom-labor/zinke/mk/mpeg2beg/whatisit.htm
WALKTHROUGH
DCT APPLIED
ENCODER
picture
partitioning
predictions transform quantization
entropy
coding
redundancy removal
entropy
reduction
lossless
compression
dct, dwt, intra-prediction,
inter-prediction, motion
estimation / compensation
linear,
logarithm
huffman, lzw
...
technique
implementation
How video codec work
ORIGINAL VS QUANTIZED (50%)
ORIGINAL VS QUANTIZED (85%)
https://www.mathworks.com/help/images/discrete-cosine-transform.html
ENCODER
picture
partitioning
predictions transform quantization
entropy
coding
redundancy removal
entropy
reduction
lossless
compression
dct, dwt, intra-prediction,
inter-prediction, motion
estimation / compensation
linear,
logarithm
huffman, lzw
...
technique
implementation
ENTROPY CODING VLC
27 10 0 0
10 0 0 0
0 0 0 0
0 0 0 0
ZIG-ZAG SCAN
(FROM 2D TO 1D)
27 10 0 0
10 0 0 0
0 0 0 0
0 0 0 0
27,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0
PROBABILITY OF EACH SYMBOL
27,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0
symbols 27 10 0
probability 1/16 2/16 13/16
BITCODE
symbols 27 10 0
probability 1/16 2/16 13/16
binary code 110 10 0
ENCODING BIT CODES
*CAVLC example
binary code 0 10 110
27,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0
110 10 10 0 0 0 ....
16B
3B + symbol table
FROM MANY BYTES TO FEW BITS
010101101101 + code table
0001101100001010000010100000
0000000000000000000000000000
0000000000000000000000000000
0000000000000000000000000000
0000000000000000
ENCODER
picture
partitioning
predictions transform quantization
entropy
coding
redundancy removal
entropy
reduction
lossless
compression
dct, dwt, intra-prediction,
inter-prediction, motion
estimation / compensation
linear,
logarithm
huffman, lzw
...
technique
implementation
ENCODER
picture
partitioning
predictions
(subtract)
transform quantization entropy coding
picture
reconstructing
predictions
(add)
inverse
transform
dequantization
entropy
decoding
DECODER
#qacodec
30 x 60 x 24 x 3 x 1080 x 1920 = 250.28GB
time in sec colorfps resolution
#qacodec
30 x 60 x 24 x 3 x 1080 x 1920 = 250.28GB
time in sec colorfps resolution
30 x 60 x 24 x 1.5 x 1080 x 1920 = 125.14GB
time in sec colorfps resolution
#qacodec
30 x 60 x 24 x 3 x 1080 x 1920 = 250.28GB
time in sec colorfps resolution
30 x 60 x 24 x 1.5 x 1080 x 1920 = 125.14GB
time in sec colorfps resolution
30 x 60 x 24 x 0.127 x 1080 x 1920 = 1.32GB
time in sec colorfps resolution
#qacodec
24 x 3 x 1080 x 1920 x 8 = 1.11Gbps
colorfps resolution bits
24 x 0.127 x 1080 x 1920 ~= 6.02Mbps
colorfps resolution
FINALLY, HOW
NEWER CODECS
BEAT OLDER ONES?
HEVC @ 2MbpsAVC @ 4Mbps
AVC @ 400kbps HEVC @ 400kbps
How video codec work
References ● https://github.com/leandromoreira/digital_video_introduction
● https://en.wikipedia.org/wiki/List_of_monochrome_and_RGB_p
alettes
● https://globoplay.globo.com/os-dias-eram-assim/p/9955/
● https://commons.wikimedia.org/wiki/File:Ressorts_de_compre
ssion_coniques.jpg
● https://commons.wikimedia.org/wiki/File:Sony_DME7000_Digit
al_Video_Multi_Effects_Processor_(13577533863).jpg
● https://commons.wikimedia.org/wiki/File:High-speed.jpg
● https://en.wikipedia.org/wiki/List_of_monochrome_and_RGB_p
alettes
● https://www.youtube.com/watch?v=o0DYP-u1rNM
● http://silicon-valley.wikia.com/wiki/Pied_Piper_(company)
● http://www.nintendo.com/
LEANDRO MOREIRA
leandromoreira.com.br
Disclaimer: The views and opinions expressed in this presentation are those of the authors and do not
necessarily reflect the policy or position of Globo.
bit.ly/intro_codec
SEE MORE:

More Related Content

PPT
Iain Richardson: An Introduction to Video Compression
PPSX
Broadway microprocessor
 
PDF
3GPP LTE Detailed explanation 1 (Random Access)
PPT
H 264 in cuda presentation
PDF
A REAL-TIME H.264/AVC ENCODER&DECODER WITH VERTICAL MODE FOR INTRA FRAME AND ...
PDF
HEVC overview main
PDF
HEVC VIDEO CODEC By Vinayagam Mariappan
PDF
Iain Richardson: An Introduction to Video Compression
Broadway microprocessor
 
3GPP LTE Detailed explanation 1 (Random Access)
H 264 in cuda presentation
A REAL-TIME H.264/AVC ENCODER&DECODER WITH VERTICAL MODE FOR INTRA FRAME AND ...
HEVC overview main
HEVC VIDEO CODEC By Vinayagam Mariappan

Similar to How video codec work (20)

PPTX
High Efficiency Video Codec
PPT
Introduction to Video Compression Techniques - Anurag Jain
PPTX
H.265ImprovedCE_over_H.264-HarmonicMay2014Final
PDF
Video compression
PDF
Are Video Codecs... Done?
PDF
An Introduction to Versatile Video Coding (VVC) for UHD, HDR and 360 Video
PPT
Compression
PPT
Compression
PPTX
Video Compression Basics by sahil jain
PPT
Media Encoding
ODP
MPEG-1 Part 2 Video Encoding
PDF
Introduction To Video Compression
PDF
Introduction To Video Compression
PDF
Introduction To Video Compression
PDF
10.1.1.184.6612
PPT
COMPRESSION MODELSCOMPRESSION MODELSCOMPRESSION MODELS
PDF
Lec 04.4_Video compression standards_H.264 Only_Intra_InterModes_OK_Tham khao...
PPT
Video Compression Demystified - Intro to MPEG, AVI, WMV
PPTX
PDF
Overview_of_H.264.pdf
High Efficiency Video Codec
Introduction to Video Compression Techniques - Anurag Jain
H.265ImprovedCE_over_H.264-HarmonicMay2014Final
Video compression
Are Video Codecs... Done?
An Introduction to Versatile Video Coding (VVC) for UHD, HDR and 360 Video
Compression
Compression
Video Compression Basics by sahil jain
Media Encoding
MPEG-1 Part 2 Video Encoding
Introduction To Video Compression
Introduction To Video Compression
Introduction To Video Compression
10.1.1.184.6612
COMPRESSION MODELSCOMPRESSION MODELSCOMPRESSION MODELS
Lec 04.4_Video compression standards_H.264 Only_Intra_InterModes_OK_Tham khao...
Video Compression Demystified - Intro to MPEG, AVI, WMV
Overview_of_H.264.pdf
Ad

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Spectroscopy.pptx food analysis technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
Teaching material agriculture food technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Advanced methodologies resolving dimensionality complications for autism neur...
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Building Integrated photovoltaic BIPV_UPV.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Understanding_Digital_Forensics_Presentation.pptx
cuic standard and advanced reporting.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectroscopy.pptx food analysis technology
Machine learning based COVID-19 study performance prediction
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Teaching material agriculture food technology
Big Data Technologies - Introduction.pptx
Electronic commerce courselecture one. Pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Programs and apps: productivity, graphics, security and other tools
Per capita expenditure prediction using model stacking based on satellite ima...
Ad

How video codec work