The main problem is this:
FFMPEG is a binary, and there are no nice, user-friendly libraries that mimick it's behaviour out there...
One attempt is this: https://github.com/RkShaRkz/android-ffmpeg (the avatar gives me away)
Another one is this: https://sourceforge.net/projects/ffmpeg4android/files/20121012/
Alot of "solutions" revolve around either 1) launching the FFMPEG binary (process) and piping commands to it. 2) calling into FFMPEG libraries
But noone has yet made a nice FFMPEG-alike SDK library which lets you use everything it offers programatically in Java nor Android.
This was too long for a comment so thats why i posted it as an answer, i hope this doesn't get downvoted to oblivion for not providing a concrete answer/solution to your question.
Answer from Shark on Stack OverflowThe main problem is this:
FFMPEG is a binary, and there are no nice, user-friendly libraries that mimick it's behaviour out there...
One attempt is this: https://github.com/RkShaRkz/android-ffmpeg (the avatar gives me away)
Another one is this: https://sourceforge.net/projects/ffmpeg4android/files/20121012/
Alot of "solutions" revolve around either 1) launching the FFMPEG binary (process) and piping commands to it. 2) calling into FFMPEG libraries
But noone has yet made a nice FFMPEG-alike SDK library which lets you use everything it offers programatically in Java nor Android.
This was too long for a comment so thats why i posted it as an answer, i hope this doesn't get downvoted to oblivion for not providing a concrete answer/solution to your question.
i resolved it please follow this...
firstly go in File--->New-->Import module--> than Select FFMPEG Folder from your Computer. after that it will be added in same hierarchy of your Project, after again go into the File-->Project Structure-->app--> dependencies--> click on plus icon -->select 3).Module Dependencies Now in your list its been shown your Library select it
this solution is working for me if not solved than please tell me i can help you if possible
Videos
The latest version of FFMPEG is 3.1.1, Just released before 12 days. So i think there is no readily available demo like this old one.
We need to build the FFMPEG library on our own. Some questions i found just pasting here that might help you. (Not tested)
How to Build FFmpeg for Android
- Compiling FFmpeg 2.3 with Android NDK r10
- How to compile ffmpeg-2.5.3 on windows with android-ndk-r10d
- How to compile ffmpeg-2.2.2 on windows with cygwin and android ndk r9c
- How to buid ffmpeg with android-ndk-r10d in windows
You need to compile it on your own the by downloading Android NDK & Latest Version of FFMPEG.
One tutorial is also there : How to Build FFmpeg for Android. This is quite old so you just need to change the versions mentioned here. For FFMPEG it will be 3.1.1 & NDK it will be r12b.
Building FFMPEG with NDK r12b:
Download Android NDK : The latest version of Android NDK can be downloaded at Android NDK website. At the time of writing this answer, the newest version is NDK r12. simply decompress the archive
Download ffmpeg source code : FFMPEG source code can be downloaded from the ffmpeg website. The latest stable release is 3.1.1 (at the time of writing). Download the source code and decompress it to $NDK/sources folder.
Update configure file : Open ffmpeg-3.1.1/configure file with a text editor, and locate the following lines.
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)'This cause ffmpeg shared libraries to be compiled to libavcodec.so. (e.g. libavcodec.so.55), which is not compatible with Android build system. Therefore we’ll need to replace the above lines with the following lines.
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 ffmpeg : Copy the following text to a text editor and save it as build_android.sh in ffmpeg_3.1.1 folder.
#!/bin/bash NDK=$HOME/Desktop/adt/android-ndk-r9 SYSROOT=$NDK/platforms/android-9/arch-arm/ TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-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_oneOnce the file is saved, go to the directory where this file lies & execute the command below,
sudo chmod +x build_android.shThen execute the script by the command,
./build_android.shBuild Output : The build can take a while to finish depending on your computer speed. Once it’s done, you should be able to find a folder $NDK/sources/ffmpeg-3.1.1/android, which contains arm/lib and arm/include folders.
- Make ffmpeg Libraries available for Your Projects
Steps above are fully tested and i performed them on my machine and the build was successful. For writing this answer i have took the reference from this article How to Build ffmpeg with NDK r9 but as it was for older version i have made some corrections on my own.
Open for asking any doubts.
I suggest you these following URLs that was helpful for me :
http://androidwarzone.blogspot.in/2011/12/ffmpeg4android.html
http://writingminds.github.io/ffmpeg-android-java/
https://androiddeveloperhelp.wordpress.com/2015/12/19/video-editing-android-example/
For knowledge:
http://www.lai18.com/content/5175900.html
Android studio Source Code:
https://drive.google.com/file/d/0B9qAjo6wKhk9MEpNNjMxaG5oWXM/view?usp=sharing
It may be help you.
Here are the steps I went through in getting ffmpeg to work on Android:
- Build static libraries of ffmpeg for Android. This was achieved by building olvaffe's ffmpeg android port (libffmpeg) using the Android Build System. Simply place the sources under /external and
makeaway. You'll need to extract bionic(libc) and zlib(libz) from the Android build as well, as ffmpeg libraries depend on them. Create a dynamic library wrapping ffmpeg functionality using the Android NDK. There's a lot of documentation out there on how to work with the NDK. Basically you'll need to write some C/C++ code to export the functionality you need out of ffmpeg into a library java can interact with through JNI. The NDK allows you to easily link against the static libraries you've generated in step 1, just add a line similar to this to Android.mk:
LOCAL_STATIC_LIBRARIES := libavcodec libavformat libavutil libc libzUse the ffmpeg-wrapping dynamic library from your java sources. There's enough documentation on JNI out there, you should be fine.
Regarding using ffmpeg for playback, there are many examples (the ffmpeg binary itself is a good example), here's a basic tutorial. The best documentation can be found in the headers.
Good luck :)
For various reasons, Multimedia was and is never easy in terms of achieving the task without compromising on efficiency. ffmpeg is an effort in improving it day by day. It supports different formats of codecs and containers.
Now to answer the question of how to use this library, i would say that it is not so simple to write it here. But i can guide you in following ways.
1) Inside the ffmpeg directory of source code, you have output_example.c or api_example.c. Here, you can see the code where encoding/decoding is done. You will get an idea as to which API's inside ffmpeg you should call. This would be your first step.
2) Dolphin player is a open source project for Android. Currently it is having bugs but developers are working continuously. In that project you have the whole setup ready which you can use to continue your investigation. Here is a link to the project from code.google.com or run the command "git clone https://code.google.com/p/dolphin-player/" in a terminal. You can see two projects named P and P86 . You can use either of them.
Extra tip i would like to offer is that when you are building the ffmpeg code, inside build.sh you need to enable the muxers/demuxers/encoders/decoders of the formats you want to use. Else the corresponding code will not be included in the libraries. It took a lot of time for me to realize this. So thought of sharing it with you.
Few Basics : When we say a video file, ex : avi, it is combination of both audio and video
Video file = Video + Audio
Video = Codec + Muxer + Demuxer
codec = encoder + Decoder
=> Video = encoder + decoder + Muxer + Demuxer(Mpeg4 + Mpeg4 + avi +avi - Example for avi container)
Audio = Codec + Muxer + Demuxer
codec = encoder + Decoder
=> Audio = encoder + decoder + Muxer + Demuxer(mp2 + mp2 + avi + avi - Example for avi container)
Codec(name is deriverd from a combination of en*co*der/*dec*oder) is just a part of format which defines the algorithms used to encode/decode a frame. AVI is not a codec, it is a container which uses Video codec of Mpeg4 and Audio codec of mp2.
Muxer/demuxer is used to combine/separate the frames from a file used while encoding/decoding.
So if you want to use avi format, you need to enable Video components + Audio components.
Ex, for avi, you need to enable the following. mpeg4 Encoder, mpeg4 decoder, mp2 encoder, mp2 decoder, avi muxer, avi demuxer.
phewwwwwww...
Programmatically build.sh should contain the following code:
--enable-muxer=avi --enable-demuxer=avi (Generic for both audio/video. generally Specific to a container)
--enable-encoder=mpeg4 --enable-decoder=mpeg4(For video support)
--enable-encoder=mp2 --enable-decoder=mp2 (For Audio support)
Hope i idid not confuse you more after all this...
Thanks, Any assistance needed, please let me know.