Visual c++ ';avcodec解码视频&x27;ffmpeg不';行不通
我使用vc++express,并将使用ffmpeg 但在第一个项目中,我遇到了麻烦 vc++在commpile进程上显示“标识符”avcodec\U decode\U video:“未找到标识符” 我不知道为什么 下一个是我编码了什么。。。Visual c++ ';avcodec解码视频&x27;ffmpeg不';行不通,visual-c++,ffmpeg,Visual C++,Ffmpeg,我使用vc++express,并将使用ffmpeg 但在第一个项目中,我遇到了麻烦 vc++在commpile进程上显示“标识符”avcodec\U decode\U video:“未找到标识符” 我不知道为什么 下一个是我编码了什么。。。 包括“avcodec.h” 包括“avformat.h” 包括“swscale.h” int main(int argc,char*argv[]) { av_寄存器_all(); AVFormatContext*pFormatCtx; //打开视频文件 如
包括“avcodec.h”
包括“avformat.h”
包括“swscale.h”
int main(int argc,char*argv[])
{
av_寄存器_all();
AVFormatContext*pFormatCtx;
//打开视频文件
如果(av打开输入文件(&pFormatCtx,argv[1],NULL,0,NULL)!=0)
return-1;//无法打开文件
//检索流信息
如果(av)查找流信息(pFormatCtx)流[视频流]->编解码器;
AVCodec*pCodec;
//查找视频流的解码器
pCodec=avcodec\u find\u解码器(pCodecCtx->codec\u id);
if(pCodec==NULL){
fprintf(stderr,“不支持的编解码器!\n”);
return-1;//找不到编解码器
}
//开放式编解码器
如果(avcodec_打开(PCODECTX,pCodec)宽度,PCODECTX->高度);
缓冲区=(uint8_t*)av_malloc(numBytes*sizeof(uint8_t));
//将缓冲区的适当部分指定给pFrameRGB中的图像平面
//请注意,pFrameRGB是一个AVFrame,但AVFrame是一个超集
//AVPicture的应用
avpicture_fill((avpicture*)pFrameRGB、缓冲器、PIX_FMT_RGB24、PCODECTX->宽度、PCODECTX->高度);
int框架完成;
数据包;
i=0;
而(av_读取_帧(pFormatCtx和数据包)>=0){
if(数据包流\索引==视频流){
**//这里出现编译错误**
avcodec_decode_视频(pCodecCtx、pFrame和frameFinished、packet.data、packet.size);
如果(框架完成){
img_convert((AVPicture*)pFram eRGB,PIX_FMT_RGB24,(AVPicture*)pFrame,pCodecCtx->PIX_FMT,pCodecCtx->宽度,pCodecCtx->高度);
}
av_免费_数据包(&数据包);
}
无AVU(缓冲区);
无AVU(pFrameRGB);
无AVU(pFrame);
avcodec_关闭(PCODECTX);
av_关闭_输入_文件(pFormatCtx);
返回0;
}可能只是因为ffmpeg中的avcodec\U decode\U video 2取代了avcodec\U decode\U video?
我建议您在正确设置代码格式方面投入更多的精力:一般来说,当您做出自己的努力时,人们更可能会提供帮助……在任何情况下,avcodec\u decode\u视频声明的标题是什么?您是否遗漏了一个包含?问9个问题,不接受回答,不投票->不太令人鼓舞。
include "avcodec.h"
include "avformat.h"
include "swscale.h"
int main(int argc, char *argv[])
{
av_register_all();
AVFormatContext *pFormatCtx;
// Open video file
if(av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL)!=0)
return -1; // Couldn't open file
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
return -1; // Couldn't find stream information
// Dump information about file onto standard error
dump_format(pFormatCtx, 0, argv[1], 0);
int i;
AVCodecContext *pCodecCtx;
// Find the first video stream
int videoStream=-1;
for(i=0; i<pFormatCtx->nb_streams; i++)
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
videoStream=i;
break;
}
if(videoStream==-1)
return -1; // Didn't find a video stream
// Get a pointer to the codec context for the video stream
pCodecCtx=pFormatCtx->streams[videoStream]->codec;
AVCodec *pCodec;
// Find the decoder for the video stream
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL) {
fprintf(stderr, "Unsupported codec!\n");
return -1; // Codec not found
}
// Open codec
if(avcodec_open(pCodecCtx, pCodec)<0)
return -1; // Could not open codec
AVFrame *pFrame;
// Allocate video frame
pFrame=avcodec_alloc_frame();
// Allocate an AVFrame structure
AVFrame* pFrameRGB=avcodec_alloc_frame();
if(pFrameRGB==NULL)
return -1;
uint8_t *buffer;
int numBytes;
// Determine required buffer size and allocate buffer
numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,pCodecCtx->height);
buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
// Assign appropriate parts of buffer to image planes in pFrameRGB
// Note that pFrameRGB is an AVFrame, but AVFrame is a superset
// of AVPicture
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,pCodecCtx->width, pCodecCtx->height);
int frameFinished;
AVPacket packet;
i=0;
while(av_read_frame(pFormatCtx, &packet)>=0) {
if(packet.stream_index==videoStream) {
**// here makes compile error**
avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);
if(frameFinished) {
img_convert((AVPicture *)pFram eRGB, PIX_FMT_RGB24, (AVPicture*)pFrame, pCodecCtx->pix_fmt,pCodecCtx->width, pCodecCtx->height);
}
av_free_packet(&packet);
}
av_free(buffer);
av_free(pFrameRGB);
av_free(pFrame);
avcodec_close(pCodecCtx);
av_close_input_file(pFormatCtx);
return 0;