Files
mobile-ffmpeg/docs/index.md
T
2018-10-16 00:41:55 +03:00

9.7 KiB

layout
layout
default

FFmpeg for Android and IOS

1. Features

  • Supports FFmpeg v3.4.x, v4.0.x and v4.1-dev releases

  • Use prebuilt binaries available under Github/JCenter/CocoaPods or build your own version with external libraries you need

  • Includes 27 external libraries, 4 GPL libraries and 10 architectures in total

  • Exposes FFmpeg capabilities both directly from FFmpeg libraries and through MobileFFmpeg wrapper library

  • 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, sdl2, shine, snappy, soxr, speex, tesseract, tiff, twolame, vid.stab, wavpack, x264, x265, xvidcore

  • Prebuilt binaries under Github, JCenter and CocoaPods

  • Supports arm-v7a, arm-v7a-neon, arm64-v8a, x86 and x86_64 Android architectures

  • Creates Android archive with .aar extension

  • Supports armv7, armv7s, arm64, i386 and x86_64 IOS architectures

  • ARC enabled library

  • Built with -fembed-bitcode flag

  • Creates IOS dynamic universal (fat) library

  • Creates IOS dynamic framework for IOS 8 or later

  • Licensed under LGPL 3.0, can be customized to support GPL v3.0

2. Using

Prebuilt libraries are available under Github, JCenter and CocoaPods

There are eight different prebuilt packages. Below you can see which external libraries are enabled in each of them.

min min-gpl https https-gpl audio video full full-gpl
- vid.stab3
x2641
x2653
xvidcore1
gnutls gnutls
vid.stab3
x2641
x2653
xvidcore1
chromaprint3
lame
libilbc1
libvorbis
opencore-amr
opus1
shine
soxr2
speex
twolame4
wavpack
fontconfig
freetype
fribidi
kvazaar
libaom2
libass
libiconv
libtheora
libvpx
snappy1
tesseract4
chromaprint3
fontconfig
freetype
fribidi
gmp
gnutls
kvazaar
lame
libaom2
libass
libiconv
libilbc1
libtheora
libvorbis
libvpx
libwebp
libxml2
opencore-amr
opus1
sdl24
shine
snappy1
soxr2
speex
tesseract4
twolame4
wavpack
chromaprint3
fontconfig
freetype
fribidi
gmp
gnutls
kvazaar
lame
libaom2
libass
libiconv
libilbc1
libtheora
libvorbis
libvpx
libwebp
libxml2
opencore-amr
opus1
sdl24
shine
snappy1
soxr2
speex
tesseract4
twolame4
vid.stab3
wavpack
x2641
x2653
xvidcore1

1 - Supported since v1.1

2 - Supported since v2.0

3 - Supported since v2.1

4 - Supported since v3.0

2.1 Android

  1. Add MobileFFmpeg dependency from jcenter()

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

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

    FFmpeg.cancel();
    
  4. Enable log callback.

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

    Config.setLogLevel(Level.AV_LOG_FATAL);
    
  7. Register custom fonts directory.

    Config.setFontDirectory(this, "fonts", Collections.EMPTY_MAP);
    

2.2 IOS

  1. Add MobileFFmpeg pod to your Podfile

    pod 'mobile-ffmpeg-full', '~> 3.0'
    
  2. Create and execute commands.

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

    [MobileFFmpeg cancel];
    
  4. Enable log callback.

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

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

    [MobileFFmpegConfig setLogLevel:AV_LOG_FATAL];
    
  7. Register custom fonts directory.

    [MobileFFmpegConfig setFontDirectory:@"fonts" with:nil];
    

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

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

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
    
  2. Android builds require these additional packages.

    • Android SDK 5.0 Lollipop (API Level 21) or later
    • Android NDK r16b or later with LLDB and CMake
    • gradle 4.4 or later
  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.

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.

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. See Also