概述

在ARM平台,可以使用live555和vlc用于RTSP推流。live555代码比较简单,但是单线程,效率不足。因为项目需要,所以交叉编译VLC,用于RTSP服务器。

编译过程

1.下载vlc源码vlc源码下载,我使用的是vlc-2.2.1版本。
2.配置编译脚本,我的编译脚本如下:

#!/bin/sh
# for arm

export PATH=/opt/arm-hisiv200-linux/bin:$PATH
export NM=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-nm
export LD=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ld
export CPLUS=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-g++
export RANLIB=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ranlib
export strip=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-strip
export AR=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ar
export CC=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-gcc
export CXX=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-g++
export ARCH=arm
export CXXFLAGS='-g -O2'
export CFLAGS="$CFLAGS -I/home/vlc/arm_libmad/include -I/home/vlc/arm_ffmpeg_high/include -I/home/vlc/arm_x264/include -I/home/vlc/arm_alsa/include -I/home/vlc/arm_gcrypt/include -I/home/vlc/arm_gpg/include"
export LDFLAGS="$LDFLAGS -L/home/vlc/arm_libmad/lib -L/home/vlc/arm_ffmpeg_high/lib -L/home/vlc/arm_x264/lib -L/home/vlc/arm_alsa/lib -L/home/vlc/arm_gcrypt/lib -L/home/vlc/arm_gpg/lib "
export LIBS="$LIBS -lpthread"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/home/vlc/arm_x264/lib/pkgconfig:/home/vlc/arm_ffmpeg_high/lib/pkgconfig:/home/vlc/arm_alsa/lib/pkgconfig:/home/vlc/arm_gpg/lib/pkgconfig"
./configure -C --build=x86_64-unknown-linux-gnu --target=arm-hisiv200-linux-gnueabi --host=arm-hisiv200-linux-gnueabi \
--prefix=/home/vlc/arm_vlc --enable-run-as-root --enable-vlc  \
--enable-avformat --enable-x264 --enable-mad --enable-httpd \
--enable-realrtsp --enable-sout --enable-libass \
--enable-optimizations \
--disable-postproc  --disable-mod \
--disable-debug --disable-dbus --disable-sdl \
--disable-sdl-image --disable-swscale \
--disable-xcb \
--disable-qt \
--disable-a52 --disable-gles2 --disable-gles1 --disable-lua \
--disable-screen --disable-libmpeg2 --disable-mkv \
--disable-pulse  -- disable-waveout \
--disable-live555 --disable- macosx --disable- macosx-vout \
--disable-macosx-dialog-provider --disable-macosx-qtkit \
--disable-macosx-eyetv --disable-macosx-vlc-app \
--disable-macosx-audio --disable-telepathy --disable-altivec \
--disable-coverage --disable-libproxy --disable-taglib --disable-dvdread \
--disable-dvdnav --disable-smb --disable-dvbpsi --disable-v4l2 \
--disable-vcdx --disable-vcd --disable--libtar --disable-dca \
--disable--vorbis --disable-tremor --disable-gme --disable-ogg \
--disable-mux_ogg --disable-faad --disable-flac \
--disable-speex --disable-theora --disable-dirac \
--disable-schroedinger --disable-png --disable-telx \
--disable-kate --disable-xvideo --disable-freetype --disable-fribidi \
--disable-fontconfig --disable-libxml2 --disable-libgcrypt \
--disable-ncurses --disable-bonjour --disable-visual \
--disable-atmo --disable-gnutls \
--disable-skins2 --disable-lirc --disable-opencv \
--disable-silent-rules \
--disable-neon --disable-dc1394 --disable-dv --disable-vlm \
--disable-gnomevfs --disable-pvr \
--disable-twolame --disable-sftp \
--disable-notify --disable-shout --disable-aa --disable-caca --disable-jack \
--disable-merge-ffmpeg --disable-libva --disable-dxva2 --disable-shine \
--disable-zvbi --disable-tiger \
--disable-maintainer-mode \
--disable-dependency-tracking --disable-non-utf8 \
--disable-gprof --disable-cprof --disable-grow --disable-libcddb \
--disable-wma-fixed  --disable-omxil  --disable-switcher \
--disable-quicktime \
--disable-fluidsynth \
--disable-svg \
--disable-wingdi --disable-directfb --disable-upnp --disable-hildon \
--disable-xosd --disable-fbosd --disable-goom --disable-projectm \
--disable-udev --disable-mtp \
--disable-update-check --disable-sqlite --disable-loader \
--disable-linsys --disable-bluray --disable-smbclient \
--disable-decklink --disable-vnc --disable-freerdp \
--disable-macosx-avfoundation --disable-asdcp \

注意:我使用的交叉编译为海思的arm-hisiv200-linux编译链
3.交叉编译x264,下载x264 x264下载,我下载的版本为last_stable_x264.tar

配置x264,我的配置脚本如下:

#!/bin/sh
./configure --prefix=/home/vlc/arm_x264 --enable-shared --enable-static --host=arm-hisiv200-linux-gnueabi --disable-asm

