1. 程式人生 > >ffmpeg 編譯常見錯誤

ffmpeg 編譯常見錯誤

一、FFmpeg原始碼下載與編譯
# wget http://www.ffmpeg.org/releases/ffmpeg-0.5.13.tar.bz2
# tar -jxvf ffmpeg-0.5.13.tar.bz2
# vim ffmpeg_configure.sh
./configure \
--prefix=/YOUR_INSTLL_DIRECTORY \
--enable-gpl --enable-nonfree --enable-version3 \
--enable-swscale --enable-avfilter  \
--enable-pthreads
【儲存並退出】
# chmod +x ffmpeg_configure.sh

# ./ffmpeg_configure.sh
# make
# make install

二、生成SDK
將安裝目錄“”下的 
YOUR_INSTLL_DIRECTORY/include
YOUR_INSTLL_DIRECTORY/lib
打包,就可以生成一個開發用的SDK
# tar -czvf YOUR_INSTLL_DIRECTORY/ ffmpeg_sdk.tar.gz

三、使用output_example測試SDK
1. 複製檔案
將ffmpeg-0.5.13下的output_example.c複製到SDK目錄;

2. 編譯生成:
# gcc output_example.c -o output_example 
-I/opt/.../include 
-L/opt/.../lib  
-lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswscale

1) 錯誤提示:
/opt/.../ffmpeg-0.5.13/libswscale/swscale.c:1234: undefined reference to `pow'
/opt/.../ffmpeg-0.5.13/libswscale/swscale.c:1238: undefined reference to `sin'
/opt/.../ffmpeg-0.5.13.install/lib/libswscale.a(swscale.o): In function `sws_getGaussianVec':
...

解決:
編譯時加連結linux的數學函式庫 "-lm"
# gcc output_example.c -o output_example 
-I/opt/.../include 
-L/opt/.../lib  
-lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswscale
-lm

2) 錯誤提示:
/opt/.../lib/libavcodec.a(pthread.o): In function `avcodec_thread_free':
/opt/.../libavcodec/pthread.c:95: undefined reference to `pthread_join'

解決:
編譯時加連結linux的多執行緒庫 "-lpthread"
# gcc output_example.c -o output_example 
-I/opt/.../include 
-L/opt/.../lib  
-lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswscale
-lm -lpthread

3). 錯誤提示:
/opt/.../lib/libavcodec.a(pngdec.o): In function `decode_frame':
/opt/.../lib/libavcodec/pngdec.c:406: undefined reference to `inflateInit_'
/opt/.../lib/libavcodec.a(pngdec.o): In function `png_decode_idat':
/opt/.../lib/libavcodec/pngdec.c:365: undefined reference to `inflate'
/opt/.../lib/libavcodec.a(pngdec.o): In function `decode_frame':
/opt/.../lib/libavcodec/pngdec.c:591: undefined reference to `inflateEnd'

解決:
編譯時加連結linux的通用例程庫 "-lz"
# gcc output_example.c -o output_example 
-I/opt/.../include 
-L/opt/.../lib  
-lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswscale
-lm -lpthread -lz

4). 錯誤提示
/opt/.../lib/libavformat.a(allformats.o): In function `av_register_all':
/opt/.../libavformat/allformats.c:48: undefined reference to `avcodec_register_all'
/opt/.../lib/libavformat.a(utils.o): In function `av_find_stream_info':
...

原因: 包依賴關係
解決:
# gcc output_example.c -o output_example 

-I/opt/ffmpeg/sourcecode/ffmpeg-0.5.13.install/include 
-L/opt/ffmpeg/sourcecode/ffmpeg-0.5.13.install/lib  
-lavformat -lavdevice -lavcodec  -lavutil -lavfilter 
-pthread -ldl -lswscale -lbz2 -lasound  -lz -lm

四、執行
# ./output_example xxx.flv