音视频流媒体之_FFmpeg(从入门到精通)之第三节(FFmpeg音视频编解码常用API详解——解封装)

本文讲解:FFmpeg解封装的常用的API以及结构体

一,解封装注册函数:
av_register_all(); //该函数是用来注册解封装函数,用于解封装函数之前

avformat_network_init(); //该函数初始化网络模块

avformat_open_input(…); // 解析函数

avformat_find_stream_info(…); //查找流信息

av_find_best_stream(…); //找到音频和视频

AVFormatContext // 封装的上下文

AVStream //流的参数信息

AVPacket //解封装完成后的数据包,包含了pts,dts,stream_index;是否是视频的关键帧

av_read_frame(…); //读取AVPacket

二,详解上述API:

1,avformat_open_input();详解:
参数:
(1): AVFormatContext **ps;
(2): const char *url;
(3): AVInputFormat *fmt; //一般情况用NULL;(探测)
(4): AVDictionary **options; //(字典数组)

2,AVFormatContext;详解:
成员:
(1): AVIOContext *pb; //IO的Context
(2): char fileName[1024]; //文件名
(3): unsigned int nb_streams;//数组大小;一般情况0是视频,1是音频
(4): AVStream **streams; //音频视频的信息,参数等;
(5): int64_t duration; //AV_TIME_BASE;
(6): int64_t bit_rate; //bit率

void avformat_close_input(AVFormatContext **s); //释放AVFormatContext对象资源;

int av_format_find_stream_info(AVFormatContext *ic, AVDictionary **option); //获取流信息;

int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb,
int related_stream, AVCodec **decoder_ret, int flags); //获取视频流信息;
参数详解:
1.AVFormatContext *ic,//封装的格式上下文
2.enum AVMediaType; //类型
3.wanted_stream_nb;// 期望获取的流的编号,-1为默认自动选择
4.related_stream; //相关音/视频,一般情况用不到,可以传-1;
5.AVCodec **decoder_ret; //一般不设置;
6.flags ; //一般不用管
返回值为流的信息;

发布了18 篇原创文章 · 获赞 12 · 访问量 413

猜你喜欢

转载自blog.csdn.net/qq_41408585/article/details/104242095