您的位置:首页 > 其它

FFMPEG结构体分析 AVFormatContext

2014-10-21 17:34 417 查看
AVFormatContext是包含码流参数较多的结构体。

在使用FFMPEG进行开发的时候,AVFormatContext是一个贯穿始终的数据结构,很多函数都要用到它作为参数。它是FFMPEG解封装(flv,mp4,rmvb,avi)功能的结构体。下面看几个主要变量的作用(在这里考虑解码的情况):

struct AVInputFormat *iformat:    输入数据的封装格式

AVIOContext *pb:
输入数据的缓存

unsigned int nb_streams:           视音频流的个数

AVStream **streams:                  视音频流

char filename[1024]:                  文件名

int64_t duration:                         时长(单位:微秒ms,转换为秒需要除以1000000)

int bit_rate:                                 比特率(单位bps,转换为kbps需要除以1000)

AVDictionary *metadata:            元数据

视频的时长可以转换成HH:MM:SS的形式,示例代码如下:

[cpp] view
plaincopy

AVFormatContext *pFormatCtx;  

CString timelong;  

...  

//duration是以微秒为单位  

//转换成hh:mm:ss形式  

int tns, thh, tmm, tss;  

tns  = (pFormatCtx->duration)/1000000;  

thh  = tns / 3600;  

tmm  = (tns % 3600) / 60;  

tss  = (tns % 60);  

timelong.Format("%02d:%02d:%02d",thh,tmm,tss);  

视频的原数据(metadata)信息可以通过AVDictionary获取。元数据存储在AVDictionaryEntry结构体中,如下所示

[cpp] view
plaincopy

typedef struct AVDictionaryEntry {  

    char *key;  

    char *value;  

} AVDictionaryEntry;  

每一条元数据分为key和value两个属性。

在ffmpeg中通过av_dict_get()函数获得视频的原数据。

下列代码显示了获取元数据并存入meta字符串变量的过程,注意每一条key和value之间有一个"\t:",value之后有一个"\r\n"

[cpp] view
plaincopy

//MetaData------------------------------------------------------------  

//从AVDictionary获得  

//需要用到AVDictionaryEntry对象  

//CString author,copyright,description;  

CString meta=NULL,key,value;  

AVDictionaryEntry *m = NULL;  

//不用一个一个找出来  

/*  m=av_dict_get(pFormatCtx->metadata,"author",m,0); 

author.Format("作者:%s",m->value); 

m=av_dict_get(pFormatCtx->metadata,"copyright",m,0); 

copyright.Format("版权:%s",m->value); 

m=av_dict_get(pFormatCtx->metadata,"description",m,0); 

description.Format("描述:%s",m->value); 

*/  

//使用循环读出  

//(需要读取的数据,字段名称,前一条字段(循环时使用),参数)  

while(m=av_dict_get(pFormatCtx->metadata,"",m,AV_DICT_IGNORE_SUFFIX)){  

    key.Format(m->key);  

    value.Format(m->value);  

    meta+=key+"\t:"+value+"\r\n" ;  

}  

转载地址:http://blog.csdn.net/leixiaohua1020/article/details/14214705
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ffmpeg AVFormatContext