FFmpeg源代码简单分析-通用-结构体分析-AVFormatContext

参考链接

  • FFMPEG结构体分析:AVFormatContext_雷霄骅的博客-CSDN博客_avformatcontext

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;elsei = 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++);elsefor (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" ;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/445998.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

plsql如何显示表结构图_【论文攻略】排版技巧——如何用 Word 编辑参考文献

每个需要写毕业论文的朋友都会发现&#xff0c;修改文献是一件非常痛苦的事情&#xff0c;虽然现在也有很多软件可以编排参考文献&#xff0c;其实 word 本身就可以。采用合适的编辑方法会方便地做到整齐,规范, 自动排序和交叉引用。 1. 以尾注的方式插入第一个参考文献将光标定…

FFmpeg源代码简单分析-通用-结构体分析-AVCodecContext

参考链接 FFMPEG结构体分析&#xff1a;AVCodecContext_雷霄骅的博客-CSDN博客_avcodeccontext AVCodecContext AVCodecContext是包含变量较多的结构体&#xff08;感觉差不多是变量最多的结构体&#xff09;结构体的定义位于avcodec.h关键的变量如下所示&#xff08;仅仅考虑…

Hello OpenGL——OpenGL在Visual c++6.0安装和配置

1、下载并安装glut库opengl的glut库 GLUT不是OpenGL所必须的&#xff0c;但它会给我们的学习带来一定的方便&#xff0c;推荐安装。 Windows环境下的GLUT下载地址&#xff1a;&#xff08;大小约为150k&#xff09; http://www.opengl.org/resources/libraries/glut/glutdlls37…

FFmpeg源代码简单分析-通用-结构体分析-AVIOContext

参考链接 FFMPEG结构体分析&#xff1a;AVIOContext_雷霄骅的博客-CSDN博客_aviocontext AVIOContext AVIOContext是FFMPEG管理输入输出数据的结构体结构体的定义位于位于avio.h关键的变量如下所示 unsigned char *buffer&#xff1a;缓存开始位置int buffer_size&#xff1…

初闻动态规划

前言 本文以一道常见的算法面试题开篇&#xff0c;引入动态规划的基础概念&#xff0c; 介绍其思考过程。 正文 一、常见的一道算法面试题——上台阶 有一个楼梯总共n个台阶&#xff0c;只能往上走&#xff0c;每次只能上1个、2个台阶&#xff0c;总共有多少种走法。 解决…

FFmpeg源代码简单分析-通用-结构体分析-AVCodec

参考链接 FFMPEG结构体分析&#xff1a;AVCodec_雷霄骅的博客-CSDN博客_avcodec AVCodec AVCodec是存储编解码器信息的结构体结构体的定义位于avcodec.h文件中最主要的几个变量 const char *name&#xff1a;编解码器的名字&#xff0c;比较短const char *long_name&#xff…

SLF4J简介与使用(整合log4j)

SLF4J简介与使用(整合log4j) 一、概念 SLF4J的全称是Simple Logging Facade for Java&#xff0c;即简单日志门面。SLF4J并不是具体的日志框架&#xff0c;而是作为一个简单门面服务于各类日志框架&#xff0c;如java.util.logging, logback和log4j。 SLF4J提供了统一的记录…

multism中ui和uo应该怎么表示_王者荣耀:梦泪直播时谈到体验服大改动,表示装备的改动很关键...

王者荣耀的主播梦泪&#xff0c;大家都很熟了&#xff0c;也是一个很强的主播&#xff0c;他对于王者荣耀的理解&#xff0c;还是非常深刻的&#xff0c;而最近王者荣耀的体验服&#xff0c;进行了大改动&#xff0c;也是改变了很多的东西。对此&#xff0c;网友们也是非常的在…

怎么关闭或者卸载ivanti_电脑软件卸载不了怎么办,教您解决电脑软件无法卸载方法技巧...

我们在使用电脑的过程中&#xff0c;肯定会安装各种软件&#xff0c;但是一些软件在使用完之后就不会再使用了&#xff0c;但又无法卸载。下面由小编分享一下电脑安装的软件无法卸载解决方法&#xff0c;如果你在某卸载软件的时候出现无法卸载的情况&#xff0c;不妨通过以下方…

解决Github图片加载失败

问题描述 浏览自己Github某仓库的README.md内时&#xff0c;发现文档的图片始终加载不出&#xff0c;打开浏览器后台&#xff0c;冒出一片红&#xff0c;Failed to load resource: net::ERR_CONNECTION_RESET&#xff0c;如下图所示&#xff1a; 问题分析 可能造成这问题的原…

FFmpeg源代码简单分析-通用-结构体分析-关键结构体之间的关系

参考链接 FFMPEG中最关键的结构体之间的关系_雷霄骅的博客-CSDN博客_ffmpeg 结构体关系 最关键的结构体可以分成以下几类&#xff1a; 解协议&#xff08;http,rtsp,rtmp,mms&#xff09; AVIOContext&#xff0c;URLProtocol&#xff0c;URLContext主要存储视音频使用的协…

用Python下载文件

前提条件 需要事先安装requests模块&#xff1a; pip install requests 放码过来 import requestsurl XXX #文件下载来源URL filename #下载到本地后新文件名 r requests.get(url) with open(filename, "wb") as code:code.write(r.content)实战演习 从目标…

FFmpeg源代码简单分析-通用-常见结构体的初始化和销毁(AVFormatContext,AVFrame等)

参考链接 FFmpeg源代码简单分析&#xff1a;常见结构体的初始化和销毁&#xff08;AVFormatContext&#xff0c;AVFrame等&#xff09;_雷霄骅的博客-CSDN博客 结构体 AVFormatContext&#xff1a;统领全局的基本结构体。主要用于处理封装格式&#xff08;FLV/MKV/RMVB等&…

FFmpeg源代码简单分析-通用-avio_open2()

参考链接 FFmpeg源代码简单分析&#xff1a;avio_open2()_雷霄骅的博客-CSDN博客_avio_open avio_open2() 该函数用于打开FFmpeg的输入输出文件avio_open2()的声明位于libavformat\avio.h文件中&#xff0c;如下所示。 /*** Create and initialize a AVIOContext for accessi…

用Tomcat构建一个简单图片服务器

前提条件 Tomcat 7.0.90 方法一&#xff1a;修改配置文件 在TOMCAT_HOME/conf/server.xml配置文件内的<Host>内添加一子标签&#xff1a; <Context docBase"C:\exambase\" path"/img"/>方法二&#xff1a;添加Servlet 新建一应用&#xf…

FFmpeg源代码简单分析-通用-av_find_decoder()和av_find_encoder()

参考链接 FFmpeg源代码简单分析&#xff1a;av_find_decoder()和av_find_encoder()_雷霄骅的博客-CSDN博客_avcodec_find_encoder avcodec_find_encoder avcodec_find_encoder()用于查找FFmpeg的编码器avcodec_find_encoder()的声明位于libavcodec\codec.h 版本差异avcode…

post方法就反回了一个string字符串前台怎么接_Golang Web入门(2):如何实现一个RESTful风格的路由...

摘要在上一篇文章中&#xff0c;我们聊了聊在Golang中怎么实现一个Http服务器。但是在最后我们可以发现&#xff0c;固然DefaultServeMux可以做路由分发的功能&#xff0c;但是他的功能同样是不完善的。由DefaultServeMux做路由分发&#xff0c;是不能实现RESTful风格的API的&a…

FFmpeg源代码简单分析-通用-avcodec_open2()

参考链接 FFmpeg源代码简单分析&#xff1a;avcodec_open2()_雷霄骅的博客-CSDN博客 avcodec_open2() 该函数用于初始化一个音视频编解码器的AVCodecContextavcodec_open2()的声明位于libavcodec\avcodec.h&#xff0c;如下所示。 /*** Initialize the AVCodecContext to use…

统计MySQL中某数据库硬盘占用量大小

放码过来 select TABLE_NAME, concat(truncate(data_length/1024/1024,2), MB) as data_size, concat(truncate(index_length/1024/1024,2), MB) as index_size from information_schema.tables where TABLE_SCHEMA your_db_name order by data_length desc;运行结果 参考…

FFmpeg源代码简单分析-解码-打开媒体的函数avformat_open_input

参考链接 图解FFMPEG打开媒体的函数avformat_open_input_雷霄骅的博客-CSDN博客_avformat_open_input 使用FFmpeg源代码简单分析&#xff1a;avformat_open_input()_雷霄骅的博客-CSDN博客_avformat_open_input() avformat_open_input FFmpeg打开媒体的的过程开始于avformat_…