FFMPEG未定义参考C中的’avcodoec_open2′
在将FFMPEG库从0.8更新为’ffmpeg version git-2012-04-12-277f20c’之后编译我的一个C程序时出错
我制作程序时遇到的错误如下: -------- begin -------- Linking: Analysing_Server ./source/Encoding_Thread.o: In function `CEncoding_Thread::do_work()': /home/Analyser/source/Encoding_Thread.cpp:155: undefined reference to `avcodec_open2' collect2: ld returned 1 exit status make: *** [Analysing_Server] Error 1 我的Make文件的相关行类似于运行g,如下所示: g++ test2.cpp -lavformat -lavcodec -lavutil -D__STDC_CONSTANT_MACROS 抛出错误的我的相关CPP代码的精简版本是: #include <stdio.h> #include <stdint.h> #define LOG_OUT_STREAM_BUFF_SIZE 200000 extern "C" { /* The ffmpeg library is completely written in C,so we need to tell the C++ compiler that so it links correctly. */ #include "stdint.h" #include "libavcodec/avcodec.h" #include "libavutil/mathematics.h" #include "libswscale/swscale.h" #include "libavfilter/avfilter.h" int avcodec_open2(AVCodecContext *avctx,AVCodec *codec,AVDictionary **options); int avcodec_encode_video2(AVCodecContext *avctx,AVPacket *avpkt,const AVFrame *frame,int *got_packet_ptr); } uint8_t m_outbuf[2][LOG_OUT_STREAM_BUFF_SIZE]; unsigned int m_out_size[2]; unsigned int m_OutBuffer_ID[2]; unsigned int m_Buffer_ID; /* This is just a uniqueish stamp we give to each buffer so we can tell when they change.. */ AVCodecContext * m_CodecContex; AVCodec * m_codec; struct SwsContext *m_img_convert_ctx; unsigned char* m_DataBuff; int Output_Width,Output_Height; int Output_Bitrate; int main(void) { //New version of FFMPEG calls this in avcodec_register_all //avcodec_init(); /* register all the codecs */ avcodec_register_all(); /* Initalise the encoder */ m_codec = avcodec_find_encoder(CODEC_ID_MP2); if (!m_codec) { printf("Encoding codec not foundn"); } /* init the pointers.. */ m_CodecContex = NULL; /* Default values.. */ Output_Width = 1600; Output_Height = 1200; Output_Bitrate = 600000; /* Create/setup the Codec details.. */ //Changed to work with new FFMPEG m_CodecContex = avcodec_alloc_context3(m_codec); avcodec_get_context_defaults3(m_CodecContex,m_codec); /* put sample parameters */ m_CodecContex->bit_rate = Output_Bitrate; /* resolution must be a multiple of two */ m_CodecContex->width = Output_Width; m_CodecContex->height = Output_Height; /* frames per second */ m_CodecContex->time_base= (AVRational){1,25}; m_CodecContex->gop_size = 10; /* emit one intra frame every ten frames */ m_CodecContex->max_b_frames=1; m_CodecContex->pix_fmt = PIX_FMT_YUV420P; /* must be YUV for encoding.. */ AVDictionary * RetunedAVDic; /* open it */ //Changed to work with new FFMPEG if (avcodec_open2(m_CodecContex,m_codec,&RetunedAVDic) < 0) { printf("could not open codec"); } } 不幸的是,FFMPEG附带的’doc / examples / decoding_encoding.c’下的示例不再有效,因为它使用的所有函数现在都已折旧.我的代码基于示例代码,并且与FFMPEG 0.8一起工作正常,但不能使用最新版本的FFMPEG进行编译.我已将一些折旧函数更改为较新版本,但仍无法编译. 有谁知道我为什么会收到这个错误?或者有没有人使用最新版本的FFMPEG链接到’doc / examples / decoding_encoding.c’这样的例子? 解决方法
>在编程中,细节很重要.您的链接命令与上面的命令不够相似,或者它可以工作. 更新:
不,我没有.我得到一个不同的错误(因为我根本没有安装avcodec). 如果示例命令已经失败,那么您应该提供它产生的错误,而不是其他命令的错误,因此我们不必猜测其他命令可能是什么样的.
可能是因为你安装了最新的libavcodec54,但没有安装最新的libavcodec-dev. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |