ffmpeg相关,undefined reference to `av_register_all' !!

a_b_c_ 2007-09-03 03:17:31
问题:提示undefined reference to `av_register_all' 等多个函数。

1 编译成功ffmpeg之后,在C:\msys\local中生成bin,include,lib这3个文件夹子,其中lib文件夹也已经包含ffmpeg下的avcodec-51.lib、avformat-51.lib、avutil-49.lib这三个文件。
2 在local文件夹中建立test.c,输入(网上找的):
#include <stdio.h>
#include "include\ffmpeg\avcodec.h"
#include "include\ffmpeg\avformat.h"
#include "include\ffmpeg\avutil.h"
#include <windows.h>
#define INBUF_SIZE 4096
//extern void print_error(const char *filename, int err);
void main()
{
const char *filename="1.3gp";
const char *filenameout="2.3gp";
AVCodec *decodecodec;
AVCodec *encodecodec;
int bytesDecoded=0;
AVCodecContext *decodec= NULL;
AVCodecContext *encodec= NULL;
AVFormatContext *pFormatCtx;
AVFormatContext *pFormatCtxForOutput;
AVOutputFormat *pOutputFormat;
AVStream *video_st=NULL;
unsigned char fgcolor[3]={255,128,128};
int frame, outbuf_size = 400000, audioStream, position=0, got_picture, len,i, frametosave=250, out_size, videoStream, err;
AVFrame *picture;
AVPacket packet;
uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *outbuf_ptr;
int audiolen = 0, audiosize = 0;
char buf[1024];
short tmp = 0;
outbuf_ptr = (unsigned char *) malloc(outbuf_size);
/*×¢²áËùÓеĽâÂë±àÂë¿â*/
av_register_all();
memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);

/*´ò¿ªÐèÒª½âÂëµÄÎļþ*/
err=av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL);
if(err!=0)
{
fprintf(stderr,"Can't open source file\n");
//print_error(filename, err);
exit(1);
}
/*»ñÈ¡¶àýÌåÎļþµÄÐÅÏ¢*/
if(av_find_stream_info(pFormatCtx)<0)
{
fprintf(stderr,"Can't find stream info\n");
exit(1);
}

/*if (av_set_parameters(pFormatCtx, NULL) < 0)
{
exit(1);
}
dump_format(pFormatCtx, 0, filename, 1); */

/*²éÕÒÎļþÖÐÊÇ·ñÓÐÊÓƵ*/
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)
{
fprintf(stderr,"Not found video stream\n");
exit(1);
}
printf("Video decoding\n");
audioStream = -1;
for(i=0; i<pFormatCtx->nb_streams; i++)
{
if(pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO)
{
audioStream = i;
break;
}
}

/*Ñ°ÕÒÏàӦýÌå¸ñʽµÄ±àÂë½âÂë*/
decodec=pFormatCtx->streams[videoStream]->codec;
decodecodec = avcodec_find_decoder(decodec->codec_id);
if (!decodecodec)
{
fprintf(stderr, "decode codec not found\n");
exit(1);
}

picture= avcodec_alloc_frame();

/*´ò¿ª½âÂë¿â*/
if (avcodec_open(decodec, decodecodec) < 0)
{
fprintf(stderr, "could not open decode codec\n");
exit(1);
}

/*³õʼ»¯Êä³ö±àÂëµÄÐÅÏ¢*/
pOutputFormat=guess_format(NULL,filename,NULL);
pFormatCtxForOutput = av_alloc_format_context();
pFormatCtxForOutput->oformat = pOutputFormat;

sprintf(pFormatCtxForOutput->filename, "%s", filenameout);

video_st = av_new_stream(pFormatCtxForOutput,0);
encodec= video_st->codec;
encodec->codec_id = pOutputFormat->video_codec;
encodec->codec_type = CODEC_TYPE_VIDEO;
encodec->bit_rate = pFormatCtx->bit_rate;
encodec->width = decodec->width ;
encodec->height = decodec->height ;
encodec->time_base= decodec->time_base;
encodec->gop_size = decodec->gop_size;
encodec->max_b_frames=decodec->max_b_frames;
encodec->pix_fmt = decodec->pix_fmt;
/*¼ì²éencodec²ÎÊýÉèÖÃ*/
if(av_set_parameters(pFormatCtxForOutput, NULL)<0)
{
fprintf(stderr, "Invalid output format parameters\n");
exit(1);
}
/*ÕÒµ½ÏàÓ¦µÄ±àÂë¿â*/
encodecodec = avcodec_find_encoder(encodec->codec_id);
if (!encodecodec)
{
fprintf(stderr, "encode codec not found\n");
exit(1);
}
/*´ò¿ª±àÂë¿â*/
if ((err=avcodec_open(encodec, encodecodec)) < 0)
{
fprintf(stderr, "could not open encode codec\n");
//print_error(filename, err);
exit(1);
}
/*´´½¨ÐÂÉú³ÉµÄÎļþ*/
if (!(pOutputFormat->flags & AVFMT_NOFILE))
{
if (url_fopen(&pFormatCtxForOutput->pb, filenameout, URL_WRONLY) < 0)
{
fprintf(stderr, "Could not open '%s'\n", filenameout);
exit(1);
}
}
/*дÎļþÍ·*/
if (av_write_header(pFormatCtxForOutput) < 0)
{
fprintf(stderr, "Could not write header for output file\n");
exit(1);
}
frame = 0;
while(av_read_frame(pFormatCtx, &packet)>=0)
{
if(packet.stream_index==videoStream)
{
len = avcodec_decode_video(decodec, picture, &got_picture,packet.data, packet.size);
//audiolen = avcodec_decode_audio(decodec, &tmp, &audiosize, packet.data, packet.size);
//printf("avcodec_decode_audio size %d.\n", audiolen);

if (got_picture)
{

printf("saving frame %3d\n", frame);
fflush(stdout);
sprintf(buf, "frame%d.pgm", frame);
picture->pts=av_rescale(frame,AV_TIME_BASE*(int64_t)encodec->time_base.num,encodec->time_base.den);
picture->pict_type=0;
out_size = avcodec_encode_video(encodec, outbuf_ptr, outbuf_size, picture);
printf("encoding frame %3d (size=%5d)\n", frame, out_size);
if (out_size > 0)
{
AVPacket pkt;
av_init_packet(&pkt);
if(encodec->coded_frame && encodec->coded_frame->key_frame)
pkt.flags |= PKT_FLAG_KEY;
pkt.flags = packet.flags;
pkt.stream_index= video_st->index;
pkt.data= outbuf_ptr;
pkt.size= out_size;
av_write_frame(pFormatCtxForOutput, &pkt);
}

frame++;
}
else
{
//av_write_frame(pFormatCtxForOutput, &packet);
}
}
else if (packet.stream_index==audioStream)
{
printf("audio format.\n");
}
av_free_packet(&packet);
}
/*дÎļþβ²¢ÇҹرձàÂë½âÂë¿â£¬ÊÍ·ÅÄÚ´æ*/
av_write_trailer(pFormatCtxForOutput);
avcodec_close(decodec);
av_free(decodec);
avcodec_close(encodec);
av_free(encodec);
av_free(picture);
if (audioStream != -1)
{
printf("audiostream %d.\n", audioStream);
}
if (videoStream != -1)
{
printf("Videostream %d.\n", videoStream);
}
}
//==================================================================================
3 在MinGW32窗口中输入:
gcc test.c 或者 gcc -o test test.c -L/lib/都提示:av_register_all()未定义。
怎么会这样?
...全文
3210 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dskit 2010-04-30
  • 打赏
  • 举报
回复
include,lib 路径要添加到项目中
一般更改 VS2005 路径都是通过打开 VS2005 ,然后选择 ”Tool”, “Options”, “Projects and Solutions”, “VC++ Directories”, 然后手动添加或删除 include, library, source 路径。

如果使用命令编译,请设置相应的选项
周江涛 2010-04-30
  • 打赏
  • 举报
回复
-lm -ld -lz -lavcodec -lavformat -lavutil
max123456 2010-04-30
  • 打赏
  • 举报
回复
在包含 ffmpeg 的相关头文件
extern "C"
{
#include"filename.h"
}

这样试一下

2,543

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