AVIOContext
typedef struct AVIOContext { /** * A class for private options. * * If this AVIOContext is created by avio_open2(), av_class is set and * passes the options down to protocols. * * If this AVIOContext is manually allocated, then av_class may be set by * the caller. * * warning -- this field can be NULL, be sure to not pass this AVIOContext * to any av_opt_* functions in that case. */ const AVClass *av_class; unsigned char *buffer; /**< Start of the buffer. */ int buffer_size; /**< Maximum buffer size */ unsigned char *buf_ptr; /**< Current position in the buffer */ unsigned char *buf_end; /**< End of the data, may be less than buffer+buffer_size if the read function returned less data than requested, e.g. for streams where no more data has been received yet. */ void *opaque; /**< A private pointer, passed to the read/write/seek/... functions. */ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size); int (*write_packet)(void *opaque, uint8_t *buf, int buf_size); int64_t (*seek)(void *opaque, int64_t offset, int whence); int64_t pos; /**< position in the file of the current buffer */ int must_flush; /**< true if the next seek should flush */ int eof_reached; /**< true if eof reached */ int write_flag; /**< true if open for writing */ int max_packet_size; unsigned long checksum; unsigned char *checksum_ptr; unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size); int error; /**< contains the error code or 0 if no error happened */ /** * Pause or resume playback for network streaming protocols - e.g. MMS. */ int (*read_pause)(void *opaque, int pause); /** * Seek to a given timestamp in stream with the specified stream_index. * Needed for some network streaming protocols which don't support seeking * to byte position. */ int64_t (*read_seek)(void *opaque, int stream_index, int64_t timestamp, int flags); /** * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable. */ int seekable; /** * max filesize, used to limit allocations * This field is internal to libavformat and access from outside is not allowed. */ int64_t maxsize; /** * avio_read and avio_write should if possible be satisfied directly * instead of going through a buffer, and avio_seek will always * call the underlying seek function directly. */ int direct; /** * Bytes read statistic * This field is internal to libavformat and access from outside is not allowed. */ int64_t bytes_read; /** * seek statistic * This field is internal to libavformat and access from outside is not allowed. */ int seek_count; /** * writeout statistic * This field is internal to libavformat and access from outside is not allowed. */ int writeout_count; /** * Original buffer size * used internally after probing and ensure seekback to reset the buffer size * This field is internal to libavformat and access from outside is not allowed. */ int orig_buffer_size; } AVIOContext;
avio_alloc_context
/** * Allocate and initialize an AVIOContext for buffered I/O. It must be later * freed with av_free(). * * @param buffer Memory block for input/output operations via AVIOContext. * The buffer must be allocated with av_malloc() and friends. * It may be freed and replaced with a new buffer by libavformat. * AVIOContext.buffer holds the buffer currently in use, * which must be later freed with av_free(). * @param buffer_size The buffer size is very important for performance. * For protocols with fixed blocksize it should be set to this blocksize. * For others a typical size is a cache page, e.g. 4kb. * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise. * @param opaque An opaque pointer to user-specific data. * @param read_packet A function for refilling the buffer, may be NULL. * @param write_packet A function for writing the buffer contents, may be NULL. * The function may not change the input buffers content. * @param seek A function for seeking to specified byte position, may be NULL. * * @return Allocated AVIOContext or NULL on failure. */ AVIOContext *avio_alloc_context( unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t (*seek)(void *opaque, int64_t offset, int whence));
负责数据输入输出,通过avio_alloc_context函数可自定义该结构体的相关参数,比如第5和第6个参数可以自定义读写的回调函数,实现自己的IO。
AVFormatContext
包含文件一些基本的信息,将其中的pb指向自己定义的AVIOContext就可以实现自己的IO了,比如可以直接从内存中读取和写入数据等等。
AVCodecContext
包含码流的一些具体信息,内容很多,像视频的宽高,平均比特率,解码器信息,音频的采样率,声道数,采样格式等
AVCodec
待续
AVPacket
待续
AVFrame
存放解码后的原始数据,
/** * For video, size in bytes of each picture line. * For audio, size in bytes of each plane. * * For audio, only linesize[0] may be set. For planar audio, each channel * plane must be the same size. * * For video the linesizes should be multiples of the CPUs alignment * preference, this is 16 or 32 for modern desktop CPUs. * Some code requires such alignment other code can be slower without * correct alignment, for yet other it makes no difference. * * @note The linesize may be larger than the size of usable data -- there * may be extra padding present for performance reasons. */ int linesize[AV_NUM_DATA_POINTERS];
linesize 对于视频,存放一行图像的大小(字节)。对于音频,存放一个声道一个采样的大小(字节)
/** * width and height of the video frame */ int width, height;
width ,height,视频的宽高
/** * number of audio samples (per channel) described by this frame */ int nb_samples;
nb_samples,对于音频frame来说,此frame含有多少个采样
/** * format of the frame, -1 if unknown or unset * Values correspond to enum AVPixelFormat for video frames, * enum AVSampleFormat for audio) */ int format;
format,音视频格式,视频在AVPixelFormat枚举变量中,音频在AVSampleFormat中
/** * 1 -> keyframe, 0-> not *是否关键帧,1是,0不是 */ int key_frame;
key_frame,是否关键帧,1是,0不是
/** * Sample rate of the audio data. */ int sample_rate;
sample_rate,音频采样率