mingw編譯ffmpeg+librtmp過程記錄

來源:互聯網
上載者:User

    ffmpeg支援RTMP用戶端,如果想使用ffmpeg將音視頻發布至red5上,以實現即時直播,則需要librtmp的支援。在linux下的編譯比較簡單,這裡使用mingw在windows上編譯。

1.相關資源下載
    rtmpdump-2.3-windows.zip    http://rtmpdump.mplayerhq.hu/download
    openssl-1.0.0g.tar.gz   http://www.openssl.org/source/
    zlib-1.2.3-lib.zip  http://nchc.dl.sourceforge.net/project/gnuwin32/zlib/1.2.3/
    ActivePerl-5.14.2.1402-MSWin32-x86-295342.msi   http://downloads.activestate.com/ActivePerl/releases/5.14.2.1402/ActivePerl-5.14.2.1402-MSWin32-x86-295342.msi

   ffmpeg-0.8.5 http://ffmpeg.org/download.html#release_0.8

   SDL-devel-1.2.15-mingw32.tar.gz http://www.libsdl.org/download-1.2.php

2.librtmp編譯及安裝
    librtmp是rtmpdump上中的一部分,rtmpdump的readme中有編譯說明,依賴於openssl及zlib.
1)openssl
    openssl-1.0.0g.tar.gz,在rtmpdump的readme中有關於openssl的編譯說明,configure需要perl的支援,所以首先安裝ActivePerl-5.14.2.1402-MSWin32-x86-295342.msi。

./Configure mingw --prefix=`pwd`/win32libs -DL_ENDIAN -DOPENSSL_NO_HWmakemake install 

    make 時提示以下錯誤:

-c -o md2test.o md2test.cmd2test.c:1:10: 錯誤:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’before ‘.’ tokenmake[1]: *** [md2test.o] Error 1make[1]: Leaving directory `/d/work/multimedia/openssl-1.0.0g/test'make: *** [build_tests] Error 1

開啟md2test.c,只有一條語句,
dummytest.c
修改為
#include "dummytest.c"
另外兩個檔案rc5test.c  jpaketest.c也同樣處理
終於make編譯通過了,然後make install進行安裝

2)zlib
zlib-1.2.3-lib.zip是已經編譯好的,直接將*.h及lib檔案copy到mingw相應目錄中即可。

3)rtmpdump
    rtmpdump-2.3-windows.zip,解壓後readme檔案中有mingw環境的編譯說明

$ make SYS=mingw$ make SYS=mingw install

2.編譯ffmpeg-0.8.5

$ ./configure --enable-librtm$ make $ make install

ffmpeg使用SDL來播放,所以在編譯ffmpeg之前,需要安裝SDL。

 編譯中的問題:

1)pkg-config的安裝 
    如果mingw中沒有安裝pkg-config,則需要安裝, 否則在./configure時會出錯,安裝方法如下:
下載

http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.18/glib_2.18.4-1_win32.zip

http://ftp.acc.umu.se/pub/gnome/binaries/win32/dependencies/pkg-config-0.26-1.zip

把glib_2.18.4-1_win32.zip中的libglib-2.0-0.dll與pkg-config.exe放在mingw中的相應目錄中.
設定環境變數
在mingw中輸入命令:export PKG_CONFIG_PATH=:/usr/local/lib/pkgconfig
/usr/local/lib/pkgconfig為*.pc檔案所在目錄。

2)configure及make時的一個錯誤
提示錯誤:
ERROR: librtmp not found
查看記錄檔config.log:

END /tmp/ffconf..liangguangwei.500.21836.cgcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -U__STRICT_ANSI__ -std=c99 -fno-common -fomit-frame-pointer -Id:/MinGW/msys/1.0/local/include -Ld:/MinGW/msys/1.0/local/lib -c -o /tmp/ffconf..liangguangwei.500.21836.o /tmp/ffconf..liangguangwei.500.21836.cgcc -Wl,--as-needed -Id:/MinGW/msys/1.0/local/include -Ld:/MinGW/msys/1.0/local/lib -o /tmp/ffconf..liangguangwei.500.21836.exe /tmp/ffconf..liangguangwei.500.21836.o -lrtmp -lz -lssl -lcrypto -lws2_32 -lgdi32 -lcrypt32 -lm -lpthread -lz -lpsapid:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../librtmp.a(rtmp.o):rtmp.c:(.text+0x3ee9): undefined reference to `timeGetTime@0'd:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../librtmp.a(rtmp.o):rtmp.c:(.text+0x4461): undefined reference to `timeGetTime@0'd:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../librtmp.a(rtmp.o):rtmp.c:(.text+0x4ddf): undefined reference to `timeGetTime@0'd:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../librtmp.a(rtmp.o):rtmp.c:(.text+0x4e33): undefined reference to `timeGetTime@0'd:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../librtmp.a(rtmp.o):rtmp.c:(.text+0xc5d): undefined reference to `timeGetTime@0'collect2: ld returned 1 exit statusERROR: librtmp not found

這是由於缺少libwinmm.a, 修改configure,在enabled librtmp 行未尾添加-lwinmm
enabled librtmp    && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket  -lwinmm

同樣在make時也會提示類似錯誤,開啟config.mak檔案,找到EXTRALIBS,在最後添加-lwinmm
EXTRALIBS=-lavicap32 -lws2_32 -mwindows -Ld:/MinGW/msys/1.0/local/lib -lmingw32 -lSDLmain -lSDL -Ld:/MinGW/msys/1.0/local/lib -lrtmp -lz -lssl -lcrypto -lws2_32 -lgdi32 -lcrypt32 -lm -lz -lpsapi -lwinmm 
終於編譯成功了,最後不要忘記make install

PS:
在編譯過程中遇到的其它問題
1)ffmpeg-0.8.5中不能使用rtmpdump-2.2x版本,rtmpdump-2.2x中缺少RTMP_Socket等函數的定義,在ffmpeg的config.log中的錯誤資訊如下:
config.log

tmp/ffconf.mlRyi10R.c: In function 'check_RTMP_Socket':/tmp/ffconf.mlRyi10R.c:2: error: 'RTMP_Socket' undeclared (first use in this function)/tmp/ffconf.mlRyi10R.c:2: error: (Each undeclared identifier is reported only once/tmp/ffconf.mlRyi10R.c:2: error: for each function it appears in.)ERROR: librtmp not found

2)一個奇怪的問題,ffmpeg與librtmp一起編譯後,ffplay竟然不能播放rtmp協議的地址了。

3)在使用mingw時,發現編譯時間竟然不能找到/usr/local/(D:\MinGW\msys\1.0\local)中的*.h與lib檔案

建立檔案 /etc/profile.d/local.sh

#! /usr/bin/shexport CPATH=/usr/local/include:/usr/include:$CPATHexport C_INCLUDE_PATH=/usr/local/include:/usr/include:$C_INCLUDE_PATHexport CPLUS_INCLUDE_PATH=/usr/local/include:/usr/include:$CPLUS_INCLUDE_PATHexport OBJC_INCLUDE_PATH=/usr/local/include:/usr/include:$OBJC_INCLUDE_PATHexport LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATHexport LIBRARY_PATH=/usr/local/lib:/usr/lib:$LIBRARY_PATHexport LIBPATH=/usr/local/lib:/usr/lib:$LIBPATH

4)在編譯rtmpdump時,不使用任何加密傳輸方式,這時就不需要openssl庫的支援了,不再支援rtmpe/rtmps/https

$ make SYS=mingw  CRYPTO=
補充:
1.ffplay無法播放rtmp路徑的問題,將rtmpdump升級至2.4版本,就可以解決。rtmpdump-2.4.tar.gz:http://download.chinaunix.net/download.php?id=32814&ResourceID=13015,官網上提供git及svn方式下載。2.用red5中的oflaDemo應用可以實現直播功能,參考Live Encoding Tutorial
ffmpeg -i test.flv -re -f flv rtmp://192.168.9.80/oflaDemo/stream
3.在ubuntu中搭建好環境後,
 
ffmpeg -re -i myfile -f flv rtmp://myserver/live/mystream

可能提示錯誤

rtmpdump: error while loading shared libraries: librtmp.so.0: cannot open shared object file: No such file or directory
輸入命令:sudo cp librtmp.so.0 /lib,即可解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.