2

我正在尝试使用 FFmpeg 打开和阅读视频 .avi 我使用 Visual Studio 2010 在 win7 x64 上工作

现在我的代码很简单:

#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "SDL.h"
#include "SDL_mixer.h"


int main (int argc, char *argv[]) {

AVFormatContext *pFile_video;
int             s, videoStream;
AVCodecContext  *pCodecCtx;
AVCodec         *pCodec;
AVFrame         *pFrame; 
AVFrame         *pFrameRGB;
AVPacket        packet;
int             frameFinished;
int             numBytes;
uint8_t         *buffer;

av_register_all();

    if((avformat_open_input(&pFile_video, "AR.avi", NULL,NULL)!=0)) cout <<"cannot open video file"<<endl;
    //if(av_find_stream_info(pFile_video) <0) cout <<"cannot retrive stream information"<<endl;

    videoStream =-1;
    for(s=0; s<pFile_video->nb_streams;s++){
        if((pFile_video->streams[s]->codec->codec_type) == AVMEDIA_TYPE_VIDEO) videoStream =s;
    }
    if(videoStream ==-1) cout <<"cannot open video stream"<<endl;

f(SDL_Init(SDL_INIT_EVERYTHING)< 0) cout<< "cannot initialize SDL subsystems"<<endl;
    if(Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2, 4096) <0) cout <<"error mixer audio"<<endl;
    music = Mix_LoadMUS("AR.wav");
    if(music == NULL) {cout <<"error loading music    "<<endl;
}

return 0;
}

我链接了以下 .lib 文件:

avcodec.lib
avdevice.lib
avfilter.lib
avformat.lib
avutil.lib
postproc.lib
swresample.lib
swscale.lib

但我收到这些错误:

>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: la libreria predefinita 'msvcrt.lib' è in conflitto con l'utilizzo di altre librerie; utilizzare /NODEFAULTLIB:libreria
1>main_video_ffmpeg.obj : error LNK2019: riferimento al simbolo esterno "int __cdecl avformat_open_input(struct AVFormatContext * *,char const *,struct AVInputFormat *,struct AVDictionary * *)" (?avformat_open_input@@YAHPAPAUAVFormatContext@@PBDPAUAVInputFormat@@PAPAUAVDictionary@@@Z) non risolto nella funzione _SDL_main
1>main_video_ffmpeg.obj : error LNK2019: riferimento al simbolo esterno "void __cdecl av_register_all(void)" (?av_register_all@@YAXXZ) non risolto nella funzione _SDL_main
1>C:\Users\Cristina\Desktop\OpenCV\Progetti\MIEI_PROGETTI_Vs\video_ffmpeg\Debug\video_ffmpeg.exe : fatal error LNK1120: 2 esterni non risolti

我认为这是一个链接器错误。但我没有其他 .lib 文件用于 FFmpeg 库。

4

1 回答 1

4

你应该用 extern "C" 包围你的 ffmpeg 包含

    extern "C" {
      #include "libavcodec/avcodec.h"
      #include "libavformat/avformat.h"
      #include "SDL.h"
      #include "SDL_mixer.h"
    }
于 2013-02-26T13:59:12.157 回答