ffmpeg学习——播放器解码流程 (转前编辑)

原文链接:http://blog.chinaunix.net/uid-26611383-id-3976154.html

1、播放器解码流程

                           

2、Demux解复用:媒体文件中音视频数据是压缩在一起的,单压缩算法不同,所以解码前需先将音视频数据解绑,解复用即将音视频数据分开

                   

3、解码,FFmpeg中解码流程对应的API函数

Ffmpeg中Demux这一步是通过

avformat_open_input()    :读出文件的头部信息,并做demux,之后可以读取媒体文件中的音频和视频流

av_read_frame()        :从音频和视频流中读取出基本数据流packet

avcodec_decode_video2():读取packet,使用相应的api进行解码

 

例:读取文件头信息

#include<libavformat/avformat.h>

static ShowUseage(const char*p){
    printf("you must specify an input file as:%s you file.avi !!!\n",p);
}
int main(intargc,char*argv[])
{
    AVFormatContext* pFormatContext=NULL;
    if(argc<2) {
        ShowUseage(argv[0]);
        return -1;
    }
    char* filepath=argv[1];
    av_register_all();
    //pFormatContext=avformat_alloc_context();
    if(avformat_open_input(&pFormatContext,filepath,NULL,NULL)!=0)    //Open the media file and read the header

    {
        printf("Can not open the media file you specified !\n");
        return -1;
    }
    printf("****************file information*****************\n");
    av_dump_format(pFormatContext,0,filepath,0);//dump input information to the stdio
    printf("*************************************************\n");
    avformat_close_input(&pFormatContext);
    return 0;
}

 

 

 

posted @ 2015-10-21 09:57  Samaritan  阅读(430)  评论(0编辑  收藏  举报