Ffmpeg Android - Minimum binary size to convert WAV to MP3 - android

The only thing I want to do is convert wav files to mp3 inside my Android application.
I am currently using https://github.com/tanersener/mobile-ffmpeg and with audio-release everything is working fine. As the lib size is about 40 MB and I only need a single command, I'd like to build my own .aar file as described in the Wiki to reduce the application size.
I edited the android-ffmpeh.sh ./configure:
--disable-everything \
--enable-pthreads \
--enable-avcodec \
--enable-avformat \
--enable-swresample \
--enable-avfilter \
--enable-libmp3lame \
--enable-parser=mpegaudio \
--enable-demuxer=mp3,wav,pcm_s16le \
--enable-muxer=mp3,wav,pcm_s16le \
--enable-decoder=pcm*,mp3*,wav,pcm_s16le \
--enable-encoder=pcm*,pcm_s16le,wav,mp3,libmp3lame \
--enable-filter=aresample \
--enable-protocol=file \
and then ran ./android.sh -l --enable-lame --enable-libiconv
In my Android app FFmpeg loads but the conversion doesn't succed with following error:
E/mobile-ffmpeg: [AVFilterGraph # 0x7209dfec40] No such filter: 'anull'
E/mobile-ffmpeg: Error reinitializing filters!
E/mobile-ffmpeg: Failed to inject frame into filter network: Invalid argument
E/mobile-ffmpeg: Error while processing the decoded data for stream #0:0
I/mobile-ffmpeg: Conversion failed!
Does anyone know what I'm missing or another config to build a minimal size binary for this.
Any help is highly appreciated!

The ffmpeg tools can call upon the following filters automatically: aformat anull atrim format hflip null transpose trim vflip. configure is set to select them automatically unless overridden, which you have by declaring --disable-everything. So, these filters need to be manually enabled.

Related

How to use only 'concat' feature of ffmpeg and disable other components in Android?

I want to use ffmpeg library in my Android application to concatenate mp4 videos. After lots of research I choose ffmpeg-kit to work with ffmpeg. The problem is that the apk size with the library is large and I want to reduce it. As described here I have to disable unused components of ffmpeg, but I don't know what components I do need and what I don't. I started with adding these lines to ffmpeg.sh file of ffmpeg-kit but, it didn't work:
--disable-everything \
--enable-avcodec \
--enable-avformat \
--enable-ffmpeg \
I got the error below when executingffmpeg -f concat -safe 0 -i mp4_parts.txt -c copy output.mp4 command:
Unrecognized option 'safe'
I added those lines with no reason but to find out the right components that I need.
So my question is that what components do I need to enable for using the concat feature of ffmpeg? Thanks

Errors in building ffmpeg for android

I have followed lots of tutorials for buildinf ffmpeg.so file like
http://enoent.fr/blog/2014/06/20/compile-ffmpeg-for-android/
http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/
and many more tutorials but at last i have stuck to this error every time i dont know how to resolve it please any one knows how to solve it then help me
my build.sh file look like this
NDK=C:/Users/Benzatine/Downloads/android-ndk-r10e
SYSROOT=$NDK/platforms/android-19/arch-arm/
TOOLCHAIN=$NDK/toolchains//arm-linux-androideabi-4.8/prebuilt/windows-x86_64
function build_one
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
But when it executes make command it gives following error
LD libswscale/libswscale-3.so
c:/users/benzatine/downloads/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: libavutil/libavutil.so:1:1: syntax error, unexpected '!', expecting $end
c:/users/benzatine/downloads/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: libavutil/libavutil.so: not an object or archive
collect2.exe: error: ld returned 1 exit status
library.mak:111: recipe for target 'libswscale/libswscale-3.so' failed
make: *** [libswscale/libswscale-3.so] Error 1
every time i try to build ffmpeg this error occure how to resolve it please someone help me
I am going to assume that you are building it on Windows system based on the error message.
I just found this post on Facebook group so I am not going to take any credit for it.Bascially he just use other project and tweak it to make it work forcefully.It use Android 'Love' version and compile it in Windows system.
FFMpeg (https://www.ffmpeg.org), one of the most used libary written in C programming language for multimedia related task.
It has a lot of feature to add multimedia support for your application but the trouble being a 'C' library we have
port it into other language if you don't want to create your application in C/C++. Trust me porting it into
different language is a lot of work which are filled with error. Luckily you can find tutorial and easy build
script in the internet but unfountenly , they are only written by assumption that you are porting it
into nix based OS and the few tutorial on porting it on Windows OS does not work (atleast for me. :) )
But the main reason I am using ffmpeg is to add a multimedia feature to the android which are not
provided by standard Android API. I found some pre-made android project on an internet
which use FFMpeg 'Love' version. Here is the project.
In case you are wondering how to use it in your Android project , here are the step
1) Add a native support to the Android Project by right-clicking the Android Tools>Add Native Support...
2) Copy 'armeabi' folder to 'libs' folder of your project
3) Replace 'obj' folder with the 'obj' of ffmpeg project in the attached file
4) Add 'ffmpeg' folder to the 'jni' folder
5) Replace 'Androd.mk' folder with the 'Android.mk' of the ffmpeg project in the attached file
6) Write your code in C/C++ and enjoy
As always if you have any trouble or question you can comment them and I will answer them as soon as possible
Attached file:http://robot-mitya.googlecode.com/files/MyFfmpegTest.zip
Source:http://dmitrydzz-hobby.blogspot.com/2012/04/how-to-build-ffmpeg-and-use-it-in.html

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:
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)
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.
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 \
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/

