2.AVFormatContext和AVInputFormat
AVFormatContext: 用来存储视音频封装格式(flv,mp4,rmvb,avi)中包含的全部信息 不少函数都要用到它做为参数。ide
AVFormatContext结构体以下所示(显示部分红员,后续深刻添加):函数
typedef struct AVFormatContext {
const AVClass *av_class; //包含AVCodecContext, AVFormatContext
/**
* The input container format.
*
* Demuxing only, set by avformat_open_input().
*/
ff_const59 struct AVInputFormat *iformat; //AVInputFormat:封装格式(flv、mkv、avi等),调用avformat_open_input()时,该成员就会被初始化
ff_const59 struct AVOutputFormat *oformat; //输入的封装格式(生成视频),调用avformat_write_header()时,该成员就会被初始化
unsigned int nb_streams; //AVFormatContext中的流个数,通常为2,若是要设置,则只能经过avformat_new_stream()来设置
AVStream **streams; //输入视频的AVStream流数组,经过avformat_open_input()来初始化流信息
#if FF_API_FORMAT_FILENAME
attribute_deprecated
char filename[1024]; //输入输出文件名路径,经过avformat_open_input()和avformat_write_header()来设置
#endif
char *url; //输入或输出URL,与filename字段不一样,此字段没有长度限制。经过avformat_open_input()和avformat_write_header()来设置
/**
* Position of the first frame of the component, in
* AV_TIME_BASE fractional seconds. NEVER set this value directly:
* It is deduced from the AVStream values.
*
* Demuxing only, set by libavformat.
*/
int64_t start_time; //第一帧的时间位置,通常为0
int64_t duration; //输入视频总时长,以微妙为单位,换算以秒为单位: duration/AV_TIME_BASE
/**
* Total stream bitrate in bit/s, 0 if not
* available. Never set it directly if the file_size and the
* duration are known as FFmpeg can compute it automatically.
*/
int64_t bit_rate; //输入视频的码率,单位为bit/s
unsigned int packet_size;
int max_delay;
const uint8_t *key;
int keylen;
unsigned int nb_programs;
AVProgram **programs;
enum AVCodecID video_codec_id; //须要强制设置的视频编码id,默认为0,自动设置
enum AVCodecID audio_codec_id; //须要强制设置的音频编码id,默认为0,自动设置
enum AVCodecID subtitle_codec_id;//须要强制设置的字幕编码id,默认为0,自动设置
AVDictionary *metadata; //整个文件的元数据,能够经过经过av_dict_get()函数得到视频的原数据,AVDictionary包含两个成员key和value
//使用循环读出
//(须要读取的数据,字段名称,前一条字段(循环时使用),参数)
//while(m=av_dict_get(pFormatCtx->metadata,"",m,AV_DICT_IGNORE_SUFFIX)){
// key.Format(m->key);
// value.Format(m->value);
// qDebug()<<"key-value:"<
其中iformat成员就是指向视频/音频流的封装格式(flv、mkv、avi等)具体结构体的指针.ui
该成员的AVInputFormat结构体以下所示(显示部分红员,后续深刻添加):this
typedef struct AVInputFormat
{
const char *name; // 封装格式的名字, 好比,“mov” “mp4” 等。
const char *long_name; ///封装格式的长名字
//标示具体的format对应的Context 的size,如:MovContext。
const char *extensions; //扩展名,若是定义了, 则不执行探测视频格式, 一般不使用扩展格式猜想,由于不可靠
//具体的操做函数
int(*read_probe)(AVProbeData*);
int(*read_header)(struct AVFormatContext *,AVFormatParameters *ap);
int(*read_packet)(struct AVFormatContext *, AVPacket *pkt);
int(*read_close)(struct AVFormatContext*);
struct AVInputFormat *next;
} AVInputFormat