1
votes

I'm trying to build simple programm using ffmpeg

#include <stdio.h>
 #include <stdlib.h>
 #define __STDC_CONSTANT_MACROS
extern "C" {
 #include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
 #include <libavformat/avio.h>
#include <libavdevice/avdevice.h>
#include <libavutil/time.h>
 }


#include <iostream> 


 int main( int argc, char* argv[] )
 {
   AVCodec *icodec;
  AVFormatContext *ifcx = NULL;
  AVInputFormat *ifmt;
  AVCodecContext *iccx;
   AVStream *ist;
   AVStream *ost;
   AVPacket pkt;
   int i_index;
  int64_t timenow, timestart;
   int got_key_frame = 0;

   AVFormatContext *ofcx;

   const char *sProg = argv[ 0 ];
   const char *sFileInput;
   const char *sFileOutput;
  int64_t bRunTime;

  bRunTime = atoi( argv[ 2 ] ) * 1000000;

   // Initialize library
   av_log_set_level( AV_LOG_DEBUG );
   av_register_all();
   avcodec_register_all(); 
   avformat_network_init();
   avdevice_register_all();

And i get these errors

g++ -o rtsp3 -I/usr/include -I/usr/local/include rtsp3.cpp -lavformat -lavcodec -lavutil -lm -lz -lva -lpthread /tmp/ccAXDgvi.o: In function main': rtsp3.cpp:(.text+0x115): undefined reference toavdevice_register_all' /usr/local/lib/libavformat.a(matroskadec.o): In function matroska_decode_buffer': /home/user/projects/ffmpeg-git/ffmpeg/libavformat/matroskadec.c:1242: undefined reference toBZ2_bzDecompressInit' /home/user/projects/ffmpeg-git/ffmpeg/libavformat/matroskadec.c:1257: undefined reference to BZ2_bzDecompress' /home/user/projects/ffmpeg-git/ffmpeg/libavformat/matroskadec.c:1250: undefined reference toBZ2_bzDecompressEnd' /home/user/projects/ffmpeg-git/ffmpeg/libavformat/matroskadec.c:1262: undefined reference to `BZ2_bzDecompressEnd' collect2: error: ld returned 1 exit status

I have git version of ffmpeg and successfully compiled it and make install.

4

4 Answers

1
votes

Try this, it worked for me:

gcc -o main.o main.c `pkg-config --cflags --libs libavformat libavutil`
0
votes

You need to link with libavdevice, e.g. -lavdevice

Also, apparently, libbz2, e.g. -lbz2

0
votes

I solved this by installing libbz2-dev

On Ubuntu: sudo apt-get install libbz2-dev

0
votes

check if you have object files for libav format added in the path. You have added librarians properly in the makefile so problem shouldn't have come. If you are using ubuntu, check if this is preset
/usr/lib/x86_64-linux-gnu/libavformat.so

If not, you need to install libavformat-dev

you can install it using "sudo apt-get install libavformat-dev"

I was facing the same issues and it got resolved after this.