FFMPEG编译后的异常-gcc编译异常

lulanqin 2014-10-11 11:00:27

以下是avio_reading.c,该样例是ffmpeg官方样例


#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
#include <libavutil/file.h>
struct buffer_data {
uint8_t *ptr;
size_t size; ///< size left in the buffer
};
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
{
struct buffer_data *bd = (struct buffer_data *)opaque;
buf_size = FFMIN(buf_size, bd->size);
printf("ptr:%p size:%zu\n", bd->ptr, bd->size);
/* copy internal buffer data to buf */
memcpy(buf, bd->ptr, buf_size);
bd->ptr += buf_size;
bd->size -= buf_size;
return buf_size;
}
int main(int argc, char *argv[])
{
AVFormatContext *fmt_ctx = NULL;
AVIOContext *avio_ctx = NULL;
uint8_t *buffer = NULL, *avio_ctx_buffer = NULL;
size_t buffer_size, avio_ctx_buffer_size = 4096;
char *input_filename = NULL;
int ret = 0;
struct buffer_data bd = { 0 };
if (argc != 2) {
fprintf(stderr, "usage: %s input_file\n"
"API example program to show how to read from a custom buffer "
"accessed through AVIOContext.\n", argv[0]);
return 1;
}
input_filename = argv[1];
/* register codecs and formats and other lavf/lavc components*/
av_register_all();
/* slurp file content into buffer */
ret = av_file_map(input_filename, &buffer, &buffer_size, 0, NULL);
if (ret < 0)
goto end;
/* fill opaque structure used by the AVIOContext read callback */
bd.ptr = buffer;
bd.size = buffer_size;
if (!(fmt_ctx = avformat_alloc_context())) {
ret = AVERROR(ENOMEM);
goto end;
}
avio_ctx_buffer = av_malloc(avio_ctx_buffer_size);
if (!avio_ctx_buffer) {
ret = AVERROR(ENOMEM);
goto end;
}
avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buffer_size,
0, &bd, &read_packet, NULL, NULL);
if (!avio_ctx) {
ret = AVERROR(ENOMEM);
goto end;
}
fmt_ctx->pb = avio_ctx;
ret = avformat_open_input(&fmt_ctx, NULL, NULL, NULL);
if (ret < 0) {
fprintf(stderr, "Could not open input\n");
goto end;
}
ret = avformat_find_stream_info(fmt_ctx, NULL);
if (ret < 0) {
fprintf(stderr, "Could not find stream information\n");
goto end;
}
av_dump_format(fmt_ctx, 0, input_filename, 0);
end:
avformat_close_input(&fmt_ctx);
/* note: the internal buffer could have changed, and be != avio_ctx_buffer */
if (avio_ctx) {
av_freep(&avio_ctx->buffer);
av_freep(&avio_ctx);
}
av_file_unmap(buffer, buffer_size);
if (ret < 0) {
fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
return 1;
}
return 0;
}

三个动态链接在 /usr/lib
libavcodec.so
libavformat.so
libavutil.so

另外安装的FFMPEG如下:

root@cruse-G41MT-D3:~# ls /usr/local/ffmpeg/lib/
libavcodec.a libavfilter.so.5 libswresample.a
libavcodec.so libavfilter.so.5.1.103 libswresample.so
libavcodec.so.56 libavformat.a libswresample.so.1
libavcodec.so.56.4.101 libavformat.so libswresample.so.1.1.100
libavdevice.a libavformat.so.56 libswscale.a
libavdevice.so libavformat.so.56.9.100 libswscale.so
libavdevice.so.56 libavutil.a libswscale.so.3
libavdevice.so.56.1.100 libavutil.so libswscale.so.3.1.100
libavfilter.a libavutil.so.54 pkgconfig
libavfilter.so libavutil.so.54.10.100

root@cruse-G41MT-D3:~# ls /usr/local/ffmpeg/lib/
libavcodec.a libavfilter.so.5 libswresample.a
libavcodec.so libavfilter.so.5.1.103 libswresample.so
libavcodec.so.56 libavformat.a libswresample.so.1
libavcodec.so.56.4.101 libavformat.so libswresample.so.1.1.100
libavdevice.a libavformat.so.56 libswscale.a
libavdevice.so libavformat.so.56.9.100 libswscale.so
libavdevice.so.56 libavutil.a libswscale.so.3

ubuntu 13.10编译后的异常如下
root@cruse-G41MT-D3:~/mpeg_project# gcc -o avio_reading avio_reading.c -lavformat -lavcodec -lavutil
/usr/bin/ld: warning: libswresample.so.1, needed by /usr/lib/gcc/i686-linux-gnu/4.8/../../../../lib/libavcodec.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc/i686-linux-gnu/4.8/../../../../lib/libavcodec.so:对‘swr_close@LIBSWRESAMPLE_1’未定义的引用
/usr/lib/gcc/i686-linux-gnu/4.8/../../../../lib/libavcodec.so:对‘swr_convert@LIBSWRESAMPLE_1’未定义的引用
/usr/lib/gcc/i686-linux-gnu/4.8/../../../../lib/libavcodec.so:对‘swr_is_initialized@LIBSWRESAMPLE_1’未定义的引用
/usr/lib/gcc/i686-linux-gnu/4.8/../../../../lib/libavcodec.so:对‘swr_alloc@LIBSWRESAMPLE_1’未定义的引用
/usr/lib/gcc/i686-linux-gnu/4.8/../../../../lib/libavcodec.so:对‘swr_free@LIBSWRESAMPLE_1’未定义的引用
/usr/lib/gcc/i686-linux-gnu/4.8/../../../../lib/libavcodec.so:对‘swr_init@LIBSWRESAMPLE_1’未定义的引用
collect2: error: ld returned 1 exit status

我想可能是编译是路径问题,但是一直没有解决。
请各位帮忙提供编译的意见和建议,谢谢!
...全文
1136 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
puhao_ph 2015-11-13
  • 打赏
  • 举报
回复
不是路径问题,而是你的编译环境依赖库先后问题,在makefile文件如下配置就能解决之(即特别注意LIBS 的顺序): LIB_DIR_FFMPEG += ./codec/ LIBS += -lpthread -ldl -lstdc++ -lz -lm -lbz2 -lrtmp -llzma LIBS += -L$(LIB_DIR_FFMPEG) -lavformat LIBS += -L$(LIB_DIR_FFMPEG) -lx264 LIBS += -L$(LIB_DIR_FFMPEG) -lavcodec LIBS += -L$(LIB_DIR_FFMPEG) -lavutil LIBS += -L$(LIB_DIR_FFMPEG) -lswresample export LIBFLAGS=$(LIBS) 这样就行了

2,542

社区成员

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

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