好久没有写有关视频的东西了。前两周一个学习说要做视频相关的实验,就开了个题,用S3C2410实现H263视频会议。同时,也希望通过把这个开发过程写下来,汇聚了下个系列。
要完成H263的视频解压,而要完成视频的解压缩,又必须完成QCIF文件的播放。下面的播放器程的主程序。
1

#include <stdio.h>
2

#include <stdlib.h>
3

#include <fcntl.h>
4

#include <unistd.h>
5

#include <string.h>
6

#include <sys/ioctl.h>
7

8

#include "fbtools.h"
9

#include "convert.h"
10

#include "read_image.h"
11

12

#define PELS (176)
13

#define LINES (144)
14

#define TRUE 1
15

#define FALSE 0
16

17

int main(int argc, char **argv)
18



{
19

FBDEV fbdev;
20

unsigned char *Y, *Cb, *Cr;
21

char *image;
22

int i;
23

24

if (argc != 2)
25


{
26

printf("Usage:\n\t%s <Qcif file>\n", argv[0]);
27

exit(-1);
28

}
29
30

memset(&fbdev, 0, sizeof(FBDEV));
31

strcpy(fbdev.dev, "/dev/fb/0");
32

if(fb_open(&fbdev)==FALSE)
33


{
34

printf("open frame buffer error\n");
35

return;
36

}
37

38

//write screen
39

fb_memset((void *)(fbdev.fb_mem + fbdev.fb_mem_offset), 0, fbdev.fb_fix.smem_len);
40

41

//draw a red line
42

fb_drawHLine(&fbdev, 2, 0xff, 0x00, 0x00);
43

fb_drawHLine(&fbdev, 3, 0xff, 0x00, 0x00);
44

45

//draw a green line
46

fb_drawHLine(&fbdev, 5, 0x00, 0xff, 0x00);
47

fb_drawHLine(&fbdev, 6, 0x00, 0xff, 0x00);
48

49

//draw a blue line
50

fb_drawHLine(&fbdev, 8, 0x00, 0x00, 0xff);
51

fb_drawHLine(&fbdev, 9, 0x00, 0x00, 0xff);
52

53

54

//draw a yellow line
55

fb_drawHLine(&fbdev, 11, 0xff, 0xff, 0x00);
56

fb_drawHLine(&fbdev, 12, 0xff, 0xff, 0x00);
57

58

getchar();
59

//druck screen
60

fb_memset((void *)(fbdev.fb_mem + fbdev.fb_mem_offset), 0, fbdev.fb_fix.smem_len);
61

InitConvertTable();
62

63

for(i=0; i<500; i++)
64


{
65

image = read_image(&Y, &Cb, &Cr, argv[1], i, 0);
66

ConvertYUV2RGB565(Y, Cb, Cr,(unsigned char *)(fbdev.fb_mem + fbdev.fb_mem_offset),
67

PELS, LINES, fbdev.fb_fix.line_length);
68

usleep(33);
69

}
70

71

free_image(image);
72

fb_close(&fbdev);
73

}
74

75

* QCIF全称Quarter common intermediate format。QCIF是常用的标准化图像格式。在H.323协议簇中,规定了视频采集设备的标准采集分辨率。QCIF = 176×144像素。
一、QCIF图像的贮存格式如下
YYYYYYYY...(一共176*144字节)
CbCbCbCbCb...(一共176*144/4字节)
CrCrCrCrCr...(一共176*144/4字节)
二、QCIF数据和像数点的关系
1. QCIF数据逻辑关系如下
Y1 Y2 Y3 Y ...
Cb1Cr1 Cb2Cr2 ...
Y4 Y5 Y6 Y..
Y7 Y8 Y9 Y ...
Cb3Cr3 Cb4Cr4 ...
Y.. ... Y... Y... ... Y...
2. 对应的点数据
Point1 = F(Y1, Cb1, Cr1)
Point2 = F(Y2, Cb1, Cr1)
Point3 = F(Y3, Cb2, Cr2)
Point4 = F(Y4, Cb1, Cr1)
Point5 = F(Y5, Cb1, Cr1)
Point6 = F(Y6, Cb2, Cr2)
Point7 = F(Y7, Cb3, Cr3)
Point8 = F(Y8, Cb3, Cr3)
Point9 = F(Y9, Cb4, Cr4)
3.计算公式
在COLOUR SPACES .17 ITU-R recommendation BT.601 中,建议在计算Y时,权重选择为kr=0.299,kg=0.587,kb=0.114。于是常用的转换公式如下:
Y = 0.299R + 0.587G + 0.114B
Cb = 0.564(B - Y )
Cr = 0.713(R - Y )
R = Y + 1.402Cr
G = Y - 0.344Cb - 0.714Cr
B = Y + 1.772Cb
不过这里面的YUV TO RGB的算法,效率实在是低,因为里面有了浮点运算,解一帧176*144的图像大概需要400ms左右,这是无法忍受的,如果消除浮点运算,只需要10ms左右,效率的提升真是无法想象
关于YUV的格式规定详情,请看http://www.fourcc.org/fccyvrgb.php或http://www.chinavideo.org/index.php?option=com_content&task=view&id=151&Itemid=5
完成的程序请在如下地址下载。完整代码