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: Select all
#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;
}
Code: Select all
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