using ffmpeg headers with a c program -


i'm trying learn ffmpeg drangers guide (for school), have mac first thing did use macports , ffmpeg , sdl...

now when i'm tried compile drangers code, compiler didnt recognize headers... used -i on gnu when compiling, , gave "whole/path/name..." headers, error on header missing...

below put code corrections.

i tried including headers error there header compiler can't find

i tried both gnu (on console) , on xcode.

// tutorial01.c // code based on tutorial martin bohme (boehme@inb.uni-luebeckremovethis.de) // tested on gentoo, cvs version 5/01/07 compiled gcc 4.1.1  // small sample program shows how use libavformat , libavcodec // read video file. // // use // // gcc -o tutorial01 tutorial01.c -lavformat -lavcodec -lz // // build (assuming libavformat , libavcodec correctly installed // system). // // run using // // tutorial01 myvideofile.mpg // // write first 5 frames "myvideofile.mpg" disk in ppm // format.  #include "/opt/local/include/libavcodec/avcodec.h" #include "/opt/local/include/libavformat/avformat.h"  #include <stdio.h>  void saveframe(avframe *pframe, int width, int height, int iframe) {   file *pfile;   char szfilename[32];   int  y;    // open file   sprintf(szfilename, "frame%d.ppm", iframe);   pfile=fopen(szfilename, "wb");   if(pfile==null)     return;    // write header   fprintf(pfile, "p6\n%d %d\n255\n", width, height);    // write pixel data   for(y=0; y<height; y++)     fwrite(pframe->data[0]+y*pframe->linesize[0], 1, width*3, pfile);    // close file   fclose(pfile); }  int main(int argc, char *argv[]) {   avformatcontext *pformatctx;   int             i, videostream;   avcodeccontext  *pcodecctx;   avcodec         *pcodec;   avframe         *pframe;    avframe         *pframergb;   avpacket        packet;   int             framefinished;   int             numbytes;   uint8_t         *buffer;    if(argc < 2) {     printf("please provide movie file\n");     return -1;   }   // register formats , codecs   av_register_all();    // open video file   if(av_open_input_file(&pformatctx, argv[1], null, 0, null)!=0)     return -1; // couldn't open file    // retrieve stream information   if(av_find_stream_info(pformatctx)<0)     return -1; // couldn't find stream information    // dump information file onto standard error   dump_format(pformatctx, 0, argv[1], 0);    // find first video stream   videostream=-1;   for(i=0; i<pformatctx->nb_streams; i++)     if(pformatctx->streams[i]->codec->codec_type==codec_type_video) {       videostream=i;       break;     }   if(videostream==-1)     return -1; // didn't find video stream    // pointer codec context video stream   pcodecctx=pformatctx->streams[videostream]->codec;    // find decoder video stream   pcodec=avcodec_find_decoder(pcodecctx->codec_id);   if(pcodec==null) {     fprintf(stderr, "unsupported codec!\n");     return -1; // codec not found   }   // open codec   if(avcodec_open(pcodecctx, pcodec)<0)     return -1; // not open codec    // allocate video frame   pframe=avcodec_alloc_frame();    // allocate avframe structure   pframergb=avcodec_alloc_frame();   if(pframergb==null)     return -1;    // determine required buffer size , allocate buffer   numbytes=avpicture_get_size(pix_fmt_rgb24, pcodecctx->width,                   pcodecctx->height);   buffer=(uint8_t *)av_malloc(numbytes*sizeof(uint8_t));    // assign appropriate parts of buffer image planes in pframergb   // note pframergb avframe, avframe superset   // of avpicture   avpicture_fill((avpicture *)pframergb, buffer, pix_fmt_rgb24,          pcodecctx->width, pcodecctx->height);    // read frames , save first 5 frames disk   i=0;   while(av_read_frame(pformatctx, &packet)>=0) {     // packet video stream?     if(packet.stream_index==videostream) {       // decode video frame       avcodec_decode_video(pcodecctx, pframe, &framefinished,                 packet.data, packet.size);        // did video frame?       if(framefinished) {     // convert image native format rgb     img_convert((avpicture *)pframergb, pix_fmt_rgb24,                      (avpicture*)pframe, pcodecctx->pix_fmt, pcodecctx->width,                      pcodecctx->height);      // save frame disk     if(++i<=5)       saveframe(pframergb, pcodecctx->width, pcodecctx->height,              i);       }     }      // free packet allocated av_read_frame     av_free_packet(&packet);   }    // free rgb image   av_free(buffer);   av_free(pframergb);    // free yuv frame   av_free(pframe);    // close codec   avcodec_close(pcodecctx);    // close video file   av_close_input_file(pformatctx);    return 0; } 

go simpler includes, like:

#include "avcodec.h" 

when using gcc or clang or whatever compiler, compiler add include directories using notation like:

gcc tutorial01.c -o tut -i/opt/local/include -lavformat -lavcodec -lz -lavutil -lm 

(i admit, not know if correct -l params, general principle applies. use

-i/path/to/dir
add include directory path.)

and on.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -