Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile FFMPEG for command line usage

I've been trying to compile FFMPEG so I can use it with my Android application with commands. The result should be 1 static file, "ffmpeg", that is not package dependent. No .so files.

I managed to compile it with guardianProject and everything is working but the source was too old and lacks options I need. I'm using the latest Ubuntu on VirtualBox, all essentials are installed and updated (gawk, yasm, aptitude, etc...).

There are multiple examples around the web. Here are the issues I've experienced with each of the options I tried. I'd appreciate help with either one of the following errors:

  1. Guardian project - I managed to compile it and get the ffmpeg file but it uses an old version of ffmpeg that doesn't include the "-movFlags faststart" option. I tried throwing the new ffmpeg (2.3.3) in there but it just throws error. (I ran git submodule init and update)

  2. JayH5 - A more generic build file that basically should work with every ffmpeg. I updated the build script to work with the latest NDK and it seems to be working but than it fails on /home/dor/Desktop/ndk/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-pkg-config not found, library detection may fail. I read about this and it seems to require a hack, which I don't understand how to implement.

  3. Trovao - this is a very nice project and the build script even downloads the latest ffmpeg and x264 sources, and I even succeeded in compiling it to FFMPEG and X264 files but when I use it, I get this error: could not load library "libx264.so.142 which is weird, as x264 is there and the whole idea of this project is to cancel the need of .so files.

I'd appreciate help with figuring out how to solve any of the issues. I prefer using the JayH5 build script as it seems the most straight forward out there...

JayH5 build file:

#!/bin/bash

# set the base path to your Android NDK (or export NDK to environment)

if [[ "x$NDK_BASE" == "x" ]]; then
    NDK_BASE=/opt/android-ndk
    echo "No NDK_BASE set, using $NDK_BASE"
fi

NDK_PLATFORM_VERSION=14
NDK_ABI=arm
NDK_COMPILER_VERSION=4.8
NDK_SYSROOT=$NDK_BASE/platforms/android-$NDK_PLATFORM_VERSION/arch-$NDK_ABI
NDK_UNAME=`uname -s | tr '[A-Z]' '[a-z]'` # Convert Linux -> linux
HOST=$NDK_ABI-linux-androideabi
NDK_TOOLCHAIN_BASE=$NDK_BASE/toolchains/$HOST-$NDK_COMPILER_VERSION/prebuilt/$NDK_UNAME-x86
CC="$NDK_TOOLCHAIN_BASE/bin/$HOST-gcc --sysroot=$NDK_SYSROOT"
LD=$NDK_TOOLCHAIN_BASE/bin/$HOST-ld

BUILD_PATH=build/ffmpeg

./configure \
$DEBUG_FLAG \
--arch=arm \
--target-os=linux \
--enable-runtime-cpudetect \
--enable-pic \
--disable-shared \
--enable-static \
--cross-prefix=$NDK_TOOLCHAIN_BASE/bin/$NDK_ABI-linux-androideabi- \
--sysroot="$NDK_SYSROOT" \
--extra-cflags="-march=armv7-a -mfloat-abi=softfp -fPIC -DANDROID" \
--extra-ldflags="" \
--enable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-network \
like image 865
Lior Iluz Avatar asked Sep 02 '14 12:09

Lior Iluz


1 Answers

After 2 days of compiling FFMPEG files that just didn't work, I finally succeeded!

In the above build.sh file, just add these 4 lines and the bottom to avoid the prebuilt/linux-x86/bin/arm-linux-androideabi-pkg-config not found, library detection may fail error.

Add to file:

$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install

Don't forget to chmod 775 ffmpeg file after the process is finished. Really hope this will help others!

If you want FFMPEG with libX264 support, use this project - just perfect. https://github.com/hiteshsondhi88/ffmpeg-android/

like image 151
Lior Iluz Avatar answered Oct 18 '22 20:10

Lior Iluz