# FFmpegDemo **Repository Path**: xiaerfei/FFmpegDemo ## Basic Information - **Project Name**: FFmpegDemo - **Description**: FFmpegDemo - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2019-04-17 - **Last Updated**: 2024-03-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # FFmpegDemo ## 步骤 1.创建文件上下文 AVFormatContext *pFormatCtx = NULL; 2.打开文件(读一些文件的信息,但是AVStream中大多数字段都还没有填充) avformat_open_input(&pFormatCtx, filename, NULL, NULL) 3.填充文件中流的信息(更新AVStream这个结构体中的字段,检测这些重要字段,如果是空白的,就设法填充它们,部分可能需要解码。因为在解析文件头的时候,已经掌握了大量的信息) avformat_find_stream_info(pFormatCtx, NULL) 4.寻找流的索引 pFormatCtx->nb_streams 给出这个视频文件中有多少个流 pFormatCtx->streams[i]->codec->codec_type 中能够拿到这个流是什么 视频流(AVMEDIA_TYPE_VIDEO)、 音频流(AVMEDIA_TYPE_AUDIO)、 字幕流(AVMEDIA_TYPE_SUBTITLE) i 为对应流的索引 5.创建流解码的上下文环境 AVCodecContext *codecCtx = avcodec_alloc_context3(NULL); 将流的一些信息参数拷贝至codecCtx avcodec_parameters_to_context(codecCtx, pFormatCtx->streams[stream_index]->codecpar); 6.找到对应的解码器 AVCodec *codec = avcodec_find_decoder(codecCtx->codec_id); 7.打开解码器 avcodec_open2(codecCtx, codec, NULL) ------- [SDL_AudioSpec结构体分析](https://my.oschina.net/u/735973/blog/780566)