跨平台实现qt+ffmpeg+rtsp

1 编译ffmpeg

##
#    Copyright By Schips, All Rights Reserved
#    https://gitee.com/schips/

#    File Name:  make.sh
#    Created  :  Mon 02 Sep 2019 08:05:53 PM HKT
##
#!/bin/sh
BASE=`pwd`
BUILD_HOST=arm-hisiv500-linux
OUTPUT_PATH=${BASE}/install

OTHER_LIB=${OUTPUT_PATH}/__all_without_ffmpeg

make_dirs () {
    #为了方便管理,创建有关的目录
    cd ${BASE} && mkdir compressed install source -p
}

tget () { #try wget
    filename=`basename $1`
    echo "Downloading [${filename}]..."
    if [ ! -f ${filename} ];then
        wget $1
    fi

    echo "[OK] Downloaded [${filename}] "
}

download_package () {
    cd ${BASE}/compressed
    tget http://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20171212-2245.tar.bz2
    tget http://ffmpeg.org/releases/ffmpeg-3.4.1.tar.bz2
    tget http://download.videolan.org/videolan/x265/x265_2.6.tar.gz
}

tar_package () {
    cd ${BASE}/compressed
    ls * > /tmp/list.txt
    for TAR in `cat /tmp/list.txt`
    do
        tar -xf $TAR -C  ../source
    done
    rm -rf /tmp/list.txt
}

make_x264() {
    cd ${BASE}/source/x264*

    CC=${BUILD_HOST}-gcc \
    ./configure \
    --host=${BUILD_HOST} \
    --enable-shared \
    --enable-static \
    --enable-pic \
    --prefix=${OUTPUT_PATH}/x264 \
    --cross-prefix=${BUILD_HOST}- \
    --disable-asm

    make -j4 && make install
}

