1、avcodec_find_decoder()
2、avcodec_open2()
3、avformat_open_input()
4、avformat_alloc_output_context2()
5、avformat_new_stream()
6、av_read_frame()
7、av_interleaved_write_frame()
8、avcodec_copy_context()
9、avio_open2()
10、avformat_write_header()
11、avio_open()
12、av_frame_alloc()
13、avpicture_get_size()
14、avpicture_fill()
15、avformat_find_stream_info()
16、avcodec_decode_video2()
17、avcodec_close()
18、avcodec_send_frame()
19、avcodec_receive_frame()
#################################################
#################################################
1、av_register_all()
注册了所有的文件格式和编解码器的库
#################################################
#################################################
1、avcodec_find_decoder()
AVCodec *avcodec_find_decoder(enum AVCodecID id);
函数的参数是一个解码器的ID,返回查找到的解码器(没有找到就返回NULL)。
#################################################
#################################################
2、avcodec_open2()
int avcodec_open(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
用中文简单转述一下avcodec_open2()各个参数的含义:
avctx:需要初始化的AVCodecContext。
codec:输入的AVCodec
options:一些选项。例如使用libx264编码的时候,“preset”,“tune”等都可以通过该参数设置。
#################################################
#################################################
3、avformat_open_input(int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
把结构体和文件相关联
4、 int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, const char *format_name, const char *filename);ps:函数调用成功之后处理过的AVFormatContext结构体。
file:打开的视音频流的URL。
fmt:强制指定AVFormatContext中AVInputFormat的。这个参数一般情况下可以设置为NULL,这样FFmpeg可以自动检测AVInputFormat。dictionay:附加的一些选项,一般情况下可以设置为NULL。
函数执行成功的话,其返回值大于等于0。
#################################################
#################################################
/** * Open an input stream and read the header. The codecs are not opened. * The stream must be closed with avformat_close_input(). * * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context). * May be a pointer to NULL, in which case an AVFormatContext is allocated by this * function and written into ps. * Note that a user-supplied AVFormatContext will be freed on failure. * @param filename Name of the stream to open. * @param fmt If non-NULL, this parameter forces a specific input format. * Otherwise the format is autodetected. * @param options A dictionary filled with AVFormatContext and demuxer-private options. * On return this parameter will be destroyed and replaced with a dict containing * options that were not found. May be NULL. * * @return 0 on success, a negative AVERROR on failure. * * @note If you want to use custom IO, preallocate the format context and set its pb field. */ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
ctx:函数调用成功之后创建的AVFormatContext结构体。
oformat:指定AVFormatContext中的AVOutputFormat,用于确定输出格式。如果指定为NULL,可以设定后两个参数(format_name或者filename)由FFmpeg猜测输出格式。
PS:使用该参数需要自己手动获取AVOutputFormat,相对于使用后两个参数来说要麻烦一些。
format_name:指定输出格式的名称。根据格式名称,FFmpeg会推测输出格式。输出格式可以是“flv”,“mkv”等等。filename:指定输出文件的名称。根据文件名称,FFmpeg会推测输出格式。文件名称可以是“xx.flv”,“yy.mkv”等等。
函数执行成功的话,其返回值大于等于0。
#################################################
#################################################
5、 avformat_new_stream()AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
在 AVFormatContext 里增加了 AVStream 通道(相关的index已经被设置了)。之后,我们就可以自行设置 AVStream 的一些参数信息。例如 : codec_id , format ,bit_rate ,width , height ... ...
#################################################
#################################################
6、av_read_frame()
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
av_read_frame()的作用是读取码流中的音频若干帧或者视频一帧。例如,解码视频的时候,每解码一个视频帧,需要先调用 av_read_frame()获得一帧视频的压缩数据,然后才能对该数据进行解码(例如H.264中一帧压缩数据通常对应一个NAL)。
#################################################
#################################################
#################################################
#################################################
#################################################
#################################################
- int avio_open2(AVIOContext **s, const char *url, int flags,
- const AVIOInterruptCB *int_cb, AVDictionary **options);
-
-
-
-
- avio_open2()函数参数的含义如下:
-
-
-
-
-
s:函数调用成功之后创建的AVIOContext结构体。
url:输入输出协议的地址(文件也是一种“广义”的协议,对于文件来说就是文件的路径)。
flags:打开地址的方式。可以选择只读,只写,或者读写。取值如下。
AVIO_FLAG_READ:只读。
AVIO_FLAG_WRITE:只写。
AVIO_FLAG_READ_WRITE:读写。
int_cb:目前还没有用过。
options:目前还没有用过。
-
-
-
-
-
-
-
-
#################################################
#################################################
-
-
-
-
-
-
-
-
-
-
- 写视频文件头
-
-
-
-
-
-
-
-
-
- int avformat_write_header(AVFormatContext *s, AVDictionary **options);
-
-
-
-
-
-
-
-
-
-
- 简单解释一下它的参数的含义:
s:用于输出的AVFormatContext。
函数正常执行后返回值等于0。
options:额外的选项,目前没有深入研究过,一般为NULL。 -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#################################################
#################################################
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 简单解释一下它的参数的含义:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
AVIO_FLAG_READ:只读。
AVIO_FLAG_WRITE:只写。
AVIO_FLAG_READ_WRITE:读写。
#################################################
#################################################
/AVFrame.extended_buf,在至少存在一个参考的时候(如AVFrame.buf[0] != NULL),则该对象被标记为“被引用”。在此情况下,AVFrame所包含的每一组数据必须包含于AVFrame的缓存中。
#################################################
#################################################
#################################################
#################################################
Fill in the AVPicture fields.
The fields of the given AVPicture are filled in by using the 'ptr' address which points to the image data buffer. Depending on the specified picture format, one or multiple image data pointers and line sizes will be set.
If a planar format is specified, several pointers will be set pointing to the different picture planes and the line sizes of the different planes will be stored in the lines_sizes array.
int avpicture_fill(AVPicture *picture,
uint8_t *ptr,
int pix_fmt,
int width,
int height);
Parameters
picture
AVPicture *picture
AVPicture whose fields are to be filled in.
avpicture填写的字段。
ptr
uint8_t *ptr
Buffer which will contain or contains the actual image data.
缓冲区,该缓冲区将包含或包含实际的图像数据。
pix_fmt
int pix_fmt
The format in which the picture data is stored. The format must be one of the values in the PixelFormat enum.
存储图像数据的格式。格式必须PixelFormat枚举的值之一。
width
int width
The width of the image in pixels.
像素的图像宽度。
height
int height
The height of the image in pixels.
像素中的图像的高度。
Return value
Size of the image data in bytes
以字节为单位的图像数据的大小
#################################################
#################################################
- int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
简单解释一下它的参数的含义:
ic:输入的AVFormatContext。
函数正常执行后返回值大于等于0。
options:额外的选项,目前没有深入研究过。
- #################################################################################################
该方法的各个参数:
AVCodecContext *avctx:编解码上下文环境,定义了编解码操作的一些细节;
AVFrame *picture:输出参数;传递到该方法的对象本身必须在外部由av_frame_alloc()分配空间,而实际解码过后的数据储存区将由AVCodecContext.get_buffer2()分配;AVCodecContext.refcounted_frames表示该frame的引用计数,当这个值为1时,表示有另外一帧将该帧用作参考帧,而且参考帧返回给调用者;当参考完成时,调用者需要调用av_frame_unref()方法解除对该帧的参考;av_frame_is_writable()可以通过返回值是否为1来验证该帧是否可写。
int *got_picture_ptr:该值为0表明没有图像可以解码,否则表明有图像可以解码;
const AVPacket *avpkt:输入参数,包含待解码数据。
int avcodec_send_frame | ( | AVCodecContext * | avctx, |
const AVFrame * | frame | ||
) |
Parameters
avctx | codec context | |
[in] | frame | AVFrame containing the raw audio or video frame to be encoded |