ffmpeg处理流程

图解

在这里插入图片描述

主流程

1、初始化avformat

av_register_all

2、初始化avformat网络

avformat_network_init

3、初始化输入流

1、申请AVFormatContext

avformat_alloc_context

2、打开输入流

avformat_open_input

3、探测输入流信息

avformat_find_stream_info

4、查找解码器(视频和音频)

avcodec_find_decoder

5、根据编码器初始化AVCodecContext

avcodec_open2

4、初始化输出流

1、申请AVFormatContext

avformat_alloc_output_context2

2、查找编码器(音频和视频)

avcodec_find_encoder

3、根据编码器创建AVCodecContext

avcodec_alloc_context3

4、根据编码器类型初始化AVCodecContext

avcodec_open2

5、根据AVFormatContext和编码器创建输出流

avformat_new_stream

6、根据URL初始化AVIOContext

avio_open

7、向输出文件写流的头信息

avformat_write_header

5、初始化滤镜

1、申请AVFilterInOut(输入和输出)

avfilter_inout_alloc

2、打开滤镜(输入滤镜和输入滤镜)

avfilter_get_by_name

3、申请AVFilterGraph

avfilter_graph_alloc

4、构造滤镜初始化参数

5、根据AVFilterGraph和初始化参数创建过滤器

avfilter_graph_create_filter

6、构造滤镜链

7、解析滤镜命令行参数

avfilter_graph_parse_ptr

8、检查及配置滤镜链

avfilter_graph_config

6、从AVFormatContext读取packet

av_read_frame

7、解码packet

avcodec_decode_video2或avcodec_decode_audio4

8、添加进滤镜

av_buffersrc_add_frame

9、从滤镜中读取数据

av_buffersink_get_frame_flags

10、编码packet

avcodec_encode_video2或avcodec_encode_audio2

11、输出数据

av_write_frame

12、写输出尾

av_write_trailer

发布了59 篇原创文章 · 获赞 22 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/Martin_chen2/article/details/98471576
今日推荐