title: FFmpeg: undefined references to av_frame_alloc()
body: <p>I want to get into FFmpeg developing and i started following these samples tutorial here: <a href="https://github.com/phamquy/FFmpeg-tutorial-samples">here</a></p>
  
  <p>I started with the first tutorial - tutorial01.c - but i run into this problem 'undefined references to av_frame_alloc()'.</p>
  
  <p>I'm on Ubuntu 12.04 LTS.</p>
  
  <p>This is my program:</p>
  
  <pre><code>/* 
   * File:   main.c
   * Author: dontrythisathome
   *
   * Created on 3 giugno 2014, 23.02
   */
  
  #include &lt;stdio.h&gt;
  #include &lt;libavcodec/avcodec.h&gt;
  #include &lt;libavformat/avformat.h&gt;
  #include &lt;libavutil/frame.h&gt;
  #include &lt;libswscale/swscale.h&gt;
  /*
   *
   */
  void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame)
      {
          FILE   *pFile;
          char  szFilename[32];
          int       y;
  
          //Apre il file
          sprintf(szFilename, "frame%d.ppm", iFrame);
          pFile=fopen(szFilename, "wb");
          if(pFile==NULL)
          {return; }
  
          //Scrive l'intestazione del file ( Larghezza x Altezza su video)
          fprintf(pFile, "P6\n%d %d\n255\n", width, height);
  
          //Scrive i data pixel
          for(y=0; y&lt;height; y++)
          {
              fwrite(pFrame-&gt;data[0]+y*pFrame-&gt;linesize[0], 1, width*3, pFile);
          }
  
          //Chiude il file
          fclose(pFile);
        }
  /*
   * 
   */
  /*Main Function*/
  int main(int argc, char *argv[])
  {
      AVFormatContext *pFormatCtx;
      int                                     i, videoStreamIdx;
      AVCodecContext   *pCodecCtx;
      AVCodec                      *pCodec;
      AVFrame                      *pFrame;
      AVFrame                      *pFrameRGB;
      AVPacket                     packet;
      int                                     frameFinished;
      int                                     numBytes;
      uint8_t                           *buffer;
      static struct SwsContext  *img_convert_ctx;
  
      if(argc &lt; 2){
          printf("Inserisci un file video\n");
          return -1;
      }
  
      //Registra tutti i formati e i codec
      av_register_all();
  
      //Apre il file video
      if(avformat_open_input(&amp;pFormatCtx, argv[1], NULL, NULL) != 0)
      {return -1;} //Impossibile aprire il file
  
      //Recupera le informazioni dello stream
      if(avformat_find_stream_info(pFormatCtx, NULL) &lt; 0)
      {return -1;} // Couldn't find stream information
  
      //Versa le informazioni del file sullo standard error
      av_dump_format(pFormatCtx, 0, argv[1], 0);
  
      //Trova il primo stream video
      videoStreamIdx=-1;
      for(i=0; i&lt;pFormatCtx-&gt;nb_streams; i++)
      {
          if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_VIDEO)
          { videoStreamIdx=i;
              break;}
      }
  
      if(videoStreamIdx==-1)
          return -1; // Impossibile trovare lo stream video
  
      // Punta al contenuto del codec per lo stream video
      pCodecCtx = pFormatCtx-&gt;streams[videoStreamIdx]-&gt;codec;
  
      // Trova il decoder per lo stream video
      pCodec = avcodec_find_decoder(pCodecCtx-&gt;codec_id);
      if(pCodec==NULL)
      {
          fprintf(stderr, "Codec Non Supportato!\n");
          return -1; //Impossibile trovare il codec
      }
  
      //Apre il codec
      if(avcodec_open2(pCodecCtx, pCodec, NULL) &lt; 0)
      {return -1;} //Impossibile aprire il codec
  
      //Alloca il frame video
      pFrame = av_frame_alloc();
  
      //Alloca una struct AVFrame
      pFrameRGB = av_frame_alloc();
      if(pFrameRGB==NULL)
      {return -1;}
  
      //Determina la grandezza necessaria per il buffer e lo alloca
      numBytes = avpicture_get_size(PIX_FMT_RGB24,
                                                                              pCodecCtx-&gt;width,
                                                                              pCodecCtx-&gt;height);
  
      buffer = (uint8_t *) av_malloc(numBytes*sizeof(uint8_t));
  
      //Assegna le parti appropriate del buffer sulla superficie dell'immagine in pFrameRGB
      //Tenere presente che pFrameRGB è un AVFrame, ma AVFrame è una superset di AVPicture
      avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx-&gt;width, pCodecCtx-&gt;height);
  
      int w = pCodecCtx-&gt;width;
      int h = pCodecCtx-&gt;height;
      img_convert_ctx = sws_getContext(w, h, pCodecCtx-&gt;pix_fmt,
                                                                                         w, h, PIX_FMT_RGB24,
                                                                                          SWS_LANCZOS, NULL, NULL, NULL);
  
      //Legge i frame e salva i primi 5 frame su disco
     i=0;
     while((av_read_frame(pFormatCtx, &amp;packet)&gt;=0) &amp;&amp; (i&lt;5))
     {
         //Questo è il packet dello stream video?
         if(packet.stream_index==videoStreamIdx)
         {
             //Decodifica il frame video
             avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);
  
             //Si è riusiciti ad ottenere il frame video?
             if(frameFinished)
             {
                 i++;
                 sws_scale(img_convert_ctx, (const uint8_t * const *)pFrame-&gt;data,
                                          pFrame-&gt;linesize, 0, pCodecCtx-&gt;height,
                                          pFrameRGB-&gt;data, pFrameRGB-&gt;linesize);
                 SaveFrame(pFrameRGB, pCodecCtx-&gt;width, pCodecCtx-&gt;height, i);
             }
         }
  
         //Libera il pacchetto che era allocato da av_read_frame
         av_free_packet(&amp;packet);
     }
  
     //Libera l'immagine RGB
     av_free(buffer);
     av_free(pFrameRGB);
  
     //Libera il frame YUV
     av_free(pFrame);
  
     //Chiude il codec
     avcodec_close(pCodecCtx);
  
     //Chiude il file video
     avformat_close_input(&amp;pFormatCtx);
  
     /*FINE PROGRAMMA*/ 
  
      return 0;
  }
  </code></pre>
  
  <p>This is the build output:</p>
  
  <pre><code>"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
  make[1]: ingresso nella directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
  "/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/simplemediaplayerforandroid
  make[2]: ingresso nella directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
  mkdir -p dist/Debug/GNU-Linux-x86
  gcc     -o dist/Debug/GNU-Linux-x86/simplemediaplayerforandroid build/Debug/GNU-Linux-x86/main.o -L/usr/lib/x86_64-linux-gnu -lavformat -lavcodec -lavutil -lswscale -lz -lbz2
  build/Debug/GNU-Linux-x86/main.o: In function `main':
  /home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c:105: undefined reference to `av_frame_alloc'
  /home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c:108: undefined reference to `av_frame_alloc'
  collect2: ld returned 1 exit status
  make[2]: *** [dist/Debug/GNU-Linux-x86/simplemediaplayerforandroid] Errore 1
  make[2]: uscita dalla directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
  make[1]: *** [.build-conf] Errore 2
  make[1]: uscita dalla directory "/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid"
  make: *** [.build-impl] Errore 2
  
  BUILD FAILED (exit value 2, total time: 143ms)
  </code></pre>
  
  <p>I also linked the correct library path and headers path because there is no error with that.</p>
  
  <p>But when i try to build the program from the terminal with these commands: <code>
  gcc -o prog1 /home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c -lavformat -lavcodec -lavutil -lswscale -lz -lbz2</code></p>
  
  <p>And the output is different:</p>
  
  <pre><code>/home/dontrythisathome/Programmazione/C-C++/SimpleMediaPlayerForAndroid/main.c:11:29: fatal error: libavutil/frame.h: File o directory non esistente
  compilation terminated.
  </code></pre>
  
  <p>The output says that there is no file or directory existing.
  What is the problem?</p>