Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
FFMPEG未定义对'的引用;avcodoec开放2';在C++; p>我在更新FFMPEG库从0.8到FFMPEG版本GIT-2012-04-1277F20C 时编译一个C++程序时出错_C++_Linux_Ffmpeg - Fatal编程技术网

FFMPEG未定义对'的引用;avcodoec开放2';在C++; p>我在更新FFMPEG库从0.8到FFMPEG版本GIT-2012-04-1277F20C 时编译一个C++程序时出错

FFMPEG未定义对'的引用;avcodoec开放2';在C++; p>我在更新FFMPEG库从0.8到FFMPEG版本GIT-2012-04-1277F20C 时编译一个C++程序时出错,c++,linux,ffmpeg,C++,Linux,Ffmpeg,我制作程序时出现的错误如下: -------- 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

我制作程序时出现的错误如下:

-------- 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 found\n");
  }

  /* 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");
  }
}
#包括
#包括
#定义日志输出流缓冲大小200000
外部“C”{
* FFMPEG库完全用C编写,所以我们需要告诉C++编译器,这样它就正确链接了。
#包括“stdint.h”
#包括“libavcodec/avcodec.h”
#包括“libavutil/mathematics.h”
#包括“libswscale/swscale.h”
#包括“libavfilter/avfilter.h”
int avcodec_open2(AVCodecContext*avctx、avcodec*codec、AVDictionary**选项);
int-avcodec_-encode_-video2(AVCodecContext*avctx,AVPacket*avpkt,const-AVFrame*frame,int*got_-packet_-ptr);
}
uint8_t m_突发[2][LOG_OUT_STREAM_BUFF_SIZE];
无符号整数m_out_size[2];
无符号整数m_突发事件ID[2];
无符号整数m_Buffer_ID;/*这只是我们给每个缓冲区的一个独一无二的标记,这样我们就可以知道它们什么时候会改变*/
AVCodecContext*m_CodecContex;
AVCodec*m_编解码器;
结构SwsContext*m_img_convert_ctx;
无符号字符*m_-DataBuff;
int输出_宽度,输出_高度;
int输出比特率;
内部主(空){
//新版本的FFMPEG在avcodec_register_all中调用此功能
//avcodec_init();
/*注册所有编解码器*/
avcodec_寄存器_all();
/*初始化编码器*/
m_codec=avcodec_find_编码器(codec_ID_MP2);
if(!m_编解码器){
printf(“未找到编码解码器\n”);
}
/*初始化指针*/
m_CodecContex=NULL;
/*默认值*/
输出宽度=1600;
输出高度=1200;
输出比特率=600000;
/*创建/设置编解码器详细信息*/
//已更改为使用新的FFMPEG
m_编解码器上下文=avcodec_alloc_上下文3(m_编解码器);
avcodec_get_context_defaults3(m_CodecContex,m_codec);
/*输入样本参数*/
m_codeContex->比特率=输出比特率;
/*分辨率必须是2的倍数*/
m_codeContex->width=输出_宽度;
m_codeContex->height=输出_height;
/*每秒帧数*/
m_CodecContex->time_base=(AVRational){1,25};
m_codeContex->gop_size=10;/*每十帧发射一帧内*/
m_CodecContex->max_b_frames=1;
m_codeContex->pix_fmt=pix_fmt_YUV420P;/*必须是YUV才能进行编码*/
AVDictionary*RetunedAVDic;
/*打开它*/
//已更改为使用新的FFMPEG
if(avcodec_open2(m_CodecContex、m_codec和RetunedAVDic)<0){
printf(“无法打开编解码器”);
}
}
不幸的是,FFMPEG附带的“doc/examples/decoding_encoding.c”下的示例不再有效,因为它使用的所有函数现在都已贬值。我的代码基于示例代码,在FFMPEG 0.8中运行良好,但没有使用最新版本的FFMPEG编译。我已经将一些折旧后的函数更改为新版本,但它仍然无法编译

有人知道我为什么会犯这个错误吗?或者是否有人使用最新版本的FFMPEG链接到“doc/examples/decoding_encoding.c”这样的示例

我的Make文件的相关行与运行g++类似,如下所示:

g++ test2.cpp -lavformat -lavcodec -lavutil -D__STDC_CONSTANT_MACROS
g++test2.cpp-lavformat-lavcodec-lavutil-D\u STDC\u CONSTANT\u宏

  • 在编程中,细节很重要。您的link命令与上面的命令不够相似,否则它可能会起作用
  • 您可能将库放在链接行的错误位置。资源和库的顺序
  • 更新:

    如果将上面提供的代码放在CPP文件中,然后使用提供的选项运行g++,则它将不起作用。您将得到错误“未定义对'avcodec_open2'的引用”

    不,我没有。我得到一个不同的错误(因为我根本没有安装avcodec)

    如果示例命令已经失败,那么您应该提供它产生的错误,而不是来自其他命令的错误,这样我们就不必猜测其他命令可能是什么样子

    对于FFMPEG版本0.8,库的顺序是一样的,为什么它不适用于最新版本


    可能是因为您安装了最新的
    libavcodec54
    ,但在我的系统上安装的
    libavcodec
    上运行
    nm-D/usr/lib/libavcodec.so.52 | grep avcodec_open
    时没有安装最新的
    libavcodec dev
    ,我得到以下输出:
    0000000000 2e4a80 T avcodec\u open
    ——no
    avcodec\u open2
    。你有信心这个符号可以使用吗?它是否需要比您(和我)安装的
    libavcodec
    更新或更旧的版本?为什么您要在代码中手动定义
    avcodec\u open2()
    avcodec\u encode\u video2()
    ,而不是让编译器使用
    avcodec.h
    中的声明?sarnold,我最初使用的是avcodec\u open,但它在avcodec.h中的注释中特别指出,使用avcodec_open2。当我尝试使用avcodec_打开代码编译,但无法打开编解码器时,它曾用于FFMPEG 0.8。我今天刚刚安装了最新版本的FFMPEG,我可能会尝试看看是否可以回滚到更高版本的FFMPEG。里米,我在某个地方读到,在C++中使用C库时,可能需要手动定义函数。如果删除这两行代码,则会出现相同的错误。sarnold,您是正确的,avcodec_open2仅在libavcodec版本54及更高版本中,而我似乎有版本52。谢谢你的帮助。可能重复:1。如果将上面提供的代码放在CPP文件中,然后使用提供的选项运行g++,则它将不起作用。您将得到错误“未定义对'avcodec_open2'的引用”。2.对于FFMPEG版本0.8,库的顺序是一样的,为什么它不适用于最新版本