修改目录下config.mak,
如下config.mak

4.在配置vlc的时候,报错如下:

configure: WARNING: Library ogg >= 1.0 needed for mux_ogg was not found
WARNING: Library ogg opus >= 1.0.3 needed for opus was not found

解决办法:下载libogg,交叉编译,配置如下

#!/bin/sh
# for arm

export NM=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-nm
export LD=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ld
export CPLUS=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-g++
export RANLIB=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ranlib
export strip=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-strip
export AR=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ar
export CC=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-gcc
export CXX=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-g++
export ARCH=arm
export CXXFLAGS='-g -O2'
./configure CC=arm-hisiv200-linux-gnueabi-gcc CXX=arm-hisiv200-linux-gnueabi-g++ ARCH=arm --build=x86_64-unknown-linux-gnu --target=arm-hisiv200-linux-gnueabi --host=arm-hisiv200-linux-gnueabi --prefix=/home/vlc/arm_gpg

然后,make,make install
5.编译libmad,配置脚本如下

./configure --build=x86_64-unknown-linux-gnu --target=arm-hisiv200-linux-gnueabi --host=arm-hisiv200-linux-gnueabi --prefix=/home/vlc/arm_libmad

执行配置脚本,出现出现下面的错误:
unrecognized command line option “-fforce-mem”
原因:gcc 3.4 或者更高版本,已经将“-fforce-mem”去除,所以会出现上面的错误!
解决:找到相关Makefile,找到Makefile里面包含”-fforce-mem”字符串,将其删除

6.编译FFmpeg,配置脚本

export CFLAGS="$CFLAGS -I/home/vlc/arm_x264/include "
export LDFLAGS="$LDFLAGS -L/home/vlc/arm_x264/lib"
./configure  --enable-cross-compile  --target-os=linux --arch=arm  --cc=arm-hisiv200-linux-gnueabi-gcc  --prefix=/home/vlc/arm_ffmpeg \
--enable-shared --postproc-version=current --disable-yasm  --disable-stripping  --enable-pthreads  --enable-shared --enable-avfilter \
--disable-static  --enable-libx264  --enable-nonfree --enable-postproc  --enable-gpl

make 出错:

libavcodec/libx264.c: In function 'X264_init_static':
libavcodec/libx264.c:595: error: 'x264_bit_depth' undeclared (first use in this function)

修改办法:

static av_cold void X264_init_static(AVCodec *codec)
 {
-    if (x264_bit_depth == 8)
+    if (X264_BIT_DEPTH == 8)
         codec->pix_fmts = pix_fmts_8bit;
-    else if (x264_bit_depth == 9)
+    else if (X264_BIT_DEPTH == 9)
         codec->pix_fmts = pix_fmts_9bit;
-    else if (x264_bit_depth == 10)
+    else if (X264_BIT_DEPTH == 10)
         codec->pix_fmts = pix_fmts_10bit;
}

7.下载alsa-lib-1.1.6.tar ,配置脚本:

#!/bin/sh
# for arm

export NM=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-nm
export LD=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ld
export CPLUS=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-g++
export RANLIB=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ranlib
export strip=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-strip
export AR=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ar
export CC=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-gcc
export CXX=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-g++
export ARCH=arm
export CXXFLAGS='-g -O2'
./configure CC=arm-hisiv200-linux-gnueabi-gcc CXX=arm-hisiv200-linux-gnueabi-g++ ARCH=arm --build=x86_64-unknown-linux-gnu --target=arm-hisiv200-linux-gnueabi --host=arm-hisiv200-linux-gnueabi --prefix=/home/vlc/arm_alsa

8.下载libgcrypt,配置脚本

#!/bin/sh
# for arm

export NM=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-nm
export LD=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ld
export CPLUS=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-g++
export RANLIB=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ranlib
export strip=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-strip
export AR=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-ar
export CC=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-gcc
export CXX=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-g++
export ARCH=arm
export CXXFLAGS='-g -O2'
export CFLAGS="$CFLAGS -I/home/vlc/arm_gpg/include"
export LDFLAGS="$LDFLAGS /home/vlc/arm_gpg/lib/libgpg-error.a"
#export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/home/vlc/arm_gpg/lib/pkgconfig"

./configure CC=arm-hisiv200-linux-gnueabi-gcc CXX=arm-hisiv200-linux-gnueabi-g++ ARCH=arm --build=x86_64-unknown-linux-gnu --target=arm-hisiv200-linux-gnueabi --host=arm-hisiv200-linux-gnueabi --prefix=/home/vlc/arm_gcrypt --with-libgpg-error-prefix=/home/vlc/arm_gpg  --enable-static

9.最终配置vlc,执行第一步配置脚本
10.make
出错: warning: libvlccore.so.8, needed by ../lib/.libs/libvlc.so, not found (try using -rpath or -rpath-link)
原因:这个步骤是出现在bin目录的make,修改bin目录的Makefile.am
Makefile.am1
Makefile.am2

11.make ,make install