此贴用于记录FFmpeg在Windows上c++开发过程中的一些坑
1.在c++上用c的库没有进行包装:
1>c:\users\s\source\repos\ffmpeg\ffmpeg\decode.cpp(112): warning C4267: “参数”: 从“size_t”转换到“int”,可能丢失数据
1>decode.obj : error LNK2001: 无法解析的外部符号 "int __cdecl av_parser_parse2(struct AVCodecParserContext *,struct AVCodecContext *,unsigned char * *,int *,unsigned char const *,int,__int64,__int64,__int64)" (?av_parser_parse2@@YAHPEAUAVCodecParserContext@@PEAUAVCodecContext@@PEAPEAEPEAHPEBEH_J55@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "struct AVCodec * __cdecl avcodec_find_decoder(enum AVCodecID)" (?avcodec_find_decoder@@YAPEAUAVCodec@@W4AVCodecID@@@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "void __cdecl av_packet_free(struct AVPacket * *)" (?av_packet_free@@YAXPEAPEAUAVPacket@@@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "void __cdecl av_frame_free(struct AVFrame * *)" (?av_frame_free@@YAXPEAPEAUAVFrame@@@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "void __cdecl av_parser_close(struct AVCodecParserContext *)" (?av_parser_close@@YAXPEAUAVCodecParserContext@@@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "int __cdecl avcodec_receive_frame(struct AVCodecContext *,struct AVFrame *)" (?avcodec_receive_frame@@YAHPEAUAVCodecContext@@PEAUAVFrame@@@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "int __cdecl avcodec_open2(struct AVCodecContext *,struct AVCodec const *,struct AVDictionary * *)" (?avcodec_open2@@YAHPEAUAVCodecContext@@PEBUAVCodec@@PEAPEAUAVDictionary@@@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "struct AVCodecContext * __cdecl avcodec_alloc_context3(struct AVCodec const *)" (?avcodec_alloc_context3@@YAPEAUAVCodecContext@@PEBUAVCodec@@@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "struct AVPacket * __cdecl av_packet_alloc(void)" (?av_packet_alloc@@YAPEAUAVPacket@@XZ)
1>decode.obj : error LNK2001: 无法解析的外部符号 "void __cdecl avcodec_free_context(struct AVCodecContext * *)" (?avcodec_free_context@@YAXPEAPEAUAVCodecContext@@@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "struct AVCodecParserContext * __cdecl av_parser_init(int)" (?av_parser_init@@YAPEAUAVCodecParserContext@@H@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "int __cdecl avcodec_send_packet(struct AVCodecContext *,struct AVPacket const *)" (?avcodec_send_packet@@YAHPEAUAVCodecContext@@PEBUAVPacket@@@Z)
1>decode.obj : error LNK2001: 无法解析的外部符号 "struct AVFrame * __cdecl av_frame_alloc(void)" (?av_frame_alloc@@YAPEAUAVFrame@@XZ)
1>C:\Users\S\source\repos\FFmpeg\x64\Release\FFmpeg.exe : fatal error LNK1120: 13 个无法解析的外部命令
解决方法:用xtern "C"{ }
包装要引用的c库,如
extern "C"
{
#include <libavcodec/avcodec.h>
}
2.使用c++符号有误:
error C3688: 文本后缀“PRId64”无效;未找到文文本运算符或文本运算符模板“operator """"PRId64”
解决方法:在PRId64前空一格
3.av_err2str函数显式转换问题:
error C4576: 后跟初始值设定项列表的带圆括号类型是一个非标准的显式类型转换语法
解决方法:在av_err2str做如下修改:
将
#define av_err2str(errnum) av_make_error_string((char[AV_ERROR_MAX_STRING_SIZE]){0}, AV_ERROR_MAX_STRING_SIZE, errnum)
改为
char av_error[AV_ERROR_MAX_STRING_SIZE] = { 0 };
#define av_err2str(errnum) av_make_error_string(av_error, AV_ERROR_MAX_STRING_SIZE, errnum)
# 3.结构体AVRational处显式转换问题:
error C4576: 后跟初始值设定项列表的带圆括号类型是一个非标准的显式类型转换语法
解决方法:去掉结构体AVRational两边的圆括号