第一个FFMPEG程序

1.将相关的库及头文件添加

2.在代码中加头文件

extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
};

注意加extern "C"

3.代码

AVFormatContext *pFormatCtx = avformat_alloc_context();

if (avformat_open_input(&pFormatCtx, "1.mp4", NULL, NULL)) {
fprintf(stderr, "open input failed\n");
return ;
}

if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
fprintf(stderr, "find stream info failed\n");
return ;
}

int videoStream = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);

printf("nb:%d, url:%s, time:%ld, duration:%ld, bitRate:%ld, videoStream:%d\n",
pFormatCtx->nb_streams, pFormatCtx->url, pFormatCtx->start_time, pFormatCtx->duration,
pFormatCtx->bit_rate, videoStream);

4.其他的错误可以直接将错误在百度中搜。

posted @ 2021-11-27 10:42  泽良_小涛  阅读(49)  评论(0编辑  收藏  举报