【FFmpeg】AVFormatContext结构体

【FFmpeg】AVFormatContext结构体

  • 1.AVFormatContext结构体
    • 1.2 const struct AVInputFormat *iformat
    • 1.3 const struct AVOutputFormat *oformat

参考:
FFMPEG结构体分析:AVFormatContext

示例工程:
【FFmpeg】调用ffmpeg库实现264软编
【FFmpeg】调用ffmpeg库实现264软解
【FFmpeg】调用ffmpeg库进行RTMP推流和拉流
【FFmpeg】调用ffmpeg库进行SDL2解码后渲染

流程分析:
【FFmpeg】编码链路上主要函数的简单分析
【FFmpeg】解码链路上主要函数的简单分析

结构体分析:
【FFmpeg】AVCodec结构体
【FFmpeg】AVCodecContext结构体
【FFmpeg】AVStream结构体

1.AVFormatContext结构体

AVFormatContext的定义位于libavformat\avformat.h之中,主要包括了格式的上下文信息,定义如下

/*** Format I/O context.* 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* avformat_alloc_context() to create an AVFormatContext.** Fields can be accessed through AVOptions (av_opt*),* the name string used matches the associated command line parameter name and* can be found in libavformat/options_table.h.* The AVOption/command line parameter names differ in some cases from the C* structure field names for historic reasons or brevity.*/
// 格式I/O的上下文结构体
// 新字段可以添加到末尾,并伴有轻微的版本变更。
// 删除、重新排序和更改现有字段需要一个主要的版本更新。
// sizeof(AVFormatContext)不能在libav*之外使用,使用avformat_alloc_context()来创建AVFormatContext
// 字段可以通过AVOptions (av_opt*)访问,使用的名称字符串匹配相关的命令行参数名称,可以在libavformat/options_table.h中找到
// 由于历史原因或简洁,AVOption/命令行参数名在某些情况下与C结构字段名不同
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()设置// 导出(删除)多个私有选项(如果存在的话)const AVClass *av_class;/*** The input container format.** Demuxing only, set by avformat_open_input().*/// 输入容器的格式// 仅用于解复用,由set by 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* if and only if iformat/oformat.priv_class is not NULL.** - muxing: set by avformat_write_header()* - demuxing: set by avformat_open_input()*/// 格式化私有数据。这是一个启用avoptions的结构体,当且仅当format/oformat。priv_class不是NULLvoid *priv_data;/*** I/O context.** - demuxing: either set by the user before avformat_open_input() (then*             the user must close it manually) or set by avformat_open_input().* - muxing: set by the user before avformat_write_header(). The caller must*           take care of closing / freeing the IO context.** Do NOT set this field if AVFMT_NOFILE flag is set in* iformat/oformat.flags. In such a case, the (de)muxer will handle* I/O in some other way and this field will be NULL.*/// 输入输出的上下文// 解复用:由用户在avformat_open_input()之前设置(然后用户必须手动关闭它)或由avformat_open_input()设置// 复用:在avformat_write_header()之前由用户设置。调用者必须负责关闭/释放IO上下文// 如果在iformat/oformat.flags中设置了AVFMT_NOFILE标志,则不要设置此字段。在这种情况下,(de)muxer将以其他方式处理I/O,并且该字段将为NULLAVIOContext *pb;/* stream info */// 下面的变量记录了流的信息/*** Flags signalling stream properties. A combination of AVFMTCTX_*.* Set by libavformat.*/// 描述了流信息的标志,是AVFMTCTX_*的组合,由libavformat设置int ctx_flags;/*** Number of elements in AVFormatContext.streams.** Set by avformat_new_stream(), must not be modified by any other code.*/// AVFormatContext.streams中的元素数量unsigned int nb_streams;/*** A list of all streams in the file. New streams are created with* avformat_new_stream().** - demuxing: streams are created by libavformat in avformat_open_input().*             If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also*             appear in av_read_frame().* - muxing: streams are created by the user before avformat_write_header().** Freed by libavformat in avformat_free_context().*/// 文件中所有流的列表。使用avformat_new_stream()创建新流// 解复用:流是由libavformat在avformat_open_input中创建的// 复用:用户在avformat_write_header()之前创建流AVStream **streams;/*** Number of elements in AVFormatContext.stream_groups.** Set by avformat_stream_group_create(), must not be modified by any other code.*/// AVFormatContext.stream_groups中的元素数量// 由avformat_stream_group_create()设置,不能被任何其他代码修改unsigned int nb_stream_groups;/*** A list of all stream groups in the file. New groups are created with* avformat_stream_group_create(), and filled with avformat_stream_group_add_stream().** - demuxing: groups may be created by libavformat in avformat_open_input().*             If AVFMTCTX_NOHEADER is set in ctx_flags, then new groups may also*             appear in av_read_frame().* - muxing: groups may be created by the user before avformat_write_header().** Freed by libavformat in avformat_free_context().*/// 文件中所有流组的列表。使用avformat_stream_group_create()创建新组,并使用avformat_stream_group_add_stream()填充新组// 解复用:组可以通过libavformat在avformat_open_input()中创建。如果AVFMTCTX_NOHEADER在ctx_flags中设置,//			那么av_read_frame()中也可能出现新的组。// 复用:用户可以在avformat_write_header()之前创建组// 由libavformat在avformat_free_context()之中释放AVStreamGroup **stream_groups;/*** Number of chapters in AVChapter array.* 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.* - muxing: set by user* - demuxing: set by libavformat*/// AVChapter数组中的章节数// 当复用时,章节通常写在文件头中,所以nb_章节通常应该在调用write_header之前初始化。// 一些编码器(例如mov和mkv)也可以在预告片中编写章节。要在尾文件中写入章节,调用write_header时nb_章节必须为零,// 调用write_trailer时nb_章节必须为非零unsigned int nb_chapters;AVChapter **chapters;/*** input or output URL. Unlike the old filename field, this field has no* length restriction.** - demuxing: set by avformat_open_input(), initialized to an empty*             string if url parameter was NULL in avformat_open_input().* - 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().** Freed by libavformat in avformat_free_context().*/// 输入或输出URL,与原来使用的filename变量不同,这里没有长度限制,原来的定义为 char filename[1024]// 解复用:由avformat_open_input()设置,如果avformat_open_input()中的url参数为NULL,则初始化为空字符串// 复用:可以由调用者在调用avformat_write_header()(或avformat_init_output()如果先调用它)之前设置为av_free()可释放的字符串。//			如果avformat_init_output()中为NULL,则设置为空字符串char *url;/*** 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.*/// 组件的第一帧的位置,以AV_TIME_BASE小数秒为单位。千万不要直接设置这个值// 它是从AVStream的值推导出来的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.** Demuxing only, set by libavformat.*/// 流的持续时间,以AV_TIME_BASE小数秒为单位。只有在您不知道任何单个流持续时间的情况下才设置此值,// 并且也不要设置它们中的任何一个。如果没有设置,这是从AVStream值推断出来的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.*/// 总流比特率(以bit/s为单位),如果不可用则为0。如果file_size和持续时间被称为FFmpeg可以自动计算,则不要直接设置它int64_t bit_rate;// pakcet包的大小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().*/// 描述复用器或者解复用器的行为,是一组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
#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_SORT_DTS    0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
#define AVFMT_FLAG_FAST_SEEK   0x80000 ///< Enable fast, but inaccurate seeks for some formats
#if FF_API_LAVF_SHORTEST
#define AVFMT_FLAG_SHORTEST   0x100000 ///< Stop muxing when the shortest stream stops.
#endif
#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().** Demuxing only, set by the caller before avformat_open_input().** @note this is \e not  used for determining the \ref AVInputFormat*       "input format"* @sa format_probesize*/// 为了确定流属性而从输入读取的最大字节数。在读取全局头文件和avformat_find_stream_info()中使用int64_t probesize;/*** Maximum duration (in AV_TIME_BASE units) of the data read* from input in avformat_find_stream_info().* Demuxing only, set by the caller before avformat_find_stream_info().* Can be set to 0 to let avformat choose using a heuristic.*/// avformat_find_stream_info()从输入中读取数据的最大持续时间(AV_TIME_BASE单位)// 可以设置为0,来让avformat选择使用启发式模式?int64_t max_analyze_duration;const uint8_t *key;int keylen;// 程序描述的结构体,从定义上看似乎是区分和管理不同的程序集unsigned int nb_programs;AVProgram **programs;/*** Forced video codec_id.* Demuxing: Set by user.*/// 视频的codec IDenum AVCodecID video_codec_id;/*** Forced audio codec_id.* Demuxing: Set by user.*/// 音频的codec IDenum AVCodecID audio_codec_id;/*** Forced subtitle codec_id.* Demuxing: Set by user.*/// 字幕的codec ID// 使用何种codec来编码和解码字幕enum AVCodecID subtitle_codec_id;/*** Forced Data codec_id.* Demuxing: Set by user.*/// 数据流的codec ID// 用于处理非音视频的数据内容,比如字幕、加密秘钥或者自定义的元数据enum AVCodecID data_codec_id;/*** Metadata that applies to the whole file.** - demuxing: set by libavformat in avformat_open_input()* - muxing: may be set by the caller before avformat_write_header()** Freed by libavformat in avformat_free_context().*/// 应用于整个文件的元数据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.* - 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.* - demuxing: Set by libavformat. AV_NOPTS_VALUE if unknown. Note that*             the value may become known after some number of frames*             have been received.*/// 流在现实世界时间中的开始时间,自Unix纪元(1970年1月1日00:00)以来以微秒为单位。// 也就是说,流中的pts=0是在这个真实世界时间被捕获的int64_t start_time_realtime;/*** The number of frames used for determining the framerate in* 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().*/// 错误识别;较高的值将检测到更多的错误,但可能会将一些或多或少有效的部分误检测为错误int error_recognition;/*** Custom interrupt callbacks for the I/O layer.** demuxing: set by the user before 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.*/// 为I/O层定制中断回调AVIOInterruptCB interrupt_callback;/*** Flags to enable debugging.*/// 用于debug的flagint debug;
#define FF_FDEBUG_TS        0x0001/*** The maximum number of streams.* - encoding: unused* - decoding: set by user*/// 流的最大数int max_streams;/*** 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*/// 用于每个流索引的最大内存量(以字节为单位)// 如果索引超过此大小,则根据需要丢弃条目以保持较小的索引大小。这可能导致搜索速度变慢或准确性降低(取决于demuxer)// 强制使用完整内存索引的解压缩器将忽略这一点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;/*** 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.** 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.** Muxing only, set by the caller before avformat_write_header().*/// 用于interleaving的最大缓冲时间// 1. 为了确保所有流都正确交错,av_interleaved_write_frame()将等待,直到每个流至少有一个数据包,// 		然后才实际将任何数据包写入输出文件。当一些流是“稀疏的”(即在连续的数据包之间有很大的间隙),这可能会导致过度的缓冲// // 2.该字段指定muxing队列中第一个和最后一个数据包的时间戳之间的最大差异,高于此值的libavformat将输出一个数据包,//		而不管它是否为所有流排队int64_t max_interleave_delta;/*** Maximum number of packets to read while waiting for the first timestamp.* Decoding only.*/// 等待第一个时间戳时要读取的最大数据包数int max_ts_probe;/*** 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;/*** Maximum number of packets that can be probed* - encoding: unused* - decoding: set by user*/// 可以探测的最大数据包数int max_probe_packets;/*** 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_*.** - 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.* - 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().*/// 指示文件上发生的事件的标志,AVFMT_EVENT_FLAG_*的组合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/*** 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*/// 在muxing期间避免负时间戳// AVFMT_AVOID_NEG_TS_*常量的任何值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/*** 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;/*** 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*/// 强制使用时钟时间戳作为包的pts/dts// 这在存在B帧的情况下会产生未定义的结果int use_wallclock_as_timestamps;/*** Skip duration calcuation in estimate_timings_from_pts.* - encoding: unused* - decoding: set by user*/// 跳过estimate_timings_from_pts中的持续时间计算int skip_estimate_duration_from_pts;/*** avio flags, used to force AVIO_FLAG_DIRECT.* - encoding: unused* - decoding: Set by user*/// avio标志,用于强制AVIO_FLAG_DIRECTint 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*/// duration字段可以通过各种方式进行估计,并且可以使用该字段了解如何估计持续时间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*/// 在每个数据包之后刷新I/O上下文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*/// 格式探测分数// 最大分数是AVPROBE_SCORE_MAX,它是在解解器探测格式时设置的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.** Demuxing only, set by the caller before avformat_open_input().** @sa probesize*/// 为了识别\ref AVInputFormat“输入格式”,从输入中读取的最大字节数。仅在调用方未显式设置格式时使用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;/*** ',' separated list of allowed protocols.* - encoding: unused* - decoding: set by user*/// 解码协议的白名单char *protocol_whitelist;/*** ',' separated list of disallowed protocols.* - encoding: unused* - decoding: set by user*/// 解码协议的黑名单char *protocol_blacklist;/*** IO repositioned flag.* This is set by avformat when the underlaying IO context read pointer* is repositioned, for example when doing byte based seeking.* Demuxers can use the flag to detect such changes.*/// IO重定位标志// 当底层IO上下文读指针被重新定位时,这是由avformat设置的,例如在进行基于字节的查找时// 解复用器可以使用这个标志来检测这种变化int io_repositioned;/*** Forced video codec.* This allows forcing a specific decoder, even when there are multiple with* the same codec_id.* Demuxing: Set by user*/// 允许强制一个特定的视频解码器,即使有多个具有相同的codec_idconst struct AVCodec *video_codec;/*** Forced audio codec.* This allows forcing a specific decoder, even when there are multiple with* the same codec_id.* Demuxing: Set by user*/// 允许强制一个特定的音频解码器,即使有多个具有相同的codec_idconst struct AVCodec *audio_codec;/*** Forced subtitle codec.* This allows forcing a specific decoder, even when there are multiple with* the same codec_id.* Demuxing: Set by user*/// 允许强制一个特定的字幕解码器,即使具有多个相同的codec_idconst struct AVCodec *subtitle_codec;/*** Forced data codec.* This allows forcing a specific decoder, even when there are multiple with* the same codec_id.* Demuxing: Set by user*/// 允许强制一个特定的数据解码器,即使具有多个相同的codec_idconst struct AVCodec *data_codec;/*** Number of bytes to be written as padding in a metadata header.* Demuxing: Unused.* Muxing: Set by user.*/// 在元数据头中写入填充的字节数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* - muxing: Set by user.* - demuxing: Set by user.*/// 输出格式分隔符uint8_t *dump_separator;/*** A callback for opening new IO streams.** 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.** @param s the format context* @param pb on success, the newly opened IO context should be returned here* @param url the url to open* @param flags a combination of AVIO_FLAG_** @param options a dictionary of additional options, with the same*                semantics as in avio_open2()* @return 0 on success, a negative AVERROR code on failure** @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.*/// 打开新的IO流的回调函数// 每当muxer或demuxer需要打开IO流时(对于demuxer通常来自avformat_open_input(),// 但对于某些格式也可能在其他时间发生),它将调用此回调以获取IO上下文// @note 某些复用器和解复用器会嵌套,也就是说,它们会打开一个或多个额外的内部格式上下文。//		因此,传递给这个回调的AVFormatContext指针可能与面向调用者的指针不同。但是,它将具有相同的“opaque”字段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().** Using this is preferred over io_close, because this can return an error.* Therefore this callback is used instead of io_close by the generic* libavformat code if io_close is NULL or the default.** @param s the format context* @param pb IO context to be closed and freed* @return 0 on success, a negative AVERROR code on failure*/// 用于关闭使用AVFormatContext.io_open()打开的流的回调// 使用这个函数比使用io_close更可取,因为这会返回一个错误// 因此,如果io_close为NULL或默认值,则通用libavformat代码将使用此回调来代替io_closeint (*io_close2)(struct AVFormatContext *s, AVIOContext *pb);
} AVFormatContext;

