ffmepg在VS开发环境中的设置以及常见问题

来源:互联网 发布:淘宝怎么删除下架宝贝 编辑:程序博客网 时间:2024/05/17 10:55

1.先下载ffmpeg的 dev版本(这个比较好)

2.解压

3.使用VS建立一个cpp工程

4.设置引用文件的位置


5.设置lib文件位置


[特别注意:一开始少了avcodec.lib和 avformat.lib , 连接的时候提示找不到一些符号,但是有一些别的符号是能找到的,

而且找不到的符号,一看就是avXXXXX,所以想到可能是没有包含avcodec.lib,加上后就能编译过。]



6. 缺少宏定义

 fatal error C1189: #error : missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS

解决方法:

 

6.编译,可能出问题:

1>test01.obj : error LNK2001: unresolvedexternal symbol "void __cdecl sws_freeContext(struct SwsContext *)"(?sws_freeContext@@YAXPAUSwsContext@@@Z) 
1>test01.obj : error LNK2001: unresolved external symbol "void __cdeclav_freep(void *)" (?av_freep@@YAXPAX@Z
1>test01.obj : error LNK2001: unresolved external symbol "int __cdeclsws_scale(struct SwsContext *,unsigned char const * const * const,int const *const,int,int,unsigned char * const * const,int const * const)"(?sws_scale@@YAHPAUSwsContext@@QBQBEQBHHHQBQAE2@Z
1>test01.obj : error LNK2001: unresolved external symbol "int __cdeclav_image_alloc(unsigned char * * const,int * const,int,int,enumAVPixelFormat,int)" (?av_image_alloc@@YAHQAPAEQAHHHW4AVPixelFormat@@H@Z
1>test01.obj : error LNK2001: unresolved external symbol "char const *__cdecl av_get_pix_fmt_name(enum AVPixelFormat)"(?av_get_pix_fmt_name@@YAPBDW4AVPixelFormat@@@Z) 
1>test01.obj : error LNK2001: unresolved external symbol "structSwsContext * __cdecl sws_getContext(int,int,enum AVPixelFormat,int,int,enumAVPixelFormat,int,struct SwsFilter *,struct SwsFilter *,double const *)"(?sws_getContext@@YAPAUSwsContext@@HHW4AVPixelFormat@@HH0HPAUSwsFilter@@1PBN@Z
1>test01.obj : error LNK2001: unresolved external symbol "int __cdeclav_parse_video_size(int *,int *,char const *)" (?av_parse_video_size@@YAHPAH0PBD@Z

 

经过查找,因为ffmpeg是 C程序编译的。

所以需要在包含头文件的时候加上 

extern "C"

 

如下:

extern "C"{

#include <libavutil/imgutils.h>

#include <libavutil/parseutils.h>

#include <libswscale/swscale.h>

};

 

7.能够编译过,到cmd命令下,运行, 提示缺少avutil-54.dll,等,

  在下载的ffmpeg 的dev版本中,没有发现这个,

去下载shared 版本的ffmpeg, 找到对应的dll文件,全部拷贝到编译的Debug目录下,能够运行。

8. 按照提示,输入相应的参数,

E:\test\FFMpeg\test01\Debug>test01.exetest.jpg 80*80

提示 

ffplay -f rawvideo -pix_fmt rgb24 -video_size80x80 test.jpg

 

能够看出运行效果来。

 

9.如果编译能够通过,链接的时候,如果发现有些函数找不到,则是没有添加足够的库,

 

1>recordDestop.obj : error LNK2019:unresolved external symbol _avcodec_alloc_frame referenced in function _main

1>recordDestop.obj : error LNK2019:unresolved external symbol _avcodec_open2 referenced in function _main

1>recordDestop.obj : error LNK2019:unresolved external symbol _avcodec_find_decoder referenced in function _main

1>recordDestop.obj : error LNK2019: unresolvedexternal symbol _av_dump_format referenced in function _main

1>recordDestop.obj : error LNK2019:unresolved external symbol _avformat_find_stream_info referenced in function_main

》》》avutil.lib swscale.lib avfilter.libavformat.lib avcodec.lib avdevice.lib 这些库应该就比较全了,

如果不全,再把其他的加上。

其实也可以看看这几个函数是在哪个头文件里面定义的,根据相应的头文件,找到对应的库加上就可以。

 

 

-========================================



0 0
原创粉丝点击