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, 再写文件长度,最后直接写入帧数据,这样就完成一帧图片的写入,前面的几个结构需要全部要写入的总帧数和总字节数,都是在最后写入数据完成后再回写回去的。

相关推荐
love530love4 分钟前
【SD WebUI踩坑】启动报错 Expecting value: line 1 column 1 (char 0) 的终极解决方案
人工智能·windows·python·github·stablediffusion
爱宇阳10 分钟前
使用 PowerShell + ffmpeg 自动压缩视频(支持 CRF、无损、目标大小模式)
ffmpeg·音视频
spencer_tseng11 分钟前
Microsoft Edge extensions
microsoft·edge
繁华似锦respect21 分钟前
C++ 设计模式之代理模式详细介绍
linux·开发语言·c++·windows·设计模式·代理模式·visual studio
獨枭9 小时前
Windows 10/11 把更新彻底禁用
windows
天才程序YUAN10 小时前
从零开始、保留 Windows 数据、安装Ubuntu 22.04 LTS双系统
linux·windows·ubuntu
0***h94210 小时前
Windows 11 如何配置node.js
windows·node.js
n***632711 小时前
DeepSeek API 调用 - Spring Boot 实现
windows·spring boot·后端
I***261512 小时前
Windows环境下安装Redis并设置Redis开机自启
数据库·windows·redis
枫叶丹413 小时前
【Qt开发】Qt窗口(三) -> QStatusBar状态栏
c语言·开发语言·数据库·c++·qt·microsoft