从AVFormatContext的定义来看,主要的信息包括:
(1)const struct AVInputFormat *iformat:输入容器的格式
(2)const struct AVOutputFormat *oformat:输出容器的格式
(3)AVIOContext *pb:输入输出的上下文结构体
(4)AVStream **streams:文件中流的list
(5)char *url:输入或者输出的地址
(6)int64_t bit_rate:整体流的码率
(7)enum AVCodecID video_codec_id:视频codec ID
(8)enum AVCodecID audio_codec_id:音频codec ID
(9)enum AVCodecID subtitle_codec_id:字幕codec ID
(10)enum AVCodecID data_codec_id:数据流codec ID
(11)unsigned int max_picture_buffer:最大的帧buffer
(12)char *XXX_whitelist:各类信息的白名单(位于白名单当中的工具表示可用,黑名单表示不可用)
(13)const struct AVCodec *XXX_codec:所定义的编解码器(音频、视频、字幕或者数据流)
(14)int (*io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url,int flags, AVDictionary **options):打开新的IO流
(15)int (*io_close2)(struct AVFormatContext *s, AVIOContext *pb):关闭流

从AVFormatContext的定义来看,除了定义了AVInputFormat和AVOutputFormat两种format结构体之外,还定义了输入输出上下文结构体AVIOContext、文件中流的list结构体AVStream、黑白名单list和流的打开关闭函数,这里与老版本的FFmpeg不同的地方包括:(1)将以前的char filename[1024]改成了现在的char* url,不再限制长度;(2)将AVCodec存放在AVFormatContext之中而不是AVStream之中,这里有一点将AVStream和AVCodec并列的思想,因为AVStream之中只包含了AVCodecParameters这个结构体,即只能访问部分codec的变量

