ubantu-16+ndk-r14b compile ffmpeg-4.0.2+lame_mp3-3.99.5

1. Environment and software version

people-16.4.1

ndk-r14b

ffmpeg-4.0.2

lame_mp3-3.99.5

2. Nonsense

    Because I’m also a novice, I’m not familiar with linux, and not familiar with compiling. My favorite action is ethics and I don’t have a deep research, so I can’t guarantee that all the operations in this article are in place in one step. Besides, even if it doesn’t work, I can also provide you with ideas.

    According to the compilation steps of my previous blog (https://my.oschina.net/u/1462828/blog/1860847), the so file that runs on the Android platform can already be compiled, but the problem is that because of copyright Problem, so ffmpeg does not include an MP3 encoder, so we can only compile a lamemp3 into ffmpeg by ourselves.

    We can first try to compile a ffmpeg with MP3 that can be run directly under ubantu, it is very simple. First install lamemp3 (ubantu command: sudo apt-get install libmp3lame-dev), then download the ffmpeg source code and decompress it, then cd to the source directory, and run the trilogy of ubantu commands:

    1:./configure --enable-libmp3lame

    2:make

    3:make install

    After that, you can run ffmpeg -version directly, you can see the version information of ffmpeg, and then find some music, test the command: ffmpeg -i 1.wav 2.mp3

    If the command runs successfully and 2.MP3 is successfully generated, it proves that the MP3 encoder has been integrated successfully.

    Then, it's that simple?

    Obviously, it can't be that simple. If it's that simple, I don't need to write a special post.

    I used the script compiled in the previous blog, and added the sentence --enable-libmp3lame, and then ran the compilation, and kept getting an error:

 

    After finding ffbuild/config.log, the book of heaven... eating logs without understanding is always a bald thing...

    In the end, between the lines, some clues were found:

    

    Ever since, I suspected that ffmpeg did not locate the installed lameMP3 directory, so all Baidus found the phrase "apt-get install libmp3lame-dev". Obviously, this is not acceptable. As for the reason, I will Say.

    After that, there was a wave of various show operations, and in the middle of despair, I put down the keyboard, picked up the phone and played a few chicken games.

    Come again after your mind is sober, and finally locate the key to the problem:

    

    -cflags is to locate the include directory, prefixed with -I (uppercase i), ldflags is to locate the lib directory, prefixed with -L

    

    In theory, this is the case, but I changed seven, four, four, nine opening methods and nine, nine, eighty-one command postures, and both returned a cold sentence:

    ERROR: libmp3lame >= 3.98.3 not found

    Helplessly, the posts on the Internet are basically h264+aac. The group of people who do live broadcasts don’t need mp3 anymore, so they can only find a ffmpeg group, which is not very active, and there is still a great god resident. Yes, although the great god did not provide the most direct help, he also gave an idea, which is to compile lamemp3 with ndk.

    This means that since ndk is used to compile ffmpeg, does the lame that need to be imported also need to be compiled with ndk.

    Said it was just... But how to compile lamemp3 with ndk? The script that directly applies ffmpeg doesn't seem to work. There is no crpss-prefix and other tags on the path.

    Let’s go to Baidu. I can’t help it. After searching for a long time, I didn’t have a clue. Later, my inspiration flashed. Isn’t ffmpeg+h264+aac the same? So I found a post, and then I got the script to compile aac, and changed it a lot. After seven or seventy-nine opening methods and nine-nine-eighty-one different postures, the compilation was finally successful.

    Then I changed the -cflags label of ffmpeg. I felt infinite longing and hope in my heart. I felt that the world was full of friendship and harmony. The only thing that was more dazzling was the red, cold code:

    

    ……

    After checking the process again, it turned out that the path of cflags and ldflags was missing one layer, which was a false alarm.

    After the compilation is complete, copy the so package, and test it on a real Mi 6 machine, no problem.

    Sure enough, the world is still friendly and harmonious.

3. The compilation process

1. Source code download

    lamemp3:http://lame.sourceforge.net/download.php

    ffmpeg:http://ffmpeg.org/

    ndk:https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip 

    Remember to download in the ubantu environment. The software decompression directory on my side is:

    lamemp3: /home/xiaoyu/lame-3.99.5

    ndk: / home / xiaoyu / ndk

    ffmpeg:    /home/xiaoyu/ffmpeg/ffmpeg-4.2.0/

    Still can't help but complain about the version of lame, the latest version is 3.100, the previous version is 3.99.5, and ffmpeg supports above 3.98.3. When I installed and downloaded 3.100 at the beginning, it shows that it is the latest version. This latest version is 3.1. Why does ffmpeg want 3.9? Later I found it online and downloaded 3.99.5. Now I look back. , What the fuck, 3.1, which is clearly 3.100...

2. Compile lamemp3

    Download, unzip, slightly...

    Then execute the compiled script build.sh

#!/bin/bash
NDK_HOME=/home/xiaoyu/ndk/android-ndk-r14b
ANDROID_API=android-21
SYSROOT=$NDK_HOME/platforms/$ANDROID_API/arch-arm
ANDROID_BIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/
CROSS_COMPILE=${ANDROID_BIN}/arm-linux-androideabi-
export PATH=$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
 
ARM_INC=$SYSROOT/usr/include
ARM_LIB=$SYSROOT/usr/lib
 
LDFLAGS=" -nostdlib -Bdynamic -Wl,--whole-archive -Wl,--no-undefined -Wl,-z,noexecstack  -Wl,-z,nocopyreloc -Wl,-soname,/system/lib/libz.so -Wl,-rpath-link=$ARM_LIB,-dynamic-linker=/system/bin/linker -L$NDK_HOME/sources/cxx-stl/gnu-libstdc++/libs/armeabi -L$NDK_HOME/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/arm-linux-androideabi/lib -L$ARM_LIB  -lc -lgcc -lm -ldl  "
 
FLAGS="--host=arm-linux --enable-static --disable-shared"
 
export CXX="${CROSS_COMPILE}g++ --sysroot=${SYSROOT}"
export LDFLAGS="$LDFLAGS"
export CC="${CROSS_COMPILE}gcc --sysroot=${SYSROOT}"
CPU=armv7-a
 
./configure $FLAGS \
--prefix=$(pwd)/android/$CPU

    cd to the lame-3.99.5 directory

    chmod +x build.sh

    ./build.sh

    make  

    make install

    After the compilation is complete, you will see an android/armv7-a directory in the lame-3.99.5 directory

    

    Inside is what we need.

2. Compile ffmpeg

    The build.sh script is basically the same as the previous blog, except that a sentence of --enbale-libmp3lame is added and the cflags and ldfags tags are modified

#!/bin/bash
NDK=/home/xiaoyu/ndk/android-ndk-r14b
SYSROOT=$NDK/platforms/android-21/arch-arm/
CPU=armv7-a
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "

function build_android
{
./configure \
--prefix=$PREFIX \
--enable-neon \
--enable-hwaccels \
--enable-shared \
--enable-libmp3lame \
--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=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=android \
--arch=arm \
--cpu=armv7-a \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
}
ADDI_CFLAGS="-I/home/xiaoyu/lame/include"
ADDI_LDFLAGS="-L/home/xiaoyu/llame/lib"
build_android

    Old rules, cd to the ffmpeg-4.0.2 directory

    chmod +x build.sh

    ./build.sh

    make

    make install

    After completion, an android/armv7-a directory will be found in the ffmpeg-4.0.2 directory

    

    At this point, you're done, do it yourself, I won't send out the compiled.

Guess you like

Origin blog.csdn.net/jiabailong/article/details/105229805