ffmpeg中有接触到的上下文

ffmpeg中有接触到的上下文

AVFormatContext
AVCodecContext

首先解释上下文:

查找资料后我理解的上下文:
一个可以让操作实现的环境,这个环境里有可以实现操作的算法,于是我们可以使用这个环境而使Windows去做我们要进行的操作(比如:解码)。

参考资料1
参考资料2

AVFormatContext (格式上下文)
:是API中直接接触到的结构体,位于avformat.h中,是音视频数据,也就是音视频文件(通常接触到的mp3/mp4等文件)的一种抽象封装,在FFMpeg格式转换过程中实现保存输入和输出的相关数据。

也就是这个结构体包含了媒体流的格式信息,比较重要的有:

  • AVInputFormat或者AVOutputFormat:只能同时存在一个。
  • AVStream
  • AVPacket
  • title、author、copyright、duration、
    start_time、bit_rate等。

AVFormatContext结构体
FFmpeg:AVFormatContext结构体分析

AVFormatContext的使用:

AVFormatContext *pAVFormatContext = avformat_alloc_context ();//开空间
avformat_open_input(&pAVFormatContext,"a.mp4",nullptr,nullptr);//读取视频文件,将视频信息存入AVFormatContext对象中

AVCodecContext:保存了AVCodec指针和与codec相关的数据,如video的width、height,audio的sample rate等。

  • AVFormatContext中有媒体流
  • 媒体流中有codec

所以可以从AVFormatContext对象中获取codec,方法如下:

 AVStream *outstream = avformat_new_stream (pAVFormatContext,NULL);
 AVCodec CodecContext = outstream->codec;//查找编码器

猜你喜欢

转载自blog.csdn.net/m0_49036370/article/details/110914490
今日推荐