解码的数据读取:
一个多媒体文件包含有多个流(视频流 video stream,音频流 audio stream,字幕等)
流是一种抽象的概念,表示一连串的数据元素;流中的数据元素称为帧Frame。也就是说多媒体文件中,主要有两种数据:流Stream及其数据元素帧Frame。
在FFmpeg自然有与这两种数据相对应的抽象:AVStream和AVPacket。
解码之前的第一步便是获取流数据+流信息,获取流的方式由两种:
①读取媒体文件以获取媒体信息:
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
该接口是通过读取file来获取AVFormatContext,并从AVForamtContext中再获取AVCodecContext信息。
FILE --> avformat_open_input() --> AVFormatContext --> av_find_stream_info() --> AVStream --> AVStream::codec
--> AVCodecContext --> av_init_packet() --> AVPacket --> pkt.size+pkt.data --> avcodec_alloc_frame() --> AVFrame
②通过手动设置媒体信息来处理流数据
STREAM --> avcodec_find_decoder() --> AVCodec --> avcodec_alloc_context3() --> AVCodecContext --> av_init_packet() --> AVPacket --> pkt.size+pkt.data --> avcodec_alloc_frame() --> AVFrame
下图是读取文件模式的解码流程: