SpaceWire UK
Specialist providers of VHDL Intellectual Property & Design Services
A Brief Introduction to Digital Video
This page provides a brief introduction to the BT656 (4:2:2) YCbCr Standard Definition 8-bit Digital Video format. By no means does it describe the full video standard in detail, it mealy introduces the subject matter from an implementation perspective.
Frames
A full frame of interlaced video consists of two almost identical fields. The first field contains all the odd video lines and the second field contains all the even video lines.
Fields
A field is made up of three distinct regions, first blanking period, active video and second blanking period. The difference between the first field and the second, is merely in the number lines during the first blanking period, the first field having one less than the second.
A complete NTSC/PAL video frame (both fields) is shown below: -
Lines |
Field / VBlk |
Line Description |
PAL |
NTSC |
F |
V |
22 |
19 |
'0' |
'1' |
Field 1 - First Vertical Blanking (Top) |
288 |
240 |
'0' |
'0' |
Field 1 - Active Video |
2 |
3 |
'0' |
'1' |
Field 1 - Second Vertical Blanking (Bottom) |
23 |
20 |
'1' |
'1' |
Field 2 - First Vertical Blanking (Top) |
288 |
240 |
'1' |
'0' |
Field 2 - Active Video |
2 |
3 |
'1' |
'1' |
Field 2 - Second Vertical Blanking (Bottom) |
625 |
525 |
|
There are two very important values to remember here, these being F (Field Number) and V (Vertical Blanking). These values control the vertical position of a line.
A logic zero on F states that a line belongs in Field 1, likewise a logic one on F states that a line belongs in Field 2.
A logic zero on V states that a line is part of the Active Video, whereas a logic one on V states that a line is part of the Vertical Blanking.
Lines
Lines consist of four parts, EAV Code, Blanking Video, SAV Code and Active Video. These are shown below: -
EAV Code |
Blanking Video |
SAV Code |
Active Video |
255 |
0 |
0 |
EAV |
Cb |
Y |
Cr |
Y |
255 |
0 |
0 |
SAV |
Cb |
Y |
Cr |
Y |
4 Bytes |
280 (268) Bytes |
4 Bytes |
1440 Bytes |
The EAV (End Active Video) and SAV (Start Active Video) Codes are made up of four bytes. The first three bytes provide the video synchronization and the last one byte provides the line coding.
What has not been discussed so far is H, the Horizontal Blanking value, this is a logic one during the EAV Code, Blanking Video and SAV Code, then becomes a logic zero for the duration of Active Video.
Note: The above description of Horizontal Blanking indicates that the H value of SAV is a logic one, this however is not the case. The H value of SAV should be a logic zero, even though the H value itself will be a logic one at this point. Care should be taken when implementing this logic!!
Both the EAV and SAV bytes are constructed in exactly the same way, as shown below: -
Bit: |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Value: |
'1' |
F |
V |
H |
V xor H |
F xor H |
F xor V |
F xor V xor H |
The Exclusive-OR components of these bytes can be used to detect and correct errors in the F, V and H values. Both one and two bit errors can be corrected by these components.
The Blanking Video period of a line consists of 280 bytes (PAL) or 268 bytes (NTSC) and the Active Video period of a line consists of 1440 bytes (PAL & NTSC). What these bytes represent is a repeated sequence of, Cb, Y, Cr, Y, where: -
Y |
= |
Brightness (Nominal Range 16-235) |
Cb |
= |
Blue Chrominance (Nominal Range 16-240) |
Cr |
= |
Red Chrominance (Nominal Range 16-240) |
The YCbCr colour space is very different from the RGB colour space, but sometimes it is useful to convert between the two. The formulae for these conversions are given below: -
Y |
= |
16 |
+ |
0.257R |
+ |
0.504G |
+ |
0.098B |
Cb |
= |
128 |
- |
0.148R |
- |
0.291G |
+ |
0.439B |
Cr |
= |
128 |
+ |
0.439R |
- |
0.368G |
- |
0.071B |
R |
= |
1.164(Y - 16) |
+ |
1.596(Cr - 128) |
|
G |
= |
1.164(Y - 16) |
- |
0.813(Cr - 128) |
- |
0.391(Cb - 128) |
B |
= |
1.164(Y - 16) |
+ |
2.018(Cb - 128) |
|
These formulae convert R(0-255), G(0-255), B(0-255) into Y(16-235), Cb(16-240), Cr(16-240) and visa-versa.
For every two Y values there is only one Cb and Cr value, this means that care must be taken when converting from RGB. Many sampling techniques exist for performing this conversion, the simplest two are based on converting one or two pixels at a time, these are given below: -
One Pixel Interleave
The above conversion formulae are used to convert one RGB pixel at a time, using only the Blue Chrominance for the even pixels and the Red Chrominance for the odd pixels: -
Pixel 1: |
Y |
= |
16 |
+ |
0.257R0 |
+ |
0.504G0 |
+ |
0.098B0 |
|
Cb |
= |
128 |
- |
0.148R0 |
- |
0.291G0 |
+ |
0.439B0 |
|
Pixel 2: |
Y |
= |
16 |
+ |
0.257R1 |
+ |
0.504G1 |
+ |
0.098B1 |
|
Cr |
= |
128 |
+ |
0.439R1 |
- |
0.368G1 |
- |
0.071B1 |
The final result: (R0, G0, B0), (R1, G1, B1) to (Cb0, Y0), (Cr1, Y1), etc.
Two Pixel Average
The above conversion formulae are used to convert two RGB pixels at a time, the Blue and Red Chrominance values are then averaged to obtain the final chrominance values: -
Pixel 1: |
Y0 |
= |
16 |
+ |
0.257R0 |
+ |
0.504G0 |
+ |
0.098B0 |
|
Cb0 |
= |
128 |
- |
0.148R0 |
- |
0.291G0 |
+ |
0.439B0 |
|
Cr0 |
= |
128 |
+ |
0.439R0 |
- |
0.368G0 |
- |
0.071B0 |
|
Pixel 2: |
Y1 |
= |
16 |
+ |
0.257R1 |
+ |
0.504G1 |
+ |
0.098B1 |
|
Cb1 |
= |
128 |
- |
0.148R1 |
- |
0.291G1 |
+ |
0.439B1 |
|
Cr1 |
= |
128 |
+ |
0.439R1 |
- |
0.368G1 |
- |
0.071B1 |
|
Average: |
Cb01 |
= |
(Cb0 + Cb1) / 2 |
|
Cr01 |
= |
(Cr0 + Cr1) / 2 |
The final result: (R0, G0, B0), (R1, G1, B1) to (Cb01, Y0, Cr01, Y1), etc.
The Complete Picture
The simplest video screen to create is a flood filled screen of one colour, for this the Y, Cb and Cr values need to be calculated for that colour, this is shown below: -
For a bright blue colour the RGB values are, Red=0, Green=0 and Blue=255. By using the above conversion formulae the YCbCr values can be obtained: -
Y |
= |
16 |
+ |
0.257(0) |
+ |
0.504(0) |
+ |
0.098(255) |
= |
41 |
Cb |
= |
128 |
- |
0.148(0) |
- |
0.291(0) |
+ |
0.439(255) |
= |
240 |
Cr |
= |
128 |
+ |
0.439(0) |
- |
0.368(0) |
- |
0.071(255) |
= |
110 |
It is customary in video to produce black pixels during the blanking periods, when auxiliary data such has sound and teletext are not being transmitted. Again by using the conversion formulae the YCbCr values can be obtained: -
Y |
= |
16 |
+ |
0.257(0) |
+ |
0.504(0) |
+ |
0.098(0) |
= |
16 |
Cb |
= |
128 |
- |
0.148(0) |
- |
0.291(0) |
+ |
0.439(0) |
= |
128 |
Cr |
= |
128 |
+ |
0.439(0) |
- |
0.368(0) |
- |
0.071(0) |
= |
128 |
Using the Frame, Field and Line descriptions above, a complete screen of blue video can be built up. An example of this is shown below for a PAL screen (NTSC values are shown in parenthesis): -
Field 1 - First Vertical Blanking (Top) - Repeat for 22 (19) lines |
EAV Code |
Blanking Video |
SAV Code |
Active Video |
255 |
0 |
0 |
182 |
128 |
16 |
128 |
16 |
255 |
0 |
0 |
171 |
128 |
16 |
128 |
16 |
Repeat 1 (1) time |
Repeat 70 (67) times |
Repeat 1 (1) time |
Repeat 360 (360) times |
Field 1 - Active Video - Repeat for 288 (240) lines |
EAV Code |
Blanking Video |
SAV Code |
Active Video |
255 |
0 |
0 |
157 |
128 |
16 |
128 |
16 |
255 |
0 |
0 |
128 |
240 |
41 |
110 |
41 |
Repeat 1 (1) time |
Repeat 70 (67) times |
Repeat 1 (1) time |
Repeat 360 (360) times |
Field 1 - Second Vertical Blanking (Bottom) - Repeat for 2 (3) lines |
EAV Code |
Blanking Video |
SAV Code |
Active Video |
255 |
0 |
0 |
182 |
128 |
16 |
128 |
16 |
255 |
0 |
0 |
171 |
128 |
16 |
128 |
16 |
Repeat 1 (1) time |
Repeat 70 (67) times |
Repeat 1 (1) time |
Repeat 360 (360) times |
Field 2 - First Vertical Blanking (Top) - Repeat for 23 (20) lines |
EAV Code |
Blanking Video |
SAV Code |
Active Video |
255 |
0 |
0 |
241 |
128 |
16 |
128 |
16 |
255 |
0 |
0 |
236 |
128 |
16 |
128 |
16 |
Repeat 1 (1) time |
Repeat 70 (67) times |
Repeat 1 (1) time |
Repeat 360 (360) times |
Field 2 - Active Video - Repeat for 288 (240) lines |
EAV Code |
Blanking Video |
SAV Code |
Active Video |
255 |
0 |
0 |
218 |
128 |
16 |
128 |
16 |
255 |
0 |
0 |
199 |
240 |
41 |
110 |
41 |
Repeat 1 (1) time |
Repeat 70 (67) times |
Repeat 1 (1) time |
Repeat 360 (360) times |
Field 2 - Second Vertical Blanking (Bottom) - Repeat for 2 (3) lines |
EAV Code |
Blanking Video |
SAV Code |
Active Video |
255 |
0 |
0 |
241 |
128 |
16 |
128 |
16 |
255 |
0 |
0 |
236 |
128 |
16 |
128 |
16 |
Repeat 1 (1) time |
Repeat 70 (67) times |
Repeat 1 (1) time |
Repeat 360 (360) times |
Colour Bars
When developing video solutions the first port of call is usually the colour bar test pattern. This is constructed from equal width vertical stripes of white, yellow, cyan, green, magenta, red, blue and black. Converting these colours from RGB to YCbCr is a very simple process of using the above formulae, the end results are shown below: -
|
RGB Colour Bars |
YCbCr Colour Bars |
R |
G |
B |
Y |
Cb |
Cr |
White |
255 |
255 |
255 |
235 |
128 |
128 |
Yellow |
255 |
255 |
0 |
210 |
16 |
146 |
Cyan |
0 |
255 |
255 |
170 |
166 |
16 |
Green |
0 |
255 |
0 |
145 |
54 |
34 |
Magenta |
255 |
0 |
255 |
107 |
202 |
222 |
Red |
255 |
0 |
0 |
82 |
90 |
240 |
Blue |
0 |
0 |
255 |
41 |
240 |
110 |
Black |
0 |
0 |
0 |
16 |
128 |
128 |
To create a colour bar test screen, a simple substitution is required in the complete picture example. This is performed on the Field 1 and Field 2 Active Video lines, during the Active Video portion of the line. Instead of the repeated sequence of 240, 41, 110, 41 the following sequence is used: -
White |
Yellow |
Cyan |
Green |
128 |
235 |
128 |
235 |
16 |
210 |
146 |
210 |
166 |
170 |
16 |
170 |
54 |
145 |
34 |
145 |
Repeat 45 times |
Repeat 45 times |
Repeat 45 times |
Repeat 45 times |
Magenta |
Red |
Blue |
Black |
202 |
107 |
222 |
107 |
90 |
82 |
240 |
82 |
240 |
41 |
110 |
41 |
128 |
16 |
128 |
16 |
Repeat 45 times |
Repeat 45 times |
Repeat 45 times |
Repeat 45 times |