在使用FFMPEG进行开发的时候,AVFormatContext是一个贯穿始终的数据结构,很多函数都要用到它作为参数。它是FFMPEG解封装(解复用)(flv,mp4,rmvb,avi)功能的结构体。
结构体参数:
const AVClass *av_class;// 与logging以及avoptions相关的class,由avformat_alloc_context()设置。
struct AVInputFormat *iformat;//输入容器格式,只用在解复用(demuxing only),由avformat_open_input()设置。(注意:它和 AVOutputFormat 同一时间只能存在一个)
struct AVOutputFormat *oformat;//输出容器格式,只用在复用(muxing only),必须在调用 avformat_write_header()之前设置。
void *priv_data;//格式私有数据, 在复用的时候由avformat_write_header()设置; demuxing:由avformat_open_input() 设置。
AVIOContext *pb;// I/O context. 在解复用时候,在avformat_open_input()调用之前设置,或者由avformat_open_input()设置;在复用时候,在avformat_write_header()之前由使用者设置。
/* 流信息 */
int ctx_flags;
unsigned int nb_streams;// 视音频流的个数,假设有3个,stream[0]是视频,stream[1]是音频,stream[2]是字幕。
**AVStream streams;//文件所有流的list,如果要创建新的流,可以通过avformat_new_stream()创建。
char filename[1024];//输入或者输出的文件名,解复用时候由avformat_open_input()设置,复用时候可以在avformat_write_header()之前设置。
int64_t start_time;//开始帧的位置,不要直接设置。只在解复用时候用到(Demuxing only)。
int64_t duration;//流的时长(单位:微秒us,转换为秒需要除以1000000)
int64_t bit_rate;//整个流的比特率 bit/s。(单位bps,转换为kbps需要除以1000)
unsigned int packeet_size;
int max_delay;
int flags;//Demuxer/Muxer的状态
//此处省略宏定义,在该段代码结束为止贴出
int64_t probesize;//通过AVInputFormat从输入流中读到数据的最大size,在avformat_open_input()之前设置,只在解复用使用(Demuxing only)。
int64_t max_analyze_duration;//从来自avformat_find_stream_info()输入流中读到数据的最大size,在avformat_find_stream_info()前设置。
const uint8_t *key;
int keylen;
unsigned int nb_programs;
AVProgram **programs;
enum AVCodecID video_codec_id;//视频编解码器id,在解码的时候由user设置
enum AVCodecID audio_codec_id;//音频编解码器id,在解码的时候由user设置
enum AVCodecID subtitle_codec_id;//字母编解码器id,在解码的时候由user设置
unsigned int max_index_size;//每条流的最大内存字节数
unsigned int max_picture_buffer;//Buffering frames的最大内存字节数
unsigned int nb_chapters;// AVChapters array的chapters的数量
AVChapter **chapters;
AVDictionary *metadata;//元数据
int64_t start_time_realtime;//起始时间,从PTS=0开始
int fps_probe_size;//用在avformat_find_stream_info()中,用于确定帧率,其值为帧数。只在解复用中。
int error_recognition;//错误检测
AVIOInterruptCB interrupt_callback;//自定义
int debug;//flags to enable debugging
#define FF_FDEBUG_TS 0x0001
int64_t max_interleave_delta;//最大交叉Buffering(缓冲数据)时长,在muxing(复用)时使用
int strict_std_compliance;//允许非标准拓展
int event_flags;// Flags for the user to detect events happening on the file.
int max_ts_probe;//解码第一帧(第一个时间戳)时读取的最大Packet数目
int avoid_negative_ts;//在复用(muxing)过程中避免无效的时间戳(timestamps)
#define AVFMT_AVOID_NEG_TS_AUTO -1 ///< Enabled when required by target format
#define AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE 1 ///< Shift timestamps so they are non negative
#define AVFMT_AVOID_NEG_TS_MAKE_ZERO 2 ///< Shift timestamps so that they start at 0
int ts_id;//ts(Transport)流的id
int audio_preload;// 音频提前加载,不是所有格式都支持
int max_chunk_duration;//最大chunk时长,不是所有格式都支持
int max_chunk_size;//最大chunk以字节为单位。不是所有格式都支持
int use_wallclock_as_timestamps;//强制使用wallclock时间戳作为数据包的pts/dts,如果有b帧存在会有未定义的结果出现
int avio_flags;
enum AVDurationEstimationMethod duration_estimation_method;//可以通过不同的方式估计持续时间字段
int64_t skip_initial_bytes;//当打开流的时候,跳过初始字节
unsigned int correct_ts_overflow;//纠正单个时间戳溢出
int seek2any;//强制seek到任一帧
int flush_packets;//在每个packet之后,刷新I/O Context
int probe_score;//格式探测评分,最大评分是AVPROBE_SCORE_MAX
int format_probesize;//读取最大的字节数来确定格式
char *codec_whitelist;//由’,'分隔的所有可用的decoder(解码器)
char *format_whitelist;//由‘,’分隔的所有可用的demuxers(解复用器)
AVFormatInternal *internal;//libavformat内部私有成员
int io_repositioned;//I/O 更改的标志
AVCodec *video_codec;// Forced video codec,特殊解码器或者相同codec_id的视频Codec
AVCodec *audio_codec;// Forced audio codec, 特殊解码器或者相同codec_id的音频Codec
AVCodec *subtitle_codec;//Forced subtitle codec, 特殊解码器或者相同codec_id的字幕Codec
AVCodec *data_codec;//Forced data codce,特殊解码器或者相同codec_id的数据Codec
int metadata_header_padding;//在metadata(元数据)头设置padding值
void *opaque;//用户私有数据
av_format_control_message control_message_cb;//设备和应用通信用的Callback
int64_t output_ts_offset;//输出时间戳偏移量
uint8_t *dump_separator;//转储分隔格式 可以是“,”或者“\n”或者其他
enum AVCodecId data_codec_id;//Forced Data codec_id
int (*open_cb)(struct AVFormatContext *s, AVIOContext **p, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options);//过时函数,用io_open_and_io_close代替
char *protocol_whitelist;//协议白名单,用’,'分隔
int (*io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url,
int flags, AVDictionary **options);//当I/O流打开时候,解复用操作的回调函数
void (*io_close)(struct AVFormatContext *s, AVIOContext *pb);//AVFormatContext打开时候的回调函数
char *protocol_blacklist;//协议黑名单
int max_streams;//流的最大数量,在decodeing的时候设置
省略的宏定义如下:
int flags;//Demuxer/Muxer的状态
#define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
#define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
#define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
#define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
#define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
#define AVFMT_FLAG_NOPARSE 0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled
#define AVFMT_FLAG_NOBUFFER 0x0040 ///< Do not buffer frames when possible
#define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don’t avio_close() it.
#define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
#define AVFMT_FLAG_FLUSH_PACKETS 0x0200 ///< Flush the AVIOContext every packet.
/**
- When muxing, try to avoid writing any random/volatile data to the output.
- This includes any random IDs, real-time timestamps/dates, muxer version, etc.
- This flag is mainly intended for testing.
*/
#define AVFMT_FLAG_BITEXACT 0x0400
#define AVFMT_FLAG_MP4A_LATM 0x8000 ///< Enable RTP MP4A-LATM payload
#define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
#define AVFMT_FLAG_PRIV_OPT 0x20000 ///< Enable use of private options by delaying codec open (this could be made default once all code is converted)
#if FF_API_LAVF_KEEPSIDE_FLAG
#define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Don’t merge side data but keep it separate. Deprecated, will be the default.
#endif
#define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate seeks for some formats
#define AVFMT_FLAG_SHORTEST 0x100000 ///< Stop muxing when the shortest stream stops.
#define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Wait for packet data before writing a header, and add bit