参考链接
AVFormatContext
- AVFormatContext是包含码流参数较多的结构体
- 结构体的定义位于libavformat/avformat.h
/**
* Format I/O context.//格式化 I/O 上下文
* New fields can be added to the end with minor version bumps.//可以将新字段添加到末尾,并带有较小的版本颠簸
* Removal, reordering and changes to existing fields require a major//移除、重新排序和更改现有字段需要专业
* version bump.//版本颠簸
* sizeof(AVFormatContext) must not be used outside libav*, use//sizeof(AVFormatContext) 不能在 libav* 之外使用,使用
* avformat_alloc_context() to create an AVFormatContext.//avformat_alloc_context() 创建一个 AVFormatContext
*
* Fields can be accessed through AVOptions (av_opt*),//可以通过 AVOptions (av_opt*) 访问字段
* the name string used matches the associated command line parameter name and//使用的名称字符串匹配相关的命令行参数名称和
* can be found in libavformat/options_table.h.//可以在 libavformat/options_table.h 中找到
* The AVOption/command line parameter names differ in some cases from the C//AVOption/命令行参数名称在某些情况下与 C 不同
* structure field names for historic reasons or brevity.//出于历史原因或简洁的结构字段名称
*/
typedef struct AVFormatContext {
/**
* A class for logging and @ref avoptions. Set by avformat_alloc_context().
* Exports (de)muxer private options if they exist.
* 用于记录和@ref avoptions 的类。 由 avformat_alloc_context() 设置。
* 导出(de)muxer 私有选项(如果存在)。
*/
const AVClass *av_class;
/**
* The input container format.//输入容器格式
*
* Demuxing only, set by avformat_open_input().//解复用,由avformat_open_input()进行参数设置
*/
const struct AVInputFormat *iformat;
/**
* The output container format.//输出容器格式
*
* Muxing only, must be set by the caller before avformat_write_header().
* 仅复用,必须由调用者在 avformat_write_header() 之前设置
*/
const struct AVOutputFormat *oformat;
/**
* Format private data. This is an AVOptions-enabled struct //格式化私人数据。 这是一个启用 AVOptions 的结构
* if and only if iformat/oformat.priv_class is not NULL. //当且仅当 iformat/oformat.priv_class 不为 NULL
*
* - muxing: set by avformat_write_header() //复用:由 avformat_write_header() 设置
* - demuxing: set by avformat_open_input() //解复用:由 avformat_open_input() 设置
*/
void *priv_data;
/**
* I/O context.//I/O 上下文
*
* - demuxing: either set by the user before avformat_open_input() (then
* the user must close it manually) or set by avformat_open_input().
* 解复用:由用户在 avformat_open_input() 之前设置(然后用户必须手动关闭)或通过 avformat_open_input() 设置。
* - muxing: set by the user before avformat_write_header(). The caller must
* take care of closing / freeing the IO context.
* 复用:由用户在 avformat_write_header() 之前设置。 调用者必须负责关闭/释放 IO 上下文
* Do NOT set this field if AVFMT_NOFILE flag is set in //如果设置了 AVFMT_NOFILE 标志,请不要设置此字段
* iformat/oformat.flags. In such a case, the (de)muxer will handle //iformat/oformat.flags。 在这种情况下,(de)muxer 将处理
* I/O in some other way and this field will be NULL. //以其他方式进行 I/O,此字段将为 NULL
*/
AVIOContext *pb;
/* stream info */ 流信息
/**
* Flags signalling stream properties. A combination of AVFMTCTX_*. //标志信号流属性。 AVFMTCTX_* 的组合
* Set by libavformat. //由 libavformat 设置
*/
int ctx_flags;
/**
* Number of elements in AVFormatContext.streams. //AVFormatContext.streams 中的元素数量
*
* Set by avformat_new_stream(), must not be modified by any other code. //由 avformat_new_stream() 设置,不得被任何其他代码修改
*/
unsigned int nb_streams;
/**
* A list of all streams in the file. New streams are created with
* avformat_new_stream(). //文件中所有流的列表。 新的流使用avformat_new_stream()进行创建
*
* - demuxing: streams are created by libavformat in avformat_open_input(). //解复用:流由 libavformat 在 avformat_open_input() 中创建
* If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also
* appear in av_read_frame(). //如果在 ctx_flags 中设置了 AVFMTCTX_NOHEADER,那么新的流也可能出现在 av_read_frame() 中
* - muxing: streams are created by the user before avformat_write_header(). //复用:流由用户在 avformat_write_header() 之前创建
*
* Freed by libavformat in avformat_free_context(). //在 avformat_free_context() 中被 libavformat 释放
*/
AVStream **streams;
/**
* input or output URL. Unlike the old filename field, this field has no
* length restriction. //输入或输出 URL。 与旧的文件名字段不同,该字段没有长度限制
*
* - demuxing: set by avformat_open_input(), initialized to an empty
* string if url parameter was NULL in avformat_open_input().
* 解复用:由 avformat_open_input() 设置,如果 avformat_open_input() 中的 url 参数为 NULL,则将其初始化为空字符串字符串
* - muxing: may be set by the caller before calling avformat_write_header()
* (or avformat_init_output() if that is called first) to a string
* which is freeable by av_free(). Set to an empty string if it
* was NULL in avformat_init_output().
* 复用:可以在调用 avformat_write_header() 之前由调用者设置(或 avformat_init_output() 如果首先调用)到一个字符串
* 在 avformat_init_output() 中为 NULL,
*
* Freed by libavformat in avformat_free_context(). //在 avformat_free_context() 中被 libavformat 释放
*/
char *url;
/**
* Position of the first frame of the component, in //组件第一帧的位置
* AV_TIME_BASE fractional seconds. NEVER set this value directly: //AV_TIME_BASE 小数秒。 切勿直接设置此值
* It is deduced from the AVStream values. //它是从 AVStream 值推导出来的
*
* Demuxing only, set by libavformat. //仅解复用,由 libavformat 设置
*/
int64_t start_time;
/**
* Duration of the stream, in AV_TIME_BASE fractional
* seconds. Only set this value if you know none of the individual stream
* durations and also do not set any of them. This is deduced from the
* AVStream values if not set.
*
* 流的持续时间,以 AV_TIME_BASE 小数秒为单位。 仅当您不知道任何单个流持续时间并且不设置
* 任何一个时才设置此值。 如果未设置,则从 AVStream 值推导出来。
*
* Demuxing only, set by libavformat. //仅解复用,由 libavformat 设置
*/
int64_t duration;
/**
* 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.
*
* 以比特/秒为单位的总流比特率,如果不可用,则为 0。
* 请不要直接设置它,如果FFmpeg知道文件大小和持续时间则可以自动计算,
*/
int64_t bit_rate;
unsigned int packet_size;
int max_delay;
/**
* Flags modifying the (de)muxer behaviour. A combination of AVFMT_FLAG_*.
* Set by the user before avformat_open_input() / avformat_write_header().
* 修改(de)muxer 行为的标志。 avformat_open_input() / avformat_write_header() 之前用户设置的 AVFMT_FLAG_* 的组合
*/
int flags;
#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 //忽略同时包含 DTS 和 PTS 的帧上的 DTS
#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
//不要使用 AVParsers,您还必须设置 AVFMT_FLAG_NOFILLIN,因为填充代码适用于帧并且不解析 -> 不帧。 如果解析以查找帧边界已被禁用,则查找帧也无法工作
#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. //调用者提供了一个自定义 AVIOContext,不要使用 avio_close() 它。
#define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted //丢弃标记为损坏的帧
#define AVFMT_FLAG_FLUSH_PACKETS 0x0200 ///< Flush the AVIOContext every packet. //刷新每个数据包的 AVIOContext。
/**
* 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. //这包括任何随机 ID、实时时间戳/日期、复用器版本等
*
* This flag is mainly intended for testing. //此标志主要用于测试
*/
#define AVFMT_FLAG_BITEXACT 0x0400
#define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down) //尝试通过 dts 交错输出的数据包(使用此标志会减慢解复用速度)
#if FF_API_LAVF_PRIV_OPT
#define AVFMT_FLAG_PRIV_OPT 0x20000 ///< Enable use of private options by delaying codec open (deprecated, does nothing) //通过延迟打开编解码器来启用私有选项(已弃用,不执行任何操作)
#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 ///< Add bitstream filters as requested by the muxer //根据复用器的要求添加比特流过滤器
/**
* Maximum number of bytes read from input in order to determine stream
* properties. Used when reading the global header and in
* avformat_find_stream_info().
*
* 从输入中读取的最大字节数以确定流属性。 在读取全局标头和 avformat_find_stream_info() 时使用
*
* Demuxing only, set by the caller before avformat_open_input(). //仅解复用,由调用者在 avformat_open_input() 之前设置
*
* @note this is \e not used for determining the \ref AVInputFormat //@note 这不是 \e 用于确定 \ref AVInputFormat "输入格式"
* "input format"
* @sa format_probesize @sa format_probesize
*/
int64_t probesize;
/**
* Maximum duration (in AV_TIME_BASE units) of the data read
* from input in avformat_find_stream_info(). //从 avformat_find_stream_info() 中的输入读取的数据的最大持续时间(以 AV_TIME_BASE 为单位)
* Demuxing only, set by the caller before avformat_find_stream_info(). //仅解复用,由调用者在 avformat_find_stream_info() 之前设置
* Can be set to 0 to let avformat choose using a heuristic. //可以设置为 0 让 avformat 使用启发式方法进行选择
*/
int64_t max_analyze_duration;
const uint8_t *key;
int keylen;
unsigned int nb_programs;
AVProgram **programs;
/**
* Forced video codec_id. //强制视频 codec_id
* Demuxing: Set by user. //解复用:由用户设置
*/
enum AVCodecID video_codec_id;
/**
* Forced audio codec_id. //强制音频 codec_id
* Demuxing: Set by user. //解复用:由用户设置
*/
enum AVCodecID audio_codec_id;
/**
* Forced subtitle codec_id. //强制字幕 codec_id
* Demuxing: Set by user. //解复用:由用户设置
*/
enum AVCodecID subtitle_codec_id;
/**
* Maximum amount of memory in bytes to use for the index of each stream. //用于每个流的索引的最大内存量(以字节为单位)
* If the index exceeds this size, entries will be discarded as
* needed to maintain a smaller size. This can lead to slower or less
* accurate seeking (depends on demuxer).
* 如果索引超过此大小,将根据需要丢弃条目以保持较小的大小。 这可能会导致更慢或更不准确的搜索(取决于解复用器)
* Demuxers for which a full in-memory index is mandatory will ignore //必须有完整的内存索引的解复用器将忽略这一点
* this.
* - muxing: unused //复用:未使用
* - demuxing: set by user //解复用:由用户设置
*/
unsigned int max_index_size;
/**
* Maximum amount of memory in bytes to use for buffering frames
* obtained from realtime capture devices. //用于缓冲从实时捕获设备获得的帧的最大内存量(以字节为单位)
*/
unsigned int max_picture_buffer;
/**
* Number of chapters in AVChapter array. //AVChapter 数组中的章节数
* When muxing, chapters are normally written in the file header,
* so nb_chapters should normally be initialized before write_header
* is called. Some muxers (e.g. mov and mkv) can also write chapters
* in the trailer. To write chapters in the trailer, nb_chapters
* must be zero when write_header is called and non-zero when
* write_trailer is called.
* 复用时,章节通常写入文件头,因此 nb_chapters 通常应在调用 write_header 之前初始化
* 一些混音器(例如 mov 和 mkv)也可以在预告片中编写章节
* 要在预告片中写入章节,调用 write_header 时 nb_chapters 必须为零,调用 write_trailer 时 nb_chapters 必须为非零
* - muxing: set by user //muxing:由用户设置
* - demuxing: set by libavformat //解复用:由 libavformat 设置
*/
unsigned int nb_chapters;
AVChapter **chapters;
/**
* Metadata that applies to the whole file. //适用于整个文件的元数据
*
* - demuxing: set by libavformat in avformat_open_input() //解复用:由 avformat_open_input() 中的 libavformat 设置
* - muxing: may be set by the caller before avformat_write_header() //muxing:可以在 avformat_write_header() 之前由调用者设置
*
* Freed by libavformat in avformat_free_context(). //在 avformat_free_context() 中被 libavformat 释放
*/
AVDictionary *metadata;
/**
* Start time of the stream in real world time, in microseconds //实时流的开始时间,以微秒为单位
* since the Unix epoch (00:00 1st January 1970). That is, pts=0 in the
* stream was captured at this real world time. //自 Unix 时代(1970 年 1 月 1 日 00:00)开始。 也就是说,流中的 pts=0 是在这个真实世界时间捕获的
* - muxing: Set by the caller before avformat_write_header(). If set to
* either 0 or AV_NOPTS_VALUE, then the current wall-time will
* be used.
* muxing:由调用者在 avformat_write_header() 之前设置。 如果设置为 0 或 AV_NOPTS_VALUE,则将使用当前的挂墙时间
* - demuxing: Set by libavformat. AV_NOPTS_VALUE if unknown. Note that
* the value may become known after some number of frames
* have been received.
* 解复用:由 libavformat 设置。 AV_NOPTS_VALUE 如果未知。 请注意,在接收到一定数量的帧后,该值可能会变得已知。
*/
int64_t start_time_realtime;
/**
* The number of frames used for determining the framerate in
* avformat_find_stream_info(). //用于确定 avformat_find_stream_info() 中的帧速率的帧数
* Demuxing only, set by the caller before avformat_find_stream_info(). //仅解复用,由调用者在 avformat_find_stream_info() 之前设置
*/
int fps_probe_size;
/**
* Error recognition; higher values will detect more errors but may
* misdetect some more or less valid parts as errors. //错误识别; 较高的值将检测到更多的错误,但可能会将某些或多或少的有效部分误检测为错误
* Demuxing only, set by the caller before avformat_open_input(). //仅解复用,由调用者在 avformat_open_input() 之前设置
*/
int error_recognition;
/**
* Custom interrupt callbacks for the I/O layer. //I/O 层的自定义中断回调
*
* demuxing: set by the user before avformat_open_input(). //demuxing:由用户在 avformat_open_input() 之前设置
* muxing: set by the user before avformat_write_header()
* (mainly useful for AVFMT_NOFILE formats). The callback
* should also be passed to avio_open2() if it's used to
* open the file. //muxing:在 avformat_write_header() 之前由用户设置(主要用于 AVFMT_NOFILE 格式)。 如果用于打开文件,还应将回调传递给 avio_open2()
*/
AVIOInterruptCB interrupt_callback;
/**
* Flags to enable debugging. //启用调试的标志
*/
int debug;
#define FF_FDEBUG_TS 0x0001
/**
* Maximum buffering duration for interleaving. //交织的最大缓冲持续时间
*
* To ensure all the streams are interleaved correctly,
* av_interleaved_write_frame() will wait until it has at least one packet
* for each stream before actually writing any packets to the output file.
* When some streams are "sparse" (i.e. there are large gaps between
* successive packets), this can result in excessive buffering.
* 为确保所有流正确交错,av_interleaved_write_frame() 将等待每个流至少有一个数据包,然后再将任何数据包实际写入输出文件。
* 当某些流是“稀疏的”时(即连续数据包之间有很大的间隙),这可能会导致过度缓冲。
* This field specifies the maximum difference between the timestamps of the
* first and the last packet in the muxing queue, above which libavformat
* will output a packet regardless of whether it has queued a packet for all
* the streams.
* 此字段指定复用队列中第一个和最后一个数据包的时间戳之间的最大差值,超过该值 libavformat 将输出一个数据包,无论它是否已为所有流排队一个数据包。
* Muxing only, set by the caller before avformat_write_header(). //仅复用,由调用者在 avformat_write_header() 之前设置
*/
int64_t max_interleave_delta;
/**
* Allow non-standard and experimental extension //允许非标准和实验性扩展
* @see AVCodecContext.strict_std_compliance
*/
int strict_std_compliance;
/**
* Flags indicating events happening on the file, a combination of
* AVFMT_EVENT_FLAG_*. //指示文件上发生的事件的标志,AVFMT_EVENT_FLAG_* 的组合
*
* - demuxing: may be set by the demuxer in avformat_open_input(),
* avformat_find_stream_info() and av_read_frame(). Flags must be cleared
* by the user once the event has been handled.
* 解复用:可以由解复用器在 avformat_open_input() 中设置,avformat_find_stream_info() 和 av_read_frame()。 处理完事件后,用户必须清除标志。
* - muxing: may be set by the user after avformat_write_header() to
* indicate a user-triggered event. The muxer will clear the flags for
* events it has handled in av_[interleaved]_write_frame().
* muxing:可以在 avformat_write_header() 之后由用户设置以指示用户触发的事件.复用器将清除它在 av_[interleaved]_write_frame() 中处理的事件的标志。
*/
int event_flags;
/**
* - demuxing: the demuxer read new metadata from the file and updated
* AVFormatContext.metadata accordingly
* - muxing: the user updated AVFormatContext.metadata and wishes the muxer to
* write it into the file
*/
#define AVFMT_EVENT_FLAG_METADATA_UPDATED 0x0001
/**
* Maximum number of packets to read while waiting for the first timestamp.
* Decoding only.
*/
int max_ts_probe;
/**
* Avoid negative timestamps during muxing.
* Any value of the AVFMT_AVOID_NEG_TS_* constants.
* Note, this works better when using av_interleaved_write_frame().
* - muxing: Set by user
* - demuxing: unused
*/
int avoid_negative_ts;
#define AVFMT_AVOID_NEG_TS_AUTO -1 ///< Enabled when required by target format
#define AVFMT_AVOID_NEG_TS_DISABLED 0 ///< Do not shift timestamps even when they are negative.
#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
/**
* Transport stream id.
* This will be moved into demuxer private options. Thus no API/ABI compatibility
*/
int ts_id;
/**
* Audio preload in microseconds.
* Note, not all formats support this and unpredictable things may happen if it is used when not supported.
* - encoding: Set by user
* - decoding: unused
*/
int audio_preload;
/**
* Max chunk time in microseconds.
* Note, not all formats support this and unpredictable things may happen if it is used when not supported.
* - encoding: Set by user
* - decoding: unused
*/
int max_chunk_duration;
/**
* Max chunk size in bytes
* Note, not all formats support this and unpredictable things may happen if it is used when not supported.
* - encoding: Set by user
* - decoding: unused
*/
int max_chunk_size;
/**
* forces the use of wallclock timestamps as pts/dts of packets
* This has undefined results in the presence of B frames.
* - encoding: unused
* - decoding: Set by user
*/
int use_wallclock_as_timestamps;
/**
* avio flags, used to force AVIO_FLAG_DIRECT.
* - encoding: unused
* - decoding: Set by user
*/
int avio_flags;
/**
* The duration field can be estimated through various ways, and this field can be used
* to know how the duration was estimated.
* - encoding: unused
* - decoding: Read by user
*/
enum AVDurationEstimationMethod duration_estimation_method;
/**
* Skip initial bytes when opening stream
* - encoding: unused
* - decoding: Set by user
*/
int64_t skip_initial_bytes;
/**
* Correct single timestamp overflows
* - encoding: unused
* - decoding: Set by user
*/
unsigned int correct_ts_overflow;
/**
* Force seeking to any (also non key) frames.
* - encoding: unused
* - decoding: Set by user
*/
int seek2any;
/**
* Flush the I/O context after each packet.
* - encoding: Set by user
* - decoding: unused
*/
int flush_packets;
/**
* format probing score.
* The maximal score is AVPROBE_SCORE_MAX, its set when the demuxer probes
* the format.
* - encoding: unused
* - decoding: set by avformat, read by user
*/
int probe_score;
/**
* Maximum number of bytes read from input in order to identify the
* \ref AVInputFormat "input format". Only used when the format is not set
* explicitly by the caller.
* 从输入读取的最大字节数,以识别 \ref AVInputFormat “输入格式”。 仅在调用者未明确设置格式时使用
* Demuxing only, set by the caller before avformat_open_input(). //仅解复用,由调用者在 avformat_open_input() 之前设置
*
* @sa probesize
*/
int format_probesize;
/**
* ',' separated list of allowed decoders.
* If NULL then all are allowed
* - encoding: unused
* - decoding: set by user
*/
char *codec_whitelist;
/**
* ',' separated list of allowed demuxers. //',' 允许的分离器的分隔列表。
* If NULL then all are allowed
* - encoding: unused
* - decoding: set by user
*/
char *format_whitelist;
/**
* IO repositioned flag. //IO 重新定位标志
* This is set by avformat when the underlaying IO context read pointer
* is repositioned, for example when doing byte based seeking. //这是在底层 IO 上下文读取指针重新定位时由 avformat 设置的,例如在进行基于字节的查找时
* Demuxers can use the flag to detect such changes. //Demuxers 可以使用该标志来检测此类更改
*/
int io_repositioned;
/**
* Forced video codec. //强制视频编解码器
* This allows forcing a specific decoder, even when there are multiple with
* the same codec_id. //这允许强制使用特定的解码器,即使有多个具有相同的 codec_id
* Demuxing: Set by user //解复用:由用户设置
*/
const AVCodec *video_codec;
/**
* Forced audio codec. //强制音频编解码器
* This allows forcing a specific decoder, even when there are multiple with
* the same codec_id. //这允许强制使用特定的解码器,即使有多个具有相同的 codec_id
* Demuxing: Set by user //解复用:由用户设置
*/
const AVCodec *audio_codec;
/**
* Forced subtitle codec. //强制字幕编解码器
* This allows forcing a specific decoder, even when there are multiple with
* the same codec_id. //这允许强制使用特定的解码器,即使有多个具有相同的 codec_id
* Demuxing: Set by user //解复用:由用户设置
*/
const AVCodec *subtitle_codec;
/**
* Forced data codec. //强制数据编解码器
* This allows forcing a specific decoder, even when there are multiple with
* the same codec_id.//这允许强制使用特定的解码器,即使有多个具有相同的 codec_id
* Demuxing: Set by user //解复用:由用户设置
*/
const AVCodec *data_codec;
/**
* Number of bytes to be written as padding in a metadata header. //在元数据头中作为填充写入的字节数
* Demuxing: Unused. //解复用:未使用
* Muxing: Set by user via av_format_set_metadata_header_padding. //Muxing:由用户通过 av_format_set_metadata_header_padding 设置
*/
int metadata_header_padding;
/**
* User data.
* This is a place for some private data of the user.
*/
void *opaque;
/**
* Callback used by devices to communicate with application. //设备用于与应用程序通信的回调。
*/
av_format_control_message control_message_cb;
/**
* Output timestamp offset, in microseconds. //输出时间戳偏移量,以微秒为单位
* Muxing: set by user
*/
int64_t output_ts_offset;
/**
* dump format separator. //转储格式分隔符
* can be ", " or "\n " or anything else //可以是 ", " 或 "\n" 或其他任何东西
* - muxing: Set by user.
* - demuxing: Set by user.
*/
uint8_t *dump_separator;
/**
* Forced Data codec_id. //强制数据 codec_id
* Demuxing: Set by user.
*/
enum AVCodecID data_codec_id;
/**
* ',' separated list of allowed protocols. //',' 分隔的允许协议列表
* - encoding: unused
* - decoding: set by user
*/
char *protocol_whitelist;
/**
* A callback for opening new IO streams. //打开新 IO 流的回调
*
* Whenever a muxer or a demuxer needs to open an IO stream (typically from
* avformat_open_input() for demuxers, but for certain formats can happen at
* other times as well), it will call this callback to obtain an IO context.
* 每当复用器或解复用器需要打开 IO 流(通常来自解复用器的 avformat_open_input(),但对于某些格式也可能在其他时间发生),它将调用此回调以获取 IO 上下文。
* @param s the format context //s 格式上下文
* @param pb on success, the newly opened IO context should be returned here //pb 成功,这里应该返回新打开的 IO 上下文
* @param url the url to open //url 要打开的 url
* @param flags a combination of AVIO_FLAG_* //标记 AVIO_FLAG_ 的组合*
* @param options a dictionary of additional options, with the same
* semantics as in avio_open2() //options 附加选项的字典,具有相同的语义如 avio_open2()
* @return 0 on success, a negative AVERROR code on failure //0 成功,负 AVERROR 代码失败
*
* @note Certain muxers and demuxers do nesting, i.e. they open one or more
* additional internal format contexts. Thus the AVFormatContext pointer
* passed to this callback may be different from the one facing the caller.
* It will, however, have the same 'opaque' field.
* 某些复用器和解复用器会进行嵌套,即它们会打开一个或多个额外的内部格式上下文。 因此,传递给此回调的 AVFormatContext 指针可能与面向调用者的指针不同。
* 但是,它将具有相同的“不透明”字段。
*/
int (*io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url,
int flags, AVDictionary **options);
/**
* A callback for closing the streams opened with AVFormatContext.io_open(). //用于关闭使用 AVFormatContext.io_open() 打开的流的回调。
*/
void (*io_close)(struct AVFormatContext *s, AVIOContext *pb);
/**
* ',' separated list of disallowed protocols. //不允许的协议的单独列表
* - encoding: unused
* - decoding: set by user
*/
char *protocol_blacklist;
/**
* The maximum number of streams.
* - encoding: unused
* - decoding: set by user
*/
int max_streams;
/**
* Skip duration calcuation in estimate_timings_from_pts. //在 pts 的估计时间中跳过持续时间计算。
* - encoding: unused
* - decoding: set by user
*/
int skip_estimate_duration_from_pts;
/**
* Maximum number of packets that can be probed //可探测的最大数据包数
* - encoding: unused //编码:未使用
* - decoding: set by user //解码:由用户设置
*/
int max_probe_packets;
/**
* A callback for closing the streams opened with AVFormatContext.io_open(). //用于关闭使用 AVFormatContext.io_open() 打开的流的回调
*
* Using this is preferred over io_close, because this can return an error. //使用 this 优于 io_close,因为这可能会返回错误
* Therefore this callback is used instead of io_close by the generic //因此,如果 io_close 为 NULL 或默认值,则通用 libavformat 代码使用此回调而不是 io_close
* libavformat code if io_close is NULL or the default.
*
* @param s the format context //格式上下文
* @param pb IO context to be closed and freed //IO 上下文被关闭和释放
* @return 0 on success, a negative AVERROR code on failure //0 成功,负 AVERROR 代码失败
*/
int (*io_close2)(struct AVFormatContext *s, AVIOContext *pb);
} AVFormatContext;
- AVFormatCOntext是ffmpeg开发中贯穿始终的数据结构,许多函数均以它为参数
- 它是FFmpeg解封装(flv、MP4、rmvb、avi)功能的结构体
- 几个主要变量的作用,限定范围为编码领域
- AVIOContext *pb; 输入数据的缓存
- unsigned int nb_streams; 音视频流的个数
- AVStream **streams; 音视频流
- int64_t duration; 时长(单位:微秒us,转换为秒需要除以1000000)
- int64_t bit_rate; 比特率(单位bps,转换为kbps需要除以1000)
- AVDictionary *metadata; 元数据
将视频的时长转换为HH:MM:SS的形式
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结构体中,如下所示
typedef struct AVDictionaryEntry {
char *key;
char *value;
} AVDictionaryEntry;
typedef struct AVDictionary AVDictionary;
- 每一条元数据分为key和value两个属性。
- 在ffmpeg中通过av_dict_get()函数获得视频的原数据。
AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,
const AVDictionaryEntry *prev, int flags)
{
unsigned int i, j;
if (!m)
return NULL;
if (prev)
i = prev - m->elems + 1;
else
i = 0;
for (; i < m->count; i++) {
const char *s = m->elems[i].key;
if (flags & AV_DICT_MATCH_CASE)
for (j = 0; s[j] == key[j] && key[j]; j++)
;
else
for (j = 0; av_toupper(s[j]) == av_toupper(key[j]) && key[j]; j++)
;
if (key[j])
continue;
if (s[j] && !(flags & AV_DICT_IGNORE_SUFFIX))
continue;
return &m->elems[i];
}
return NULL;
}
- 下列代码显示了获取元数据并存入meta字符串变量的过程,注意每一条key和value之间有一个"\t:",value之后有一个"\r\n"
//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" ;
}