1../configure --enable swscale
2.make
3.make install
正常安装结束。此时/usr/local/include下会多出一个ffmpeg文件夹,里面有一些头文件,以后要用到。
/usr/local/lib下会多出libavformat.a,libavcodec.a,libavutils.a,这几个静态库在编译output_example.c的时候要用到。
4.gcc -o hh output_examples.c
错误: output_example.c:34:22: avformat.h: 没有那个文件或目录
output_example.c:35:21: swscale.h: 没有那个文件或目录
output_example.c:45: `SWS_BICUBIC' undeclared here (not in a function)
output_example.c:52: parse error before '*' token
...
解决:需要添加引用头文件的位置
5.gcc -o hh output_example.c -I/usr/local/include/ffmpeg
错误: /tmp/ccW5CPkd.o(.text+0xf): In function `add_audio_stream':
: undefined reference to `av_new_stream'
/tmp/ccW5CPkd.o(.text+0xa0): In function `open_audio':
: undefined reference to `avcodec_find_encoder'
/tmp/ccW5CPkd.o(.text+0xda): In function `open_audio':
...
解决:为编译选项添加要用到的静态库(就是前面提到的那三个.a库)
6.cp /usr/local/lib/libav*a /usr/lib
gcc -o hh output_example.c -I/usr/local/include/ffmpeg -lavformat -lavcodec -lavutil
错误: /tmp/ccI2Tg2J.o(.text+0x1f4): In function `get_audio_frame':
: undefined reference to `sin'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libavformat.a(mov.o)(.text+0x211d): In function `mov_read_cmov':
/tmp/ffmpeg/libavformat/mov.c:1186: undefined reference to `uncompress'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libavcodec.a(mpegvideo.o)(.text+0x28b0): In function `ff_print_debug_info':
/tmp/ffmpeg/libavcodec/mpegvideo.c:1328: undefined reference to `cos'
...
解决:添加lmath库
7.gcc -o hh output_example.c -I/usr/local/include/ffmpeg -lavformat -lavcodec -lavutil -lm
错误: /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libavformat.a(mov.o)(.text+0x211d): In function `mov_read_cmov':
/tmp/ffmpeg/libavformat/mov.c:1186: undefined reference to `uncompress'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libavcodec.a(cscd.o)(.text+0xb1): In function `decode_frame':
/tmp/ffmpeg/libavcodec/cscd.c:168: undefined reference to `uncompress'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libavcodec.a(dxa.o)(.text+0xde): In function `decode_frame':
/tmp/ffmpeg/libavcodec/dxa.c:233: undefined reference to `uncompress'
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../libavcodec.a(flashsv.o)(.text+0x3e): In function `flashsv_decode_init':
...
解决:添加zlib库
8. gcc -o hh output_example.c -I/usr/local/include/ffmpeg -lavformat -lavcodec -lavutil -lm -lz
错误undefined reference to `BZ2_bzDecompressInit'
解决添加库
gcc -o hh output_example.c -I/usr/local/include/ffmpeg -lavformat -lavcodec -lavutil -lm -lz -lbz2
9. gcc -o hh output_example.c -I/usr/local/include/ffmpeg -lavformat -lavcodec -lavutil -lm -lz -lbz2
错误 undefined reference to 'sws_scale'
解决添加库(lswscale)
gcc -o hh output_example.c -I/usr/local/include/ffmpeg -lavformat -lavcodec -lavutil -lswscale -lm -lz -lbz2
编译成功。
10.运行编译出来的东东。
[root@localhost ffmpeg]# ./hh
usage: ./hh output_file
API example program to output a media file with libavformat.
The output format is automatically guessed according to the file extension.
Raw images can also be output by using '%d' in the filename
本人使用的ffmpeg是0.6的版本。前面7条是转载别人的文章,后面两条是我遇到的问题以及解决方法。
希望以上对入门者有点帮助。