#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static int q=0;
static int sp=0;
static int aq=0;
//static int at=0;
static unsigned int vzj=0;
static unsigned int azj=0;
int main(void){
struct file{
struct riff{
char id[4];
unsigned int size;
char type[4];
struct hdrl{
char id[4];
unsigned int size;
unsigned char type[4];
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; //指定读取本文件建议使用的缓冲区大小,通常为存储一桢图像
unsigned int width; //视频主窗口宽度(单位:像素)
unsigned int height; //视频主窗口高度(单位:像素)
unsigned int reserved[4]; //保留段,设为0即可
}av;
struct strl{
unsigned char id[4]; //块ID,固定为LIST
unsigned int size; //块大小,等于struct avi_strl_list去掉id和size的大小
unsigned char type[4]; //strl
struct strh1{
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即可
short left; //这个流在视频主窗口中的显示位置,设为{0,0,width,height}即可
short top;
short right;
short bottom;
}sh1;
struct strf1{
unsigned char id[4]; //块ID,固定为strf
unsigned int size; //块大小,等于struct avi_strf_chunk去掉id和size的大小
//_BITMAPINFOHEADER 结构
int 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]; //指定压缩的自下而上位图的压缩类型
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即可
}sf1;
}sl1;
struct strl2{
unsigned char id[4]; //块ID,固定为LIST
unsigned int size; //块大小,等于struct avi_strl_list去掉id和size的大小
unsigned char type[4]; //strl
struct strh2{
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即可
short left; //这个流在视频主窗口中的显示位置,设为{0,0,width,height}即可
short top;
short right;
short bottom;
}sh2;
struct strf2{
char id[4]; //strf
int size;
short wFormatTag; //波形音频格式类型,格式标记在 Microsoft Corporation 中注册,用于许多压缩算法,
short nChannels; //声道数 85= WAVE_FORMAT_PCM
int nSamplesPerSec; //采样率,以每秒样本数 (赫) ,常见值为 8.0 kHz、11.025 kHz、22.05 kHz 和 44.1 kHz
int nAvgBytesPerSec; //格式标记所需的平均数据传输速率(以字节/秒为单位)=nsam*nblock
short nBlockAlign; //阻止对齐(以字节为单位),nBlockAlign 必须等于 nChannels 和 wBitsPerSample 的乘积除以 8 (位/字节)
short wBitsPerSample;// 如果 wFormatTag WAVE_FORMAT_PCM,则 wBitsPerSample 应等于 8 或 16
short biSize; //追加到 WAVEFORMATEX 结构末尾的额外格式信息的大小(以字节为单位)
}sf2;
}sl2;
}hd;
struct movi{
char id[4];
unsigned int size;
char type[4];
}mo;
}ri;
}head;
FILE *fo=fopen("/home/wzpc/Videos/demo.avi","w+b"); //生成avi
FILE *f=fopen("/home/wzpc/Videos/tra_mjpg.avi","rb"); //无声视频文件
FILE *af=fopen("/home/wzpc/Music/musicdemo.wav","r+b"); //wav 文件
fseek(fo,sizeof(head),SEEK_SET);
if(f==NULL){
puts("file_in error");
exit(-1);
}
if(af==NULL){
puts("file2_in error");
exit(-1);
}
fseek(f,0,SEEK_END);
int flen=ftell(f);
fseek(f,0,SEEK_SET);
fseek(af,0,SEEK_END);
int aflen=ftell(af);
fseek(af,0,SEEK_SET);
int tf=fileno(f);
int taf=fileno(af);
char *mf=mmap(NULL,flen,PROT_READ,MAP_SHARED,tf,0);
char *maf=mmap(NULL,aflen,PROT_READ,MAP_SHARED,taf,0);
for(int t=0;t
程序基本上可用,还没完全理解视频与音频交叉贮存。完善中。
此程序现在只能用ffplay打开,估计是文件头,和存储音视频数据还不完善。
编程中发现,头文件结构中很多参数要求很不严格,只有少数几个很重要,甚至结构中的结构长度的准确度也可以不严格。
其实,这个程序就是为后期的用摄像头录像,麦克风录音作准备的,此程序用的音频我就是用麦克风录制的。