A Brief Introduction to Digital Video

来源:互联网 发布:个性彩铃制作软件 编辑:程序博客网 时间:2024/04/20 08:43

转自http://www.spacewire.co.uk/video_standard.html

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: -

LinesField / VBlkLine
Description
PALNTSCFV2219'0''1'Field 1 - First Vertical Blanking (Top)288240'0''0'Field 1 - Active Video23'0''1'Field 1 - Second Vertical Blanking (Bottom)2320'1''1'Field 2 - First Vertical Blanking (Top)288240'1''0'Field 2 - Active Video23'1''1'Field 2 - Second Vertical Blanking (Bottom)625525 
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 CodeBlanking VideoSAV CodeActive Video25500EAVCbYCrY25500SAVCbYCrY4 Bytes280 (268) Bytes4 Bytes1440 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:76543210Value:'1'FVHV xor HF xor HF xor VF 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.098BCb=128-0.148R-0.291G+0.439BCr=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)=41Cb=128-0.148(0)-0.291(0)+0.439(255)=240Cr=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)=16Cb=128-0.148(0)-0.291(0)+0.439(0)=128Cr=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) linesEAV CodeBlanking VideoSAV CodeActive Video255001821281612816255001711281612816Repeat 1 (1) timeRepeat 70 (67) timesRepeat 1 (1) timeRepeat 360 (360) times
Field 1 - Active Video - Repeat for 288 (240) linesEAV CodeBlanking VideoSAV CodeActive Video255001571281612816255001282404111041Repeat 1 (1) timeRepeat 70 (67) timesRepeat 1 (1) timeRepeat 360 (360) times
Field 1 - Second Vertical Blanking (Bottom) - Repeat for 2 (3) linesEAV CodeBlanking VideoSAV CodeActive Video255001821281612816255001711281612816Repeat 1 (1) timeRepeat 70 (67) timesRepeat 1 (1) timeRepeat 360 (360) times
Field 2 - First Vertical Blanking (Top) - Repeat for 23 (20) linesEAV CodeBlanking VideoSAV CodeActive Video255002411281612816255002361281612816Repeat 1 (1) timeRepeat 70 (67) timesRepeat 1 (1) timeRepeat 360 (360) times
Field 2 - Active Video - Repeat for 288 (240) linesEAV CodeBlanking VideoSAV CodeActive Video255002181281612816255001992404111041Repeat 1 (1) timeRepeat 70 (67) timesRepeat 1 (1) timeRepeat 360 (360) times
Field 2 - Second Vertical Blanking (Bottom) - Repeat for 2 (3) linesEAV CodeBlanking VideoSAV CodeActive Video255002411281612816255002361281612816Repeat 1 (1) timeRepeat 70 (67) timesRepeat 1 (1) timeRepeat 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 BarsYCbCr Colour BarsRGBYCbCrWhite255255255235128128Yellow255255021016146Cyan025525517016616Green025501455434Magenta2550255107202222Red255008290240Blue0025541240110Black00016128128
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: -

WhiteYellowCyanGreen12823512823516210146210166170161705414534145Repeat 45 timesRepeat 45 timesRepeat 45 timesRepeat 45 times
MagentaRedBlueBlack20210722210790822408224041110411281612816Repeat 45 timesRepeat 45 timesRepeat 45 timesRepeat 45 times