音视频码流播放流程
##读取文件并打印视频流信息
#include "stdafx.h"
#include <string>
#include "ScopeGuard.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <libavformat/avformat.h>
#ifdef __cplusplus
}
#endif
#pragma comment(lib,"avformat.lib")
int main()
{
AVFormatContext* ifmt_ctx = nullptr;
const char* file_name = "D:\\rtsp_test\\h264.mp4";
int res = avformat_open_input(&ifmt_ctx, file_name, nullptr, nullptr);//打开文件流
if (res != 0){
fprintf(stderr, "avformat_open_input error\n");
getchar();
return 0;
}
ON_SCOPE_EXIT([&] {avformat_close_input(&ifmt_ctx); });
res = avformat_find_stream_info(ifmt_ctx, nullptr);//查询流信息
if (res < 0) {
fprintf(stderr, "avformat_open_input error\n");
getchar();
return 0;
}
int video_stream_no = -1;
for (unsigned int i = 0; i < ifmt_ctx->nb_streams; ++i){
if (AVMEDIA_TYPE_VIDEO == ifmt_ctx->streams[i]->codecpar->codec_type){
video_stream_no = i;
break;
}
}
if(-1!=video_stream_no)
av_dump_format(ifmt_ctx, video_stream_no, file_name, 0);//打印视频流信息
getchar();
return 0;
}
输出信息如下图:
使用的ffmpeg版本号
ffmpeg version git-2020-03-01-1281399