FFmpeg在Ubuntu下的編譯
VMware Workstation10
Ubuntu 16
android-ndk-r15c(用其他版本有時候編譯不過)
ffmpeg-4.2.1(地址:https://www.johnvansickle.com/ffmpeg/)
將下載下來的ffmpeg進(jìn)行解壓
進(jìn)入已解壓的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的可執(zhí)行文件宣蔚,并給權(quán)限 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
執(zhí)行FFmpeg源碼的配置命./configure(build_android.sh執(zhí)行前)
執(zhí)行該句命令,如果報錯:nasm/yasm not found or too old.則需要安裝yasm,可以執(zhí)行命令
sudo apt-get install yasm,或者按照提示執(zhí)行./configure --disable-x86asm
安裝完成好,再次執(zhí)行FFmpeg源碼的配置命令横殴,yasm的錯誤信息已消除,但出現(xiàn)如下警告信息:
WARNING: pkg-config not found, library detection may fail.
執(zhí)行安裝命令sudo apt-get install pkg-config
再次執(zhí)行FFmpeg源碼的配置命令./configure
執(zhí)行編譯FFmpeg命令./build_android.sh;
如果出現(xiàn)/bin/bash^M: 解釋器錯誤: 沒有那個文件或目錄妇智,可以使用命令行?bash build_android.sh
如果出現(xiàn)找不到文件等是由于拷貝的文件是doc滥玷,查看 vim??build_android.sh 進(jìn)入:set ff? 查看文件格式?fileformat=dos
安裝工具:sudo apt-get install?dos2unix
使用工具:dos2unix??build_android.sh? ?
查看格式:?set ff??
執(zhí)行完編譯./build_android.sh后,靜等編譯完成
編譯生成靜態(tài)庫:
將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就能得到可直接使用的動態(tài)庫,而非鏈接文件:的?libavcodec.so?libavdevice.so?libavfilter.so?libavformat.so?libavutil.so?libswresample.so?libswscale.so
以上方法很多編譯不過航徙,參照網(wǎng)上最新的做法:https://juejin.im/post/6844903945496690696?utm_source=gold_browser_extension