您的位置:首页 > 理论基础 > 数据结构算法

ffmpeg常用数据结构一

2013-03-30 16:09 344 查看
整体结构图:



附:

聚合(Aggregation) : 表示has-a的关系,是一种不稳定的包含关系。较强于一般关联,有整体与局部的关系,并且没有了整体,局部也可单独存在。如公司和员工的关系,公司包含员工,但如果公司倒闭,员工依然可以换公司。在类图使用空心的菱形表示,菱形从局部指向整体。



依赖(Dependency):对象之间最弱的一种关联方式,是临时性的关联。代码中一般指由局部变量、函数参数、返回值建立的对于其他对象的调用关系。一个类调用被依赖类中的某些方法而得以完成这个类的一些职责。在类图使用带箭头的虚线表示,箭头从使用类指向被依赖的类。

AVCodecContext

这是一个描述编解码器上下文的数据结构,包含了众多编解码器需要的参数信息,如下列出了部分比较重要的域:

typedef struct AVCodecContext {

......

/**

* some codecs need / can use extradata like Huffman tables.

* mjpeg: Huffman tables

* rv10: additional flags

* mpeg4: global headers (they can be in the bitstream or here)

* The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger

* than extradata_size to avoid prolems if it is read with the bitstream reader.

* The bytewise contents of extradata must not depend on the architecture or CPU endianness.

* - encoding: Set/allocated/freed by libavcodec.

* - decoding: Set/allocated/freed by user.

*/

uint8_t *extradata;

intextradata_size;

/**

* This is the fundamental unit of time (in seconds) in terms

* of which frame timestamps are represented. For fixed-fps content,

* timebase should be 1/framerate and timestamp increments should be

* identically 1.

* - encoding: MUST be set by user.

* - decoding: Set by libavcodec.

*/

AVRationaltime_base;

/* video only */

/**

* picture width / height.

* - encoding: MUST be set by user.

* - decoding: Set by libavcodec.

* Note: For compatibility it is possible to set this instead of

* coded_width/height before decoding.

*/

int width, height;

......

/* audio only */

intsample_rate; ///< samples per second

int channels; ///< number of audio channels

/**

* audio sample format

* - encoding: Set by user.

* - decoding: Set by libavcodec.

*/

enumSampleFormatsample_fmt; ///< sample format

/* The following data should not be initialized. */

/**

* Samples per packet, initialized when calling 'init'.

*/

intframe_size;

intframe_number; ///< audio or video frame number

......

char codec_name[32];

enumAVMediaTypecodec_type; /* see AVMEDIA_TYPE_xxx */

enumCodecIDcodec_id; /* see CODEC_ID_xxx */

/**

* fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').

* This is used to work around some encoder bugs.

* A demuxer should set this to what is stored in the field used to identify the codec.

* If there are multiple such fields in a container then the demuxer should choose the one

* which maximizes the information about the used codec.

* If the codec tag field in a container is larger then 32 bits then the demuxer should

* remap the longer ID to 32 bits with a table or other structure. Alternatively a new

* extra_codec_tag + size could be added but for this a clear advantage must be demonstrated

* first.

* - encoding: Set by user, if not then the default based on codec_id will be used.

* - decoding: Set by user, will be converted to uppercase by libavcodec during init.

*/

unsigned intcodec_tag;

......

/**

* Size of the frame reordering buffer in the decoder.

* For MPEG-2 it is 1 IPB or 0 low delay IP.

* - encoding: Set by libavcodec.

* - decoding: Set by libavcodec.

*/

inthas_b_frames;

/**

* number of bytes per packet if constant and known or 0

* Used by some WAV based audio codecs.

*/

intblock_align;

......

/**

* bits per sample/pixel from the demuxer (needed for huffyuv).

* - encoding: Set by libavcodec.

* - decoding: Set by user.

*/

intbits_per_coded_sample;

......

} AVCodecContext;

如果是单纯使用libavcodec,这部分信息需要调用者进行初始化;如果是使用整个FFMPEG库,这部分信息在调用 avformat_open_input和avformat_find_stream_info的过程中根据文件的头信息及媒体流内的头部信息完成初始化。其中几个主要域的释义如下:

1. extradata/extradata_size:这个buffer中存放了解码器可能会用到的额外信息,在av_read_frame中填充。一般来说,首先,某种具体格式的demuxer在读取格式头信息的时候会填充extradata,其次,如果demuxer没有做这个事情,比如可能在头部压根儿就没有相关的编解码信息,则相应的parser会继续从已经解复用出来的媒体流中继续寻找。在没有找到任何额外信息的情况下,这个buffer指针为空。

2. time_base:

3. width/height:视频的宽和高。

4. sample_rate/channels:音频的采样率和信道数目。

5. sample_fmt: 音频的原始采样格式。

6. codec_name/codec_type/codec_id/codec_tag:编解码器的信息。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: