2016年6月13日 星期一

[Embedded] How to rebuild ffmpeg with librtmp

Here list the procedure to cross compile ffmpeg with librtmp plugin.



0. Test environment

  • Ubuntu:  version X86_64 14.02
  • FFmpeg:  version 2.7
  • rtmpdump:  git commit fa8646daeb19dfd12c181f7d19de708d623704c0


1. Download and rebuild librtmp
$ git clone git://git.ffmpeg.org/rtmpdump
$ cd rtmpdump/
$ cd librtmp
$ vi Makefile
CROSS_COMPILE=arm-linux-gnueabihf-
CFLAGS=-Wall $(XCFLAGS) $(INC) $(DEF) $(OPT) $(SO_DEF) -I../zlib-1.2.8 -I../openssl/include
LDFLAGS=$(XLDFLAGS) -L../openssl -L../zlib-1.2.8
$ make
$ make install

2. Rebuild ffmpeg.
Add below configuration when you execute "./configure"
--extra-cflags="-I../ -I../librtmp/" \
--extra-ldflags="-L../librtmp/ -L../zlib-1.2.8/ -L../openssl/ -lrtmp -lz -lssl -lcrypto" \
--extra-libs="-lz -lssl -lcrypto -lrtmp" 
For example:
$ ./configure --cross-prefix=arm-linux-gnueabihf- --enable-librtmp \
....  (omit) \
--extra-cflags="-I../ -I../librtmp/" \
--extra-ldflags="-L../librtmp/ -L../zlib-1.2.8/ -L../openssl/ -lrtmp -lz -lssl -lcrypto" \
--extra-libs="-lz -lssl -lcrypto -lrtmp"
$ make

3. Make sure if ffmpeg is compiled correctly
  Tag        Type                         Name/Value
0x00000001 (NEEDED)                     Shared library: [librtmp.so.1]
0x00000001 (NEEDED)                     Shared library: [libz.so.1]
0x00000001 (NEEDED)                     Shared library: [libavdevice.so.56]
0x00000001 (NEEDED)                     Shared library: [libavfilter.so.5]
0x00000001 (NEEDED)                     Shared library: [libavformat.so.56]
0x00000001 (NEEDED)                     Shared library: [libavcodec.so.56]
0x00000001 (NEEDED)                     Shared library: [libswresample.so.1]
0x00000001 (NEEDED)                     Shared library: [libswscale.so.3]
0x00000001 (NEEDED)                     Shared library: [libavutil.so.54]
0x00000001 (NEEDED)                     Shared library: [libm.so.6]
0x00000001 (NEEDED)                     Shared library: [libpthread.so.0]
0x00000001 (NEEDED)                     Shared library: [libc.so.6]
0x0000000c (INIT)                       0xcf0c

4. Create youtube live streaming and test
a. Below is an example of youtube live streaming
b. The example ffmpeg command
$ ffmpeg -i 7h800.mp4 -vcodec copy -acodec copy -f flv rtmp://a.rtmp.youtube.com/live2/g6tk-0su4-x85k-7vgc
NOTE: In a network behind NAT, the RTMP streaming may not work. You can use NATDetector to detect your NAT type.

Reference:

  1. http://blog.csdn.net/fireroll/article/details/18899285
  2. http://blog.csdn.net/fireroll/article/details/8607955