4

FFMPEGライブラリを0.8から'ffmpegversion git-2012-04-12-277f20c'に更新した後、C++プログラムの1つをコンパイルするとエラーが発生します

プログラムを作成するときに発生するエラーは次のとおりです。

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

残念ながら、FFMPEGに付属している「doc / examples / decode_encoding.c」の下の例は、使用するすべての関数が減価償却されているため、機能しなくなりました。私のコードはサンプルコードに基づいており、FFMPEG 0.8で正常に動作しましたが、最新バージョンのFFMPEGではコンパイルされません。減価償却された関数の一部を新しいバージョンに変更しましたが、それでもコンパイルされません。

なぜ私がこのエラーを受け取るのか誰かが知っていますか?または、FFMPEGの最新バージョンを使用した「doc / examples / decode_encoding.c」のような例へのリンクを持っている人はいますか?

4

1 に答える 1

1

私のMakeファイルの関連する行は、以下のようにg++を実行するのと似ています。

g++ test2.cpp -lavformat -lavcodec -lavutil -D__STDC_CONSTANT_MACROS

  1. プログラミングでは、詳細が重要です。linkコマンドは、上記のコマンドと十分に類似していないか、機能しているはずです。
  2. リンクラインの間違った場所にライブラリを配置している可能性があります。ソースとライブラリの順序が重要です。

アップデート:

上記のコードをCPPファイルに入れてから、提供されたオプションを指定してg ++を実行すると、機能しません。「`avcodec_open2'への未定義の参照」というエラーが表示されます。

いいえ、私はしません。別のエラーが発生します(avcodecがまったくインストールされていないため)。

サンプルコマンドがすでに失敗している場合は、他のコマンドからのエラーではなく、それが生成したエラーを提供する必要があります。そのため、他のコマンドがどのように見えるかを推測する必要はありません。

ライブラリの順序はFFMPEGバージョン0.8で機能しましたが、最新バージョンでは機能しないのはなぜですか?

おそらく、最新のlibavcodec54ものをインストールしたが、最新のものをインストールしなかったためですlibavcodec-dev

于 2012-04-12T03:10:00.187 に答える