下面先看看AVInputFormat和AVOutputFormat的内容(这两个定义比较简单),后续再看AVIOContext

1.2 const struct AVInputFormat *iformat

该结构体描述了输入音视频的格式,定义位于libavformat\avformat.h中

/*** @addtogroup lavf_decoding* @{*/
typedef struct AVInputFormat {/*** A comma separated list of short names for the format. New names* may be appended with a minor bump.*/// format的名称const char *name;/*** Descriptive name for the format, meant to be more human-readable* than name. You should use the NULL_IF_CONFIG_SMALL() macro* to define it.*/// format的全名const char *long_name;/*** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,* AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,* AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.*/// 定义了format的行为int flags;/*** If extensions are defined, then no probe is done. You should* usually not use extension format guessing because it is not* reliable enough*/// 如果定义了扩展,则不执行探测。通常不应该使用扩展格式猜测,因为它不够可靠const char *extensions;// AVCodecTag标识了媒体文件中的编解码格式const struct AVCodecTag * const *codec_tag;const AVClass *priv_class; ///< AVClass for the private context/*** Comma-separated list of mime types.* It is used check for matching mime types while probing.* @see av_probe_input_format2*/// mime(Multipurpose Internet Mail Extensions)的类型const char *mime_type;
} AVInputFormat;

