GitHub - tanersener/mobile-ffmpeg: FFmpeg for Android and IOS
source link: https://github.com/tanersener/mobile-ffmpeg
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
MobileFFmpeg
FFmpeg for Android and IOS
1. Features
-
Use binaries available at
Github
/JCenter
/CocoaPods
or build your own version with external libraries you need -
Supports
-
Both Android and IOS
-
FFmpeg
v3.4.x
,v4.0.x
andv4.1
releases -
27 external libraries
chromaprint
,fontconfig
,freetype
,fribidi
,gmp
,gnutls
,kvazaar
,lame
,libaom
,libass
,libiconv
,libilbc
,libtheora
,libvorbis
,libvpx
,libwebp
,libxml2
,opencore-amr
,opus
,sdl
,shine
,snappy
,soxr
,speex
,tesseract
,twolame
,wavpack
-
4 external libraries with GPL license
vid.stab
,x264
,x265
,xvidcore
-
-
Exposes both FFmpeg library and MobileFFmpeg wrapper library capabilities
-
Creates shared libraries (.so for Android, .dylib for IOS)
-
Includes cross-compile instructions for 43 open-source libraries
chromaprint
,expat
,ffmpeg
,fontconfig
,freetype
,fribidi
,giflib
,gmp
,gnutls
,kvazaar
,lame
,leptonica
,libaom
,libass
,libiconv
,libilbc
,libjpeg
,libjpeg-turbo
,libogg
,libpng
,libsndfile
,libtheora
,libuuid
,libvorbis
,libvpx
,libwebp
,libxml2
,nettle
,opencore-amr
,opus
,sdl
,shine
,snappy
,soxr
,speex
,tesseract
,tiff
,twolame
,vid.stab
,wavpack
,x264
,x265
,xvidcore
-
Licensed under LGPL 3.0, can be customized to support GPL v3.0
1.1 Android
- Builds
arm-v7a
,arm-v7a-neon
,arm64-v8a
,x86
andx86_64
architectures - Supports
zlib
andMediaCodec
system libraries - Creates Android archive with .aar extension
1.2 IOS
- Builds
armv7
,armv7s
,arm64
,i386
andx86_64
architectures - Supports
bzip2
,zlib
system libraries andAudioToolbox
,CoreImage
,VideoToolbox
,AVFoundation
system frameworks - Camera and microphone access
ARC
enabled library- Built with
-fembed-bitcode
flag - Creates IOS shared/dynamic universal (fat) library
- Creates IOS static universal (fat) library
- Creates IOS dynamic framework for IOS 8 or later
- Supports Xcode 7.3.1 or later
2. Using
Binaries are available at Github, JCenter and CocoaPods.
Refer to Using IOS Universal Binaries guide to import IOS universal binaries released at Github.
There are eight different binary packages. Below you can see which system libraries and external libraries are enabled in each of them.
min
min-gpl
https
https-gpl
audio
video
full
full-gpl
external libraries
-
vid.stab
x264
x265
xvidcore
gmp
gnutls
gmp
gnutls
vid.stab
x264
x265
xvidcore
chromaprint
lame
libilbc
libvorbis
opencore-amr
opus
shine
soxr
speex
twolame
wavpack
fontconfig
freetype
fribidi
kvazaar
libaom
libass
libiconv
libtheora
libvpx
libwebp
snappy
chromaprint
fontconfig
freetype
fribidi
gmp
gnutls
kvazaar
lame
libaom
libass
libiconv
libilbc
libtheora
libvorbis
libvpx
libwebp
libxml2
opencore-amr
opus
sdl
shine
snappy
soxr
speex
tesseract
twolame
wavpack
chromaprint
fontconfig
freetype
fribidi
gmp
gnutls
kvazaar
lame
libaom
libass
libiconv
libilbc
libtheora
libvorbis
libvpx
libwebp
libxml2
opencore-amr
opus
sdl
shine
snappy
soxr
speex
tesseract
twolame
vid.stab
wavpack
x264
x265
xvidcore
android system libraries
zlib
MediaCodec
ios system libraries
zlib
AudioToolbox
AVFoundation
CoreImage
VideoToolbox
bzip2
-
libilbc
,opus
,snappy
,x264
andxvidcore
are supported sincev1.1
-
libaom
andsoxr
are supported sincev2.0
-
chromaprint
,vid.stab
andx265
are supported sincev2.1
-
sdl
,tesseract
,twolame
external libraries;zlib
,MediaCodec
Android system libraries;bzip2
,zlib
IOS system libraries andAudioToolbox
,CoreImage
,VideoToolbox
,AVFoundation
IOS system frameworks are supported sincev3.0
2.1 Android
-
Add MobileFFmpeg dependency from
jcenter()
dependencies {` implementation 'com.arthenica:mobile-ffmpeg-full:3.1' }
-
Execute commands.
import com.arthenica.mobileffmpeg.FFmpeg; FFmpeg.execute("-i file1.mp4 -c:v mpeg4 file2.mp4");
-
Check execution output.
int rc = FFmpeg.getLastReturnCode(); String output = FFmpeg.getLastCommandOutput(); if (rc == RETURN_CODE_SUCCESS) { Log.i(Config.TAG, "Command execution completed successfully."); } else if (rc == RETURN_CODE_CANCEL) { Log.i(Config.TAG, "Command execution cancelled by user."); } else { Log.i(Config.TAG, String.format("Command execution failed with rc=%d and output=%s.", rc, output)); }
-
Stop an ongoing operation.
FFmpeg.cancel();
-
Get media information for a file.
MediaInformation info = FFmpeg.getMediaInformation('<file path or uri>');
-
List enabled external libraries.
List<String> externalLibraries = Config.getExternalLibraries();
-
Enable log callback.
Config.enableLogCallback(new LogCallback() { public void apply(LogMessage message) { Log.d(Config.TAG, message.getText()); } });
-
Enable statistics callback.
Config.enableStatisticsCallback(new StatisticsCallback() { public void apply(Statistics newStatistics) { Log.d(Config.TAG, String.format("frame: %d, time: %d", newStatistics.getVideoFrameNumber(), newStatistics.getTime())); } });
-
Set log level.
Config.setLogLevel(Level.AV_LOG_FATAL);
-
Register custom fonts directory.
Config.setFontDirectory(this, "<folder with fonts>", Collections.EMPTY_MAP);
2.2 IOS
-
Add MobileFFmpeg pod to your
Podfile
pod 'mobile-ffmpeg-full', '~> 3.1'
-
Execute commands.
#import <mobileffmpeg/MobileFFmpeg.h> [MobileFFmpeg execute: @"-i file1.mp4 -c:v mpeg4 file2.mp4"];
-
Check execution output.
int rc = [MobileFFmpeg getLastReturnCode]; NSString *output = [MobileFFmpeg getLastCommandOutput]; if (rc == RETURN_CODE_SUCCESS) { NSLog(@"Command execution completed successfully.\n"); } else if (rc == RETURN_CODE_CANCEL) { NSLog(@"Command execution cancelled by user.\n"); } else { NSLog(@"Command execution failed with rc=%d and output=%@.\n", rc, output); }
-
Stop an ongoing operation.
[MobileFFmpeg cancel];
-
Get media information for a file.
MediaInformation *mediaInformation = [MobileFFmpeg getMediaInformation:@"<file path or uri>"];
-
Record video and audio using IOS camera
[MobileFFmpeg execute: @"-f avfoundation -r 30 -video_size 1280x720 -pixel_format bgr0 -i 0:0 -vcodec h264_videotoolbox -vsync 2 -f h264 -t 00:00:05 %@", recordFilePath];
-
List enabled external libraries.
NSArray *externalLibraries = [MobileFFmpegConfig getExternalLibraries];
-
Enable log callback.
[MobileFFmpegConfig setLogDelegate:self]; - (void)logCallback: (int)level :(NSString*)message { dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"%@", message); }); }
-
Enable statistics callback.
[MobileFFmpegConfig setStatisticsDelegate:self]; - (void)statisticsCallback:(Statistics *)newStatistics { dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"frame: %d, time: %d\n", newStatistics.getVideoFrameNumber, newStatistics.getTime); }); }
-
Set log level.
[MobileFFmpegConfig setLogLevel:AV_LOG_FATAL];
-
Register custom fonts directory.
[MobileFFmpegConfig setFontDirectory:@"<folder with fonts>" with:nil];
2.3 Test Application
You can see how MobileFFmpeg is used inside an application by running test applications provided.
There is an Android test application under the android/test-app
folder and an IOS test application, which requires
Xcode 9.x
or later, under the ios/test-app
folder. Both applications are identical and supports command
execution, video encoding, accessing https, encoding audio, burning subtitles and video stabilization.
3. Versions
-
MobileFFmpeg v1.x
is the previous stable, includesFFmpeg v3.4.4
-
MobileFFmpeg v2.x
is the current stable, includesFFmpeg v4.0.3
-
MobileFFmpeg v3.x
is the next stable, includesFFmpeg v4.1-10
4. Building
4.1 Prerequisites
-
Use your package manager (apt, yum, dnf, brew, etc.) to install the following packages.
autoconf automake libtool pkg-config curl cmake gcc gperf texinfo yasm nasm bison autogen patch
Some of these packages are not mandatory for the default build. Please visit Android Prerequisites and IOS Prerequisites for the details.
-
Android builds require these additional packages.
- Android SDK 5.0 Lollipop (API Level 21) or later
- Android NDK r17c or later with LLDB and CMake
-
IOS builds need these extra packages and tools.
- IOS SDK 8.0.x or later
- Xcode 7.3.1 or later
- Command Line Tools
4.2 Build Scripts
Use android.sh
and ios.sh
to build MobileFFmpeg for each platform.
After a successful build, compiled FFmpeg and MobileFFmpeg libraries can be found under prebuilt
directory.
Both android.sh
and ios.sh
can be customized to override default settings,
android.sh and
ios.sh wiki pages include all available build options.
4.2.1 Android
export ANDROID_NDK_ROOT=<Android NDK Path>
./android.sh
4.2.2 IOS
./ios.sh
4.3 GPL Support
It is possible to enable GPL licensed libraries x264
, xvidcore
since v1.1
and vid.stab
, x265
since v2.1
from the top level build scripts.
Their source code is not included in the repository and downloaded when enabled.
4.4 External Libraries
build
directory includes build scripts for external libraries. There are two scripts for each library, one for Android
and one for IOS. They include all options/flags used to cross-compile the libraries. ASM
is enabled by most of them,
exceptions are listed under the ASM Support page.
5. Documentation
A more detailed documentation is available at Wiki.
6. License
This project is licensed under the LGPL v3.0. However, if source code is built using optional --enable-gpl
flag or
prebuilt binaries with -gpl
postfix are used then MobileFFmpeg is subject to the GPL v3.0 license.
Source code of FFmpeg and external libraries is included in compliance with their individual licenses.
strip-frameworks.sh
script included and distributed is published under the Apache License version 2.0.
In test applications, fonts embedded are licensed under the SIL Open Font License; other digital assets are published in the public domain.
Please visit License page for the details.
7. Contributing
If you have any recommendations or ideas to improve it, please feel free to submit issues or pull requests. Any help is appreciated.
8. See Also
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK