forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with linking FFMPEG's libraries

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
The_Fearless



Joined: 31 Jul 2007
Posts: 2

PostPosted: Tue Jul 31, 2007 12:45 am    Post subject: Problem with linking FFMPEG's libraries Reply with quote

Hi,
I'm trying to use FFMPEG in a program, but i've got a problem... I can compile the 4 libraries, and i want to use them in this program (that's just the first version, it'll be a video player):

Code:
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <string.h>

#include "../ffmpeg/libavcodec/avcodec.h"
#include "../ffmpeg/libavformat/avformat.h"
#include "../ffmpeg/libavformat/avio.h"
#include "../ffmpeg/libavcodec/opt.h"
#include "../ffmpeg/libavutil/fifo.h"
#include "../ffmpeg/libavutil/avstring.h"


PSP_MODULE_INFO("CONTROLTEST", 0, 1, 1);

#define printf   pspDebugScreenPrintf

int done = 0;

int exit_callback(int arg1, int arg2, void *common)
{
   return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
   int cbid;

   cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
   sceKernelRegisterExitCallback(cbid);
   sceKernelSleepThreadCB();

   return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
   int thid = 0;

   thid = sceKernelCreateThread("update_thread", CallbackThread,
                 0x11, 0xFA0, 0, 0);
   if(thid >= 0)
   {
      sceKernelStartThread(thid, 0, 0);
   }

   return thid;
}

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(void) {
   SceCtrlData pad;

   pspDebugScreenInit();
   SetupCallbacks();

   sceCtrlSetSamplingCycle(0);
   sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

   printf("Press X to rip frame");

   while(!done){
      pspDebugScreenSetXY(0, 2);

          sceCtrlReadBufferPositive(&pad, 1);

      if (pad.Buttons != 0){
         if (pad.Buttons & PSP_CTRL_CROSS){
            printf("Ripping Frame");
            //Start of Movie Rip
            av_register_all();
            
            AVFormatContext *pFormatCtx;
            // Open video file
            if(av_open_input_file(&pFormatCtx, "prova.avi", 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 about file onto standard error
            dump_format(pFormatCtx, 0, "prova.avi", 0);
            
            int i;
            AVCodecContext *pCodecCtx;
            
            // Find the first video stream
            int 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 a video stream
            
             // Get a pointer to the codec context for the video stream
             pCodecCtx=pFormatCtx->streams[videoStream]->codec;
            
             AVCodec *pCodec;
            
             // Find the decoder for the 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; // Could not open codec
            
             AVFrame *pFrame;
             AVFrame *pFrameRGB;
            
             // Allocate video frame
             pFrame=avcodec_alloc_frame();
            
             // Allocate an AVFrame structure
             pFrameRGB=avcodec_alloc_frame();
            
             if(pFrameRGB==NULL)
                      return -1;
            
             uint8_t *buffer;
             int numBytes;
             // Determine required buffer size and 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 to image planes in pFrameRGB
             // Note that pFrameRGB is an AVFrame, but AVFrame is a superset
             // of AVPicture
             avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
                   pCodecCtx->width, pCodecCtx->height);
            
             int frameFinished;
             AVPacket packet;
            
             i=0;
             while(av_read_frame(pFormatCtx, &packet)>=0) {
                     // Is this a packet from the video stream?
                if(packet.stream_index==videoStream) {
                    // Decode video frame
               avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
                                                             packet.data, packet.size);
               
               // Did we get a video frame?
               if(frameFinished) {
                   // Convert the image from its native format to RGB
                   img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24,
                                                       (AVPicture*)pFrame, pCodecCtx->pix_fmt,
                                         pCodecCtx->width, pCodecCtx->height);
                   // Save the frame to disk
                   if(++i<=5)
                      SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i);
               }
                }
                // Free the packet that was allocated by av_read_frame
                av_free_packet(&packet);
             }

                                 // Free the RGB image
             av_free(buffer);
             av_free(pFrameRGB);
            
             // Free the YUV frame
             av_free(pFrame);
            
             // Close the codec
             avcodec_close(pCodecCtx);
            
             // Close the video file
             av_close_input_file(pFormatCtx);


            
             return 0;
                          }
                  }
           }

        printf("Finito. Ritorno all'XMB...");

       sceKernelExitGame();
   return 0;
}


But when i try to compile the code it displays this:
Code:
XP@xp- ~/PSP_Video_Player
$ make
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -lavutil -lavforma
t -lavcodec -lz -lavutil -lm -D_PSP_FW_VERSION=150   -c -o main.o main.c
main.c: In function 'main':
main.c:187: warning: 'img_convert' is deprecated (declared at ../ffmpeg/libavcod
ec/avcodec.h:2395)
psp-gcc: -lavutil: linker input file unused because linking not done
psp-gcc: -lavformat: linker input file unused because linking not done
psp-gcc: -lavcodec: linker input file unused because linking not done
psp-gcc: -lz: linker input file unused because linking not done
psp-gcc: -lavutil: linker input file unused because linking not done
psp-gcc: -lm: linker input file unused because linking not done
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -lavutil -lavforma
t -lavcodec -lz -lavutil -lm -D_PSP_FW_VERSION=150  -L. -L/usr/local/pspdev/psp/
sdk/lib   main.o -lavutil -lavformat -lavcodec -lz -lavutil -lm -lpspdebug -lpsp
display -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lp
spnet_resolver -lpsputility -lpspuser -lpspkernel -o main.elf
main.o: In function `main':
main.c:(.text+0x218): undefined reference to `av_register_all'
main.c:(.text+0x230): undefined reference to `av_open_input_file'
main.c:(.text+0x2ac): undefined reference to `av_find_stream_info'
main.c:(.text+0x2c8): undefined reference to `dump_format'
main.c:(.text+0x2f4): undefined reference to `avcodec_find_decoder'
main.c:(.text+0x304): undefined reference to `avcodec_open'
main.c:(.text+0x314): undefined reference to `avcodec_alloc_frame'
main.c:(.text+0x31c): undefined reference to `avcodec_alloc_frame'
main.c:(.text+0x338): undefined reference to `avpicture_get_size'
main.c:(.text+0x340): undefined reference to `av_malloc'
main.c:(.text+0x360): undefined reference to `avpicture_fill'
main.c:(.text+0x36c): undefined reference to `av_read_frame'
main.c:(.text+0x3d0): undefined reference to `avcodec_decode_video'
main.c:(.text+0x3f8): undefined reference to `img_convert'
main.c:(.text+0x438): undefined reference to `av_free'
main.c:(.text+0x440): undefined reference to `av_free'
main.c:(.text+0x448): undefined reference to `av_free'
main.c:(.text+0x450): undefined reference to `avcodec_close'
main.c:(.text+0x458): undefined reference to `av_close_input_file'
collect2: ld returned 1 exit status
make: *** [main.elf] Error 1


I understand that it's a problem with the linking of the libs, but i don't know how to fix it... Please help me XD
Back to top
View user's profile Send private message MSN Messenger
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Tue Jul 31, 2007 12:59 am    Post subject: Reply with quote

Either order your libraries properly (gcc ld will only find symbols imported from libs earlier in the linking process, so -la -lb isn't the same as -lb -la), or you can group all your libs like this:

gcc -o executable.elf -Wl,--start-group -lone -ltwo -lthree -Wl,--end-group

That will tell the linker to continue looking for symbols if it cannot find them in the currently available ones (more like how it works on other compilers).
_________________
GE Dominator
Back to top
View user's profile Send private message
The_Fearless



Joined: 31 Jul 2007
Posts: 2

PostPosted: Tue Jul 31, 2007 1:18 am    Post subject: Reply with quote

mmm...

I'm using this makefile to build my program:

Code:
TARGET = main
OBJS = main.o

INCDIR =

CFLAGS = -O2 -G0 -Wall

CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti

ASFLAGS = $(CFLAGS)


LIBDIR =
LIBS = -lavcodec -lavformat -lavutil -lz -lavutil -lm

PSPSDK=$(shell psp-config --pspsdk-path)

LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP

PSP_EBOOT_TITLE = Basic PSP Movie Player


include $(PSPSDK)/lib/build.mak


and it now gives this error:

Code:
$ make
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=
150   -c -o main.o main.c
main.c: In function 'main':
main.c:187: warning: 'img_convert' is deprecated (declared at ../ffmpeg/libavcod
ec/avcodec.h:2395)
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=
150  -L. -L/usr/local/pspdev/psp/sdk/lib   main.o -lavcodec -lavformat -lavutil
-lz -lavutil -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet
 -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkern
el -o main.elf
main.o: In function `main':
main.c:(.text+0x218): undefined reference to `av_register_all'
main.c:(.text+0x230): undefined reference to `av_open_input_file'
main.c:(.text+0x2ac): undefined reference to `av_find_stream_info'
main.c:(.text+0x2c8): undefined reference to `dump_format'
main.c:(.text+0x2f4): undefined reference to `avcodec_find_decoder'
main.c:(.text+0x304): undefined reference to `avcodec_open'
main.c:(.text+0x314): undefined reference to `avcodec_alloc_frame'
main.c:(.text+0x31c): undefined reference to `avcodec_alloc_frame'
main.c:(.text+0x338): undefined reference to `avpicture_get_size'
main.c:(.text+0x340): undefined reference to `av_malloc'
main.c:(.text+0x360): undefined reference to `avpicture_fill'
main.c:(.text+0x36c): undefined reference to `av_read_frame'
main.c:(.text+0x3d0): undefined reference to `avcodec_decode_video'
main.c:(.text+0x3f8): undefined reference to `img_convert'
main.c:(.text+0x438): undefined reference to `av_free'
main.c:(.text+0x440): undefined reference to `av_free'
main.c:(.text+0x448): undefined reference to `av_free'
main.c:(.text+0x450): undefined reference to `avcodec_close'
main.c:(.text+0x458): undefined reference to `av_close_input_file'
collect2: ld returned 1 exit status
make: *** [main.elf] Error 1


There's still the undefined reference error...

EDIT: Is there any way to know if a lib is compiled the right way?
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group