avformat_new_stream的使用方法
一:介绍
1.1 AVStream
首先了解下 AVStream : http://ffmpeg.org/doxygen/3.1/structAVStream.html
AVStream 即是流通道。例如我们将 H264 和 AAC 码流存储为MP4文件的时候,就需要在 MP4文件中增加两个流通道,一个存储Video:H264,一个存储Audio:AAC。(假设H264和AAC只包含单个流通道)。
AVStream包含很多参数,用于记录通道信息,其中最重要的是 :
AVCodecParameters * codecpar :用于记录编码后的流信息,即通道中存储的流的编码信息。
AVRational time_base :AVStream通道的时间基,时间基是个相当重要的概念。(可参考之后的关于ffmpeg时间的文章)
需要注意的是:现在的 ffmpeg 3.1.4版本已经使用AVCodecParameters * codecpar替换了原先的CodecContext* codec !
1.2 avformat_new_stream
avformat_new_stream 在 AVFormatContext 中创建 Stream 通道。
AVFormatContext :
unsigned int nb_streams; 记录stream通道数目。
AVStream **streams; 存储stream通道。
AVStream :
int index; 在AVFormatContext 中所处的通道索引
avformat_new_stream之后便在 AVFormatContext 里增加了 AVStream 通道(相关的index已经被设置了)。之后,我们就可以自行设置 AVStream 的一些参数信息。例如 : codec_id , format ,bit_rate ,width , height ... ...