avi视频协议的理解

可以把avi文件理解为由无数个struct结构组成的:

  1. struct avifile { 'RIFF', 'AVI', struct. movi, struct hdrl}

  2. struct hdrl { 'LIST', 'hdal', struct avih, struct stream0,struct stream1,struct stream2};

  3. struct stream {'LIST' , 'STRL', struct strh, struct strf }

  4. struct movi { 'LIST' , 'movi'}

  5. n* struct data { '00db' ,data} 循环写入帧数据

在avi文件中都是按照这个镶嵌顺序顺序写入的。

  1. avifile:

struct avifile

{

unsigned char id[4];

unsigned int size;

unsigned char type[4];

struct. movi;

struct hdrl avi_hdrl;

}

  1. struct hdrl

typedef struct hdrl

{

unsigned char id[4]; //块ID,固定为LIST

unsigned int size; //块大小,等于struct avi_hdrl_list去掉id和size的大小

unsigned char type[4]; //块类型,固定为hdrl

struct avih;

struct stream;

}

  1. struct avih

struct avih

{

unsigned char id[4]; //块ID,固定为avih

unsigned int size; //块大小,等于struct avi_avih_chunk去掉id和size的大小

unsigned int us_per_frame; //视频帧间隔时间(以微秒为单位)

unsigned int max_bytes_per_sec; //AVI文件的最大数据率

unsigned int padding; //设为0即可

unsigned int flags; //AVI文件全局属性,如是否含有索引块、音视频数据是否交叉存储等

unsigned int total_frames; //总帧数

unsigned int init_frames; //为交互格式指定初始帧数(非交互格式应该指定为0)

unsigned int streams; //文件包含的流的个数,仅有视频流时为1

unsigned int suggest_buff_size; //指定读取本文件建议使用的缓冲区大小,通常为存储一桢图像 //以及同步声音所需的数据之和,不指定时设为0

unsigned int width; //视频主窗口宽度(单位:像素)

unsigned int height; //视频主窗口高度(单位:像素)

unsigned int reserved[4]; //保留段,设为0即可

}

4 . 含两个struct strh,struct strf

struct stream {

struct strh

{

unsigned char id[4]; //块ID,固定为strh

unsigned int size; //块大小,等于struct avi_strh_chunk去掉id和size的大小

unsigned char stream_type[4]; //流的类型,vids表示视频流,auds表示音频流

unsigned char codec[4]; //指定处理这个流需要的解码器,如JPEG

unsigned int flags; //标记,如是否允许这个流输出、调色板是否变化等,一般设为0即可

unsigned short priority; //流的优先级,视频流设为0即可

unsigned short language; //音频语言代号,视频流设为0即可

unsigned int init_frames; //为交互格式指定初始帧数(非交互格式应该指定为0)

unsigned int scale; //

unsigned int rate; //对于视频流,rate / scale = 帧率fps

unsigned int start; //对于视频流,设为0即可

unsigned int length; //对于视频流,length即总帧数

unsigned int suggest_buff_size; //读取这个流数据建议使用的缓冲区大小

unsigned int quality; //流数据的质量指标

unsigned int sample_size; //音频采样大小,视频流设为0即可

AVI_RECT_FRAME rcFrame; //这个流在视频主窗口中的显示位置,设为{0,0,width,height}即可

},

struct strf

{

unsigned char id[4]; //块ID,固定为strf

unsigned int size; //块大小,等于struct avi_strf_chunk去掉id和size的大小

unsigned int size1; //size1含义和值同size一样

unsigned int width; //视频主窗口宽度(单位:像素)

unsigned int height; //视频主窗口高度(单位:像素)

unsigned short planes; //始终为1

unsigned short bitcount; //每个像素占的位数,只能是1、4、8、16、24和32中的一个

unsigned char compression[4]; //视频流编码格式,如JPEG、MJPG等

unsigned int image_size; //视频图像大小,等于width * height * bitcount / 8

unsigned int x_pixels_per_meter; //显示设备的水平分辨率,设为0即可

unsigned int y_pixels_per_meter; //显示设备的垂直分辨率,设为0即可

unsigned int num_colors; //含义不清楚,设为0即可

unsigned int imp_colors; //含义不清楚,设为0即可

}

}

typedef struct avi_rect_frame

{

short left;

short top;

short right;

short bottom;

}AVI_RECT_FRAME;

上面的4个结构体都是镶嵌的,在文件中都是顺序写入的,甚至可以把这几个组织称一个 struct

  1. struct movi

struct movi

{

unsigned char id[4]; //块ID,固定为LIST

unsigned int size;

unsigned char type[4]; //固定为MOVI

}

  1. 写data

struct data {

unsigned char id[4]; // 00dc 表示第一个流为视频压缩数据

unsigned int len; // 每帧数据大小

void *data ; //数据

}

最后写数据可以理解为是struct,但不用结构处理,而是直接先写4字节的00dc, 再写文件长度,最后直接写入帧数据,这样就完成一帧图片的写入,前面的几个结构需要全部要写入的总帧数和总字节数,都是在最后写入数据完成后再回写回去的。

相关推荐
阿白的白日梦1 天前
winget基础管理---更新/修改源为国内源
windows
埃博拉酱5 天前
VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传
windows·ssh·visual studio code
唐宋元明清21886 天前
.NET 本地Db数据库-技术方案选型
windows·c#
加号36 天前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql
tryCbest6 天前
Windows环境下配置pip镜像源
windows·pip
REDcker6 天前
WebCodecs VideoDecoder 的 hardwareAcceleration 使用
前端·音视频·实时音视频·直播·webcodecs·videodecoder
呉師傅6 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
gihigo19986 天前
基于TCP协议实现视频采集与通信
网络协议·tcp/ip·音视频
百事牛科技6 天前
保护文档安全:PDF限制功能详解与实操
windows·pdf
一个人旅程~6 天前
如何用命令行把win10/win11设置为长期暂停更新?
linux·windows·经验分享·电脑