FFmpeg在Ubuntu下的编译

FFmpeg在Ubuntu下的编译

VMware Workstation10

Ubuntu 16

android-ndk-r15c(用其他版本有时候编译不过)

ffmpeg-4.2.1(地址:https://www.johnvansickle.com/ffmpeg/)

将下载下来的ffmpeg进行解压

进入已解压的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)'



编写build_android.sh的可执行文件,并给权限 chmod 0777 build_android.sh



#!/bin/bash

# 清空上次的编译

make clean

#你自己的NDK路径.

export NDK=/home/huangsuwen/tangshanqiang/ffmpeg/android-ndk-r15c

function build_android

{

echo "Compiling FFmpeg for $CPU"

./configure \

    --prefix=$PREFIX \

    --enable-neon \

    --enable-hwaccels \

    --enable-gpl \

    --enable-postproc \

    --enable-shared \

    --enable-jni \

    --enable-mediacodec \

    --enable-decoder=h264_mediacodec \

    --disable-static \

    --disable-doc \

    --enable-ffmpeg \

    --disable-ffplay \

    --disable-ffprobe \

    --enable-avdevice \

    --disable-doc \

    --disable-symver \

    --cross-prefix=$CROSS_PREFIX \

    --target-os=android \

    --arch=$ARCH \

    --cpu=$CPU \

    --enable-cross-compile \

    --sysroot=$SYSROOT \

    --extra-cflags="-Os -fpic $OPTIMIZE_CFLAGS" \

    --extra-ldflags="$ADDI_LDFLAGS" \

    $ADDITIONAL_CONFIGURE_FLAG

make clean

make

make install

echo "The Compilation of FFmpeg for $CPU is completed"

}

#armv8-a

if false;then

ARCH=arm64

CPU=armv8-a

TOOLCHAIN=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64

SYSROOT=$NDK/platforms/android-21/arch-$ARCH/

CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-

PREFIX=$(pwd)/android/$CPU

OPTIMIZE_CFLAGS="-march=$CPU"

build_android

fi

#armv7-a

ARCH=arm

CPU=armv7-a

TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64

SYSROOT=$NDK/platforms/android-21/arch-$ARCH/

CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-

PREFIX=$(pwd)/android/$CPU

rm -rf $PREFIX

mkdir -p $PREFIX

OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "

build_android

if false;then

#x86

ARCH=x86

CPU=x86

TOOLCHAIN=$NDK/toolchains/x86-4.9/prebuilt/linux-x86_64

SYSROOT=$NDK/platforms/android-21/arch-$ARCH/

CROSS_PREFIX=$TOOLCHAIN/bin/i686-linux-android-

PREFIX=$(pwd)/android/$CPU

OPTIMIZE_CFLAGS="-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32"

build_android

fi

#x86_64

if false;then

ARCH=x86_64

CPU=x86-64

TOOLCHAIN=$NDK/toolchains/x86_64-4.9/prebuilt/linux-x86_64

SYSROOT=$NDK/platforms/android-21/arch-$ARCH/

CROSS_PREFIX=$TOOLCHAIN/bin/x86_64-linux-android-

PREFIX=$(pwd)/android/$CPU

OPTIMIZE_CFLAGS="-march=$CPU -msse4.2 -mpopcnt -m64 -mtune=intel"

build_android

fi;


安装必要的编译库;

sudo apt-get install make 

sudo apt-get install  gcc


执行FFmpeg源码的配置命./configure(build_android.sh执行前)

执行该句命令,如果报错:nasm/yasm not found or too old.则需要安装yasm,可以执行命令

sudo apt-get install yasm,或者按照提示执行./configure --disable-x86asm

安装完成好,再次执行FFmpeg源码的配置命令,yasm的错误信息已消除,但出现如下警告信息:

WARNING: pkg-config not found, library detection may fail.

执行安装命令sudo apt-get install pkg-config

再次执行FFmpeg源码的配置命令./configure

执行编译FFmpeg命令./build_android.sh;

如果出现/bin/bash^M: 解释器错误: 没有那个文件或目录,可以使用命令行 bash build_android.sh

如果出现找不到文件等是由于拷贝的文件是doc,查看 vim  build_android.sh 进入:set ff  查看文件格式 fileformat=dos

安装工具:sudo apt-get install dos2unix

使用工具:dos2unix  build_android.sh   

查看格式: set ff  

执行完编译./build_android.sh后,静等编译完成


编译生成静态库:

将ffbuild/library.mak中

install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)

$(Q)mkdir -p"$(SHLIBDIR)"

$$(INSTALL) -m 755 $$<"$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"

$$(STRIP)"$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"

$(Q)$(foreach F,$(SLIB_INSTALL_LINKS),(cd"$(SHLIBDIR)"&& $(LN_S) $(SLIB_INSTALL_NAME) $(F));)

$(if$(SLIB_INSTALL_EXTRA_SHLIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_SHLIB:%=$(SUBDIR)%)"$(SHLIBDIR)")

$(if$(SLIB_INSTALL_EXTRA_LIB),$(Q)mkdir -p"$(LIBDIR)")

$(if$(SLIB_INSTALL_EXTRA_LIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_LIB:%=$(SUBDIR)%)"$(LIBDIR)")

注释掉几行,如下:

install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)

$(Q)mkdir -p"$(SHLIBDIR)"

$$(INSTALL) -m 755 $$<"$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"

# $$(STRIP) "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"

# $(Q)$(foreach F,$(SLIB_INSTALL_LINKS),(cd "$(SHLIBDIR)" && $(LN_S) $(SLIB_INSTALL_NAME) $(F));)

# $(if $(SLIB_INSTALL_EXTRA_SHLIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_SHLIB:%=$(SUBDIR)%) "$(SHLIBDIR)")

# $(if $(SLIB_INSTALL_EXTRA_LIB),$(Q)mkdir -p "$(LIBDIR)")

# $(if $(SLIB_INSTALL_EXTRA_LIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_LIB:%=$(SUBDIR)%) "$(LIBDIR)")


make,make install就能得到可直接使用的动态库,而非链接文件:的 libavcodec.so libavdevice.so libavfilter.so libavformat.so libavutil.so libswresample.so libswscale.so


以上方法很多编译不过,参照网上最新的做法:https://juejin.im/post/6844903945496690696?utm_source=gold_browser_extension

你可能感兴趣的:(FFmpeg在Ubuntu下的编译)