Android and FFMpeg. How to add more codecs is build sh script

I built ffmpeg library for my Android project and now I want to add more codecs for my libs. I have build_android.sh script, where are defined encoders-decoders, muxers-demuxers, for example
--enable-decoder=flv \
--enable-encoder=flv \
--enable-demuxer=flv \
--enable-muxer=flv \
And I want to add there codecs for bink, avi, smacker and some others.
https://help.ubuntu.com/community/FFmpeg#Multiverse - here I have found list of codecs.
So, if I need to add for example smacker codec I need to put in my sh script following lines:
--enable-decoder=smackvid \
--enable-encoder=smackvid \
--enable-demuxer=smackvid \
--enable-muxer=smackvid\
And the same for all other codecs...
Am I right, or I am wrong? Thank You!

Building FFMPEG with librtmp for android

I'm trying to build all-in-one static binary of FFMPEG with NDK r7b and everything works fine untill i try to build it with RTMP support.
I'm usind sources from https://github.com/guardianproject/android-ffmpeg with librtmp2.4 and custom config like this
.configure \
--target-os=linux \
--cross-prefix=arm-linux-androideabi- \
--arch=arm \
--sysroot=/home/andrey/android-ndk-r7b/platforms/android-3/arch-arm \
--enable-static \
--disable-shared \
--disable-symver \
--enable-small \
--disable-devices \
--disable-avdevice \
--enable-gpl \
--enable-librtmp \
--prefix=../build/ffmpeg/armeabi \
--extra-cflags=-I../rtmpdump/librtmp \
--extra-ldflags=-L../rtmpdump/librtmp \
and rtmpdump directory lays on the same level as ffmpeg.
As i understand last two strings in my config says where compiler may find sources of librtmp.
But all i get is ERROR: librtmp not found
I'm not expereienced with NDK and obviosly i missing some important part but i can't find it by myself.
This is challenging, but I think I have a solution. The problem at configure-time is that FFmpeg wants to detect a proper librtmp installation via the pkg-config management system.
I'm assuming your have successfully cross-compiled librtmp in the directory referenced by ../rtmpdump. Edit the FFmpeg configure script and search for the line:
enabled librtmp && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
Comment that out (put a '#' at the front of the line). Now, re-run configure, only with these modifications:
--extra-cflags="-I/full/path/to/rtmpdump"
It may help to have an absolute path here. Also, omit /librtmp/ at the end since the #include directives already prefix the header files with librtmp/. Next:
--extra-ldflags="-L/full/path/to/rtmpdump -lrtmp"
Again, absolute path, and specify the library to link against since we commented out that logic via configure.
Now, configure should succeed and the cross-compilation should also be happy. The final ffmpeg binary should report the family of RTMP modules under protocols:
ffmpeg -protocols
[...]
rtmp
rtmpe
rtmps
rtmpt
rtmpte
Note that I don't have an NDK dev environment to test this on. But I tested on my desktop Ubuntu system by compiling librtmp (without the package being installed via pkg-config) and then performing the above steps.

Categories

Resources