Latest 3.1
Homepage https://github.com/tanersener/mobile-ffmpeg
License LGPL-3.0
Platforms ios 8.0, requires ARC
Authors

MobileFFmpeg Join the chat at https://gitter.im/mobile-ffmpeg/Lobby GitHub release Bintray CocoaPods

FFmpeg for Android and IOS

mobile-ffmpeg-full

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 and v4.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 and x86_64 architectures
  • Supports zlib and MediaCodec system libraries
  • Creates Android archive with .aar extension

1.2 IOS

  • Builds armv7, armv7s, arm64, i386 and x86_64 architectures
  • Supports bzip2, zlib system libraries and AudioToolbox, 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 and xvidcore are supported since v1.1

  • libaom and soxr are supported since v2.0

  • chromaprint, vid.stab and x265 are supported since v2.1

  • sdl, tesseract, twolame external libraries; zlib, MediaCodec Android system libraries; bzip2, zlib IOS system libraries and AudioToolbox, CoreImage, VideoToolbox, AVFoundation IOS system frameworks are supported since v3.0

2.1 Android

  1. Add MobileFFmpeg dependency from jcenter()

    dependencies {`
        implementation 'com.arthenica:mobile-ffmpeg-full:3.1'
    }
  2. Execute commands.

    import com.arthenica.mobileffmpeg.FFmpeg;
    
    FFmpeg.execute("-i file1.mp4 -c:v mpeg4 file2.mp4");
  3. 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));
    }
  4. Stop an ongoing operation.

    FFmpeg.cancel();
  5. Get media information for a file.

    MediaInformation info = FFmpeg.getMediaInformation('<file path or uri>');
  6. List enabled external libraries.

    List<String> externalLibraries = Config.getExternalLibraries();
  7. Enable log callback.

    Config.enableLogCallback(new LogCallback() {
        public void apply(LogMessage message) {
            Log.d(Config.TAG, message.getText());
        }
    });
  8. 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()));
        }
    });
  9. Set log level.

    Config.setLogLevel(Level.AV_LOG_FATAL);
  10. Register custom fonts directory.
    Config.setFontDirectory(this, "<folder with fonts>", Collections.EMPTY_MAP);

2.2 IOS

  1. Add MobileFFmpeg pod to your Podfile

    pod 'mobile-ffmpeg-full', '~> 3.1'
  2. Execute commands.

    #import <mobileffmpeg/MobileFFmpeg.h>
    
    [MobileFFmpeg execute: @"-i file1.mp4 -c:v mpeg4 file2.mp4"];
  3. 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);
    }
  4. Stop an ongoing operation.

    [MobileFFmpeg cancel];
  5. Get media information for a file.

    MediaInformation *mediaInformation = [MobileFFmpeg getMediaInformation:@"<file path or uri>"];
  6. 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];
  7. List enabled external libraries.

    NASArray *externalLibraries = [MobileFFmpegConfig getExternalLibraries];
  8. Enable log callback.

    - (void)logCallback: (int)level :(NSString*)message {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"%@", message);
        });
    }
    ...
    [MobileFFmpegConfig setLogDelegate:self];
  9. Enable statistics callback.

    - (void)statisticsCallback:(Statistics *)newStatistics {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"frame: %d, time: %dn", newStatistics.getVideoFrameNumber, newStatistics.getTime);
        });
    }
    ...
    [MobileFFmpegConfig setStatisticsDelegate:self];
  10. Set log level.

    [MobileFFmpegConfig setLogLevel:AV_LOG_FATAL];
  11. 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.

mobile-ffmpeg-full

3. Versions

  • MobileFFmpeg v1.x is the previous stable, includes FFmpeg v3.4.4

  • MobileFFmpeg v2.x is the current stable, includes FFmpeg v4.0.3

  • MobileFFmpeg v3.x is the next stable, includes FFmpeg v4.1-10

4. Building

4.1 Prerequisites

  1. 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.

  2. 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
  3. 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

mobile-ffmpeg-full

4.2.2 IOS
./ios.sh    

mobile-ffmpeg-full

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

Latest podspec

{
    "name": "mobile-ffmpeg-full",
    "version": "3.1",
    "summary": "Mobile FFmpeg Full Dynamic Framework",
    "description": "Includes FFmpeg v4.1-10 with chromaprint v1.4.3, fontconfig v2.13.1, freetype v2.9.1, fribidi v1.0.5, gmp v6.1.2, gnutls v3.5.19, kvazaar v1.2.0, lame v3.100, libaom v1.0.0-1014, libass v0.14.0, libiconv v1.15, libilbc v2.0.2, libtheora v1.1.1, libvorbis v1.3.6, libvpx v1.7.0, libwebp v1.0.1, libxml2 v2.9.8, opencore-amr v0.1.5, opus v1.3, sdl v2.0.8, shine v3.1.1, snappy v1.1.7, soxr v0.1.3, speex v1.2.0, tesseract v3.05.02, twolame v0.3.13 and wavpack v5.1.0 libraries enabled.",
    "homepage": "https://github.com/tanersener/mobile-ffmpeg",
    "authors": {
        "Taner Sener": "[email protected]"
    },
    "license": {
        "type": "LGPL-3.0",
        "file": "mobileffmpeg.framework/LICENSE"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "ios": {
        "frameworks": [
            "Foundation",
            "AudioToolbox",
            "CoreImage",
            "CoreMotion",
            "CoreVideo",
            "GameController",
            "VideoToolbox"
        ],
        "libraries": [
            "z",
            "bz2",
            "c++"
        ],
        "vendored_frameworks": [
            "mobileffmpeg.framework",
            "libavcodec.framework",
            "libavdevice.framework",
            "libavfilter.framework",
            "libavformat.framework",
            "libavutil.framework",
            "libswresample.framework",
            "libswscale.framework"
        ]
    },
    "source": {
        "http": "https://github.com/tanersener/mobile-ffmpeg/releases/download/v3.1/mobile-ffmpeg-full-3.1-ios-framework.zip"
    }
}

Pin It on Pinterest

Share This