mingw编译ffmpeg+librtmp过程记录

    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_HW
make
make install 
    make 时提示以下错误:
-c -o md2test.o md2test.c
md2test.c:1:10: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’
before ‘.’ token
make[1]: *** [md2test.o] Error 1
make[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.c
gcc -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.c
gcc -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 -lpsapi
d:/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 status
ERROR: 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/sh
export CPATH=/usr/local/include:/usr/include:$CPATH
export C_INCLUDE_PATH=/usr/local/include:/usr/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/local/include:/usr/include:$CPLUS_INCLUDE_PATH
export OBJC_INCLUDE_PATH=/usr/local/include:/usr/include:$OBJC_INCLUDE_PATH
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=/usr/local/lib:/usr/lib:$LIBRARY_PATH
export 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,即可解决









你可能感兴趣的:(socket,function,Path,include,library,reference)