当前是用的是3.4版本的FFmpeg
av_register_all
    avformat_open_input
        avformat_find_stream_info
            avcodec_find_decoder
                avcodec_open2
av_read_frame
    avcodec_send_packet
        avcodec_receive_frame


申请过程
1)调用avformat_alloc_context创建一个AVFormatContext变量的实例pAVFormatContext
AVFormatContext* pAVFormatContext = avformat_alloc_context();


2)调用avio_alloc_context创建一个AVIOContext变量的实例pAVIOContext
AVIOContext* pAVIOContext = avio_alloc_context(mallocBuffer,  mallocBufferSize, 0, this, ReadStreamData, NULL, NULL);
该函数中ReadStreamData用于读取读取的网络或者文件中的视频或者音频流的函数,mallocBuffer用于保存读取到的数据用于分析,mallocBufferSize是分配的缓存长度,一旦mallocBufferSize申请的缓存长度小于返回读取的数据长度会导致拷贝到缓存中的数据越界,导致程序崩溃


3)如果已经知道数据的格式为h264,调用av_find_input_format创建一个AVInputFormat变量的实例pAVInputFormat
AVInputFormat* pAVInputFormat = av_find_input_format("h264");
pAVFormatContext->iformat = pAVInputFormat;
if (avformat_open_input(&pAVFormatContext, "", pAVInputFormat, NULL) < 0)


4)开始探测码流格式
avformat_find_stream_info(pAVFormatContext, NULL);



释放过程
avformat_close_input(pAVFormatContext);

分析该函数分为三部分
第一部分
关闭输入:
    if (s->iformat)
        if (s->iformat->read_close)
            s->iformat->read_close(s);
对于播放rtsp://admin:admin888@192.168.28.130:554/h264/ch1/main/av_stream,主要是发送TearDown指令给摄像机


第二部分
avio_close(pb)


第三部分
avformat_free_context(s)
该函数的核心就是释放申请创建的视频和音频的流  
 for (i = s->nb_streams - 1; i >= 0; i--)
        ff_free_stream(s, s->streams[i]);