ffmpeg源码分析02(函数)

av_register_all

av_register_all()调用了avcodec_register_all()。avcodec_register_all()注册了和编解码器有关的组件:硬件加速器,解码器,编码器,Parser,Bitstream Filter。av_register_all()除了调用avcodec_register_all()之外,还注册了复用器,解复用器,协议处理器。


2099527-4e1f36cf43111050.jpg
av_register_all.jpg

解码流程

1,int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)

它的声明位于libavformat\avformat.h
打开多媒体数据,并把解析出来的信息(主要是文件头信息)写入封装格式上下文AVFormatContext。
两个比较重要的内部函数
init_input():它的主要工作就是打开输入的视频数据并且探测视频的格式,得到相应的AVInputFormat。该函数的定义位于libavformat\utils.c(内部会调用avio_open)
s->iformat->read_header():读取多媒体数据文件头,根据视音频流创建相应的AVStream。

2,int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)

1.查找解码器:find_decoder()
2.打开解码器:avcodec_open2()
3.读取完整的一帧压缩编码的数据:read_frame_internal()
注:av_read_frame()内部实际上就是调用的read_frame_internal()。
4.解码一些压缩编码数据:try_decode_frame()

2099527-b7eeb2981381e943.jpg
avformat_find_stream_info.jpg

3,int av_read_frame(AVFormatContext *s, AVPacket *pkt);

读取码流中的音频若干帧或者视频一帧。例如,解码视频的时候,每解码一个视频帧,需要先调用 av_read_frame()获得一帧视频的压缩数据,然后才能对该数据进行解码。
输入一个AVFormatContext
输出AVPacket


2099527-c965cad142cc400d.jpg
av_read_frame.jpg

4,int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr,const AVPacket *avpkt)

解码一帧视频数据。输入一个压缩编码的结构体AVPacket,输出一个解码后的结构体AVFrame。该函数的声明位于libavcodec\avcodec.h

编码流程

1,int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,const char *format_name, const char *filename)

初始化一个用于输出的AVFormatContext结构体
推测输出最合适的AVOutputFormat


2099527-519daa2e16305889.png
avformat_alloc_output_context2.png

2,int avformat_write_header(AVFormatContext *s, AVDictionary **options);

用于写视频文件头,声明位于libavformat\avformat.h

3,int avio_open(AVIOContext **s, const char *filename, int flags)

该函数用于打开FFmpeg的输入输出文件。avio_open2()的声明位于libavformat\avio.h

4,int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,const AVFrame *frame, int *got_packet_ptr);

该函数用于编码一帧视频数据,声明位于libavcodec\avcodec.h
avctx:编码器的AVCodecContext。
avpkt:编码输出的AVPacket。
frame:编码输入的AVFrame。
got_packet_ptr:成功编码一个AVPacket的时候设置为1。

5,int av_write_frame(AVFormatContext *s, AVPacket *pkt);

用于输出一帧视音频数据,它的声明位于libavformat\avformat.h
s:用于输出的AVFormatContext。
pkt:等待输出的AVPacket。

6,av_write_trailer()

用于输出文件尾,它的声明位于libavformat\avformat.h

猜你喜欢

转载自blog.csdn.net/weixin_34417814/article/details/87384020