其中AVCodecTag标识了媒体文件中的编解码格式,定义如下

typedef struct AVCodecTag {enum AVCodecID id;unsigned int tag;
} AVCodecTag;

1.3 const struct AVOutputFormat *oformat

AVOutputFormat之中记录了输出格式的类型,定义位于libavformat\avformat.h中

/*** @addtogroup lavf_encoding* @{*/
typedef struct AVOutputFormat {// 名称const char *name;/*** Descriptive name for the format, meant to be more human-readable* than name. You should use the NULL_IF_CONFIG_SMALL() macro* to define it.*/// 全名const char *long_name;// mime的类型const char *mime_type;const char *extensions; /**< comma-separated filename extensions *//* output support */// 输出codec的IDenum AVCodecID audio_codec;    /**< default audio codec */enum AVCodecID video_codec;    /**< default video codec */enum AVCodecID subtitle_codec; /**< default subtitle codec *//*** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER,* AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,* AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS,* AVFMT_TS_NONSTRICT, AVFMT_TS_NEGATIVE*/// 输出格式的行为int flags;/*** List of supported codec_id-codec_tag pairs, ordered by "better* choice first". The arrays are all terminated by AV_CODEC_ID_NONE.*/// 支持的codec_id-codec_tag对列表,按“优先选择更好”排序。数组都以AV_CODEC_ID_NONE结束const struct AVCodecTag * const *codec_tag;const AVClass *priv_class; ///< AVClass for the private context
} AVOutputFormat;

CSDN : https://blog.csdn.net/weixin_42877471
Github : https://github.com/DoFulangChen

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

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

相关文章

YOLOv5改进(八)--引入Soft-NMS非极大值抑制

文章目录 1、前言2、各类NMS代码实现2.1、general.py 3、各类NMS实现3.1、Soft-NMS3.2、GIoU-NMS3.3、DIoU-NMS3.4、CIoU-NMS3.5、EIoU-NMS 4、目标检测系列文章 1、前言 目前yolov5使用的是NMS进行极大值抑制&#xff0c;本篇文章是要将各类NMS添加到yolov5中&#xff0c;同时…

6.25作业

1.整理思维导图 2.终端输入两个数&#xff0c;判断两数是否相等&#xff0c;如果不相等&#xff0c;判断大小关系 #!/bin/bash read num1 read num2 if [ $num1 -eq $num2 ] then echo num1num2 elif [ $num1 -gt $num2 ] then echo "num1>num2" else echo &quo…

【基于构件的软件工程开发模型】

文章目录 前言一、基本概念二、优点1. 可重用性2. 易于维护3. 并行开发4. 灵活性 三、缺点1. 构件选择2. 接口管理3. 效率问题 前言 基于构件的开发模型是一种常见的方法之一&#xff0c;它将软件系统划分为独立的构件&#xff0c;并通过组装这些构件来构建整个系统。 一、基本…

200.回溯算法:子集||(力扣)

class Solution { public:vector<int> res; // 当前子集vector<vector<int>> result; // 存储所有子集void backtracing(vector<int>& nums, int index, vector<bool>& used) {result.push_back(res); // 将当前…

Unity 公用函数整理【二】

1、在规定时间时间内将一个值变化到另一个值&#xff0c;使用Mathf.Lerp实现 private float timer;[Tooltip("当前温度")]private float curTemp;[Tooltip("开始温度")]private float startTemp 20;private float maxTemp 100;/// <summary>/// 升…

【嵌入式Linux】<总览> 进程间通信(更新中)

文章目录 前言 一、管道 1. 概念 2. 匿名管道 3. 有名管道 二、内存映射区 1. 概念 2. mmap函数 3. 进程间通信&#xff08;有血缘关系&#xff09; 4. 进程间通信&#xff08;没有血缘关系&#xff09; 5. 拷贝文件 前言 在文章【嵌入式Linux】&#xff1c;总览&a…

ArkTS开发系列之事件(2.8.2手势事件)

上篇回顾&#xff1a;ArkTS开发系列之事件&#xff08;2.8.1触屏、键鼠、焦点事件&#xff09; 本篇内容&#xff1a;ArkTS开发系列之事件&#xff08;2.8.2手势事件&#xff09; 一、绑定手势方法 1. 常规手势绑定方法 Text(手势).fontSize(44).gesture(TapGesture().onAct…

Latex学习之fontspect宏包

Latex学习之fontspect宏包 一、简介 fontspec 宏包是 XeLaTeX 和 LuaLaTeX 编译器的字体配置工具。它允许用户直接使用操作系统中安装的任何 OpenType 或 TrueType 字体&#xff0c;使用 fontspec 宏包&#xff0c;你可以轻松地设置文档的主字体、 sans-serif 字体、 monospac…

浏览器断点调试(用图说话)

浏览器断点调试&#xff08;用图说话&#xff09; 1、开发者工具2、添加断点3、查看变量值 浏览器断点调试 有时候我们需要在浏览器中查看 html页面的js中的变量值。1、开发者工具 打开浏览器的开发者工具 按F12 &#xff0c;没反应的话按FnF12 2、添加断点 3、查看变量值

nodejs - - - - - 文件上传

文件上传 1. 代码如下 1. 代码如下 // 引入需要的依赖&#xff08;multer需要提前安装&#xff09; const multer require("multer"); const path require("path"); const fs require("fs");const imgPath "/keep/"; // 文件保存…

利用ref实现防抖

结合vue的customRef function debounceRef(value,time1000){ let t return customRef((track,trigger)>{ return { get(){ track() return value; } set(val){ clearTimeout(t) tsetTimeout(()>{ trigger() valueval },time) } } }) }

大模型日报2024-06-25

大模型日报 2024-06-25 大模型资讯 大模型产品 大模型论文 GenoTEX&#xff1a;基因表达数据探索基准 摘要: GenoTEX提供自动化基因表达数据探索的基准数据集&#xff0c;包含数据选择、预处理和统计分析&#xff0c;支持LLM方法评估和开发。 多模态任务向量实现多样本上下文学…

清理占道经营商贩自砸西瓜?智慧城管AI视频方案助力城市街道管理

一、背景分析 近日有新闻报道&#xff0c;在山西太原&#xff0c;城管凌晨3时许查处商贩占道经营&#xff0c;商贩将西瓜砸碎一地&#xff0c;引起热议。据悉&#xff0c;事件发生的五龙口街系当地主要街道&#xff0c;来往车辆众多。该商贩长期在该地段占道经营&#xff0c;影…

昇思25天学习打卡营第2天|快速入门

快速入门 操作步骤1.引入依赖包2.下载Mnist数据集3.划分训练集和测试集4.数据预处理5.网络构建6.模型训练7.保存模型8.加载模型9.模型预测 今天通过昇思大模型平台AI实验室提供的在线Jupyter工具&#xff0c;快速入门MindSpore。 目标&#xff1a;通过MindSpore的API快速实现一…

《昇思 25 天学习打卡营第 6 天 | 函数式自动微分 》

《昇思 25 天学习打卡营第 6 天 | 函数式自动微分 》 活动地址&#xff1a;https://xihe.mindspore.cn/events/mindspore-training-camp 签名&#xff1a;Sam9029 函数式自动微分 自动微分是深度学习中的一个核心概念&#xff0c;它允许我们自动计算模型参数的梯度&#xff0c…

云计算 | 期末梳理(下)

1.模运算 2. 拓展欧几里得算法 3.扩散和混淆、攻击的分类 香农的贡献:定义了理论安全性,提出扩散和混淆原则,奠定了密码学的理论基础。扩散:将每一位明文尽可能地散布到多个输出密文中去,以更隐蔽明文数字的统计特性。混淆:使密文的统计特性与明文密钥之间的关系尽量复杂…

深入解析直播带货系统源码:短视频商城APP开发全攻略

本篇文章&#xff0c;小编将深入解析直播带货系统的源码&#xff0c;并为开发短视频商城APP提供全攻略&#xff0c;助力开发者打造高效、稳定的带货平台。 一、直播带货系统概述 直播带货系统主要由直播模块、商品管理模块、订单处理模块、用户管理模块、以及支付模块等组成。…

Ubuntu20.04使用Samba

目录 一、Samba介绍 Samba 的主要功能 二、启动samba 三、主机操作 四、Ubuntu与windows系统中文件互联 五、修改samba路径 一、Samba介绍 Samba 是一个开源软件套件&#xff0c;用于在 Linux 和 Unix 系统上实现 SMB&#xff08;Server Message Block&#xff09;协议…

速卖通自养号测评:安全高效的推广手段

在速卖通平台上&#xff0c;卖家们常常寻求各种方法来提升商品的曝光、转化率和店铺权重。其中&#xff0c;自养号测评作为一种低成本、高回报的推广方式&#xff0c;备受关注。然而&#xff0c;若操作不当&#xff0c;也可能带来风险。以下是如何安全有效地进行自养号测评的指…

VS Code 使用 Makefile 运行 CPP项目

Installing the MinGW-w64 toolchainCMake Toolsmakelist.txt报错 1报错 2报错 3生成了 Makefile &#xff0c;如何使用 make 命令 Installing the MinGW-w64 toolchain 参见文档 将 GCC 与 MinGW 结合使用 CMake Tools 参见文档 Linux 上的 CMake 工具入门 CMake 的使用 …