make_x265() {
    #sudo apt-get install cmake -y
    # 其他编译选项可以 通过 在 cmake ../source 以后 ccmake ../source 可以查看 ( ccmake 可以通过 sudo apt-get install cmake-curses-gui  进行安装 )
        cd ${BASE}/source/x265*/source
    # 获取 工具链所在位置 下面的操作为的是在 CMakeLists.txt 中插入下面内容
        #set( CMAKE_SYSTEM_NAME Linux  )
        #set( CMAKE_SYSTEM_PROCESSOR ARM  )
        #set( CMAKE_C_COMPILER "/opt/hisi-linux/x86-arm/arm-hisiv500-linux/target/bin/arm-hisiv500-linux-gcc" )
        #set( CMAKE_CXX_COMPILER "/opt/hisi-linux/x86-arm/arm-hisiv500-linux/target/bin/arm-hisiv500-linux-g++" )
        #set( CMAKE_FIND_ROOT_PATH "/opt/hisi-linux/x86-arm/arm-hisiv500-linux/target/bin/" )
    GCC_FULL_PATH=`whereis ${BUILD_HOST}-gcc | awk -F: '{ print $2 }' | awk '{print $1}'` # 防止多个结果
    GCC_DIR=`dirname ${GCC_FULL_PATH}/`
    sed -i "1i\set( CMAKE_SYSTEM_NAME Linux  )"                         CMakeLists.txt
    sed -i "2a\set( CMAKE_SYSTEM_PROCESSOR ARM  )"                      CMakeLists.txt
    sed -i "2a\set( CMAKE_C_COMPILER ${GCC_DIR}/${BUILD_HOST}-gcc  )"   CMakeLists.txt
    sed -i "2a\set( CMAKE_CXX_COMPILER ${GCC_DIR}/${BUILD_HOST}-g++  )" CMakeLists.txt
    sed -i "2a\set( CMAKE_FIND_ROOT_PATH ${GCC_DIR} )"                  CMakeLists.txt
    cmake ../source
    # 指定安装路径
    sed -i "1i\set( CMAKE_INSTALL_PREFIX "${BASE}/install/x265"  )"     cmake_install.cmake
    make && make install
}
prepare_other_lib () {
    # 这一个是针对 ffmpeg 方便管理外部库使用的
    # 核心思想是把 所有的库都放到一起,再让 ffmpeg ld的时候在这里找(而不是添加多行) --extra-cflags="-I${X264_DIR}/include -I${xxx}/include" \
    cd ${BASE}/install/
    rm ${OTHER_LIB} -rf
    ls > /tmp/list.txt
    mkdir ${OTHER_LIB} -p
    for sub_dir in `cat /tmp/list.txt`
    do
        cp ${sub_dir}/* ${OTHER_LIB} -r -v
    done
    rm -rf /tmp/list.txt
}
make_ffmpeg() {
    cd ${BASE}/source/ffmpeg*
    ./configure \
    --cross-prefix=${BUILD_HOST}- \
    --enable-cross-compile \
    --target-os=linux \
    --cc=${BUILD_HOST}-gcc \
    --arch=arm \
    --prefix=${OUTPUT_PATH}/ffmpeg \
    --enable-shared \
    --enable-static \
    --enable-gpl \
    --enable-nonfree \
    --enable-ffmpeg \
    --disable-ffplay \
    --enable-ffserver \
    --enable-swscale \
    --enable-pthreads \
    --disable-armv5te \
    --disable-armv6 \
    --disable-armv6t2 \
    --disable-yasm \
    --disable-stripping \
    --enable-libx264 \
    --enable-libx265 \
    --extra-cflags=-I${OTHER_LIB}/include \
    --extra-ldflags=-L${OTHER_LIB}/lib
    make clean && make -j4 && make install
}
echo "Using ${BUILD_HOST}-gcc"
make_dirs
download_package
tar_package
make_x264
make_x265
prepare_other_lib
make_ffmpeg

遇到问题
1、ERROR: x265 not found using pkg-config
检查ffmepg目录下/ffbuild/config.log
# warning You must include stdint.h or inttypes.h before x264.h
^
/tmp/ffconf.Se4erZG7/test.c:3:2: error: #error “unsatisfied condition: X264_MPEG2”
#error “unsatisfied condition: X264_MPEG2”
^
require_pkg_config libx265 x265 x265.h x265_api_get
use_pkg_config libx265 x265 x265.h x265_api_get
check_pkg_config libx265 x265 x265.h x265_api_get
false --exists --print-errors x265
ERROR: x265 not found using pkg-config
很诡异吧 因为x264库的问题导致这个问题 搜索了一下网上关于ffmpeg的各种编译问题大概有如下几个解决方法需要针对你自己的config。log文件去对照
a、x265.pc文件 -lpthread 加到了 Libs.private 这一句的后面 解决线程相关的错误俄
x265::Thread::start()。。。。。。。。。。
b、在./configure之前输入export PKG_CONFIG_PATH=/usr/local/lib /pkgconfig:$PKG_CONFIG_PATH(此路径为.pc文件所在路径),可使用
echo $PKG_CONFIG_PATH查看
c、 #error “unsatisfied condition: X264_MPEG2”
# warning You must include stdint.h or inttypes.h before x264.h

android apk error:
07-15 13:59:22.632: E/art(2135): dlopen("/data/app/com.demo.openglshow-1/lib/arm/libswresample-2.so", RTLD_LAZY) failed: dlopen failed: could not load library “libavutil.so.55” needed by “libswresample-2.so”; caused by library “libavutil.so.55” not found
07-15 13:59:22.635: E/AndroidRuntime(2135): FATAL EXCEPTION: GLThread 39119
07-15 13:59:22.635: E/AndroidRuntime(2135): Process: com.demo.openglshow, PID: 2135
07-15 13:59:22.635: E/AndroidRuntime(2135): java.lang.UnsatisfiedLinkError: dlopen failed: could not load library “libavutil.so.55” needed by “libswresample-2.so”; caused by library “libavutil.so.55” not found
解决办法:
修改configure文件:

#SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'

#LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'

#SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'

#SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'

SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'

LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'

SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'

//很多ffmpeg编译资料上面说要修改configure文件 ,说的原因是 如果不修改的话,在android上 System.loadLibrary(‘xxx’); 的时候个别so//库无法加载的问题。
//打开 ffmpeg源码内 configure 文件进行如下修改:

SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)'$(LIBDIR)/$(LIBNAME)''
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR)$(SLIBNAME)'
替换为:
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)'$(LIBDIR)/$(LIBNAME)''
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'

你可能感兴趣的:(qt)