MobileFFmpeg

适用于 Android、iOS 和 tvOS 的 FFmpeg。不再维护。被 FFmpegKit 所取代。「FFmpeg for Android, iOS and tvOS. Not maintained anymore. Superseded by FFmpegKit.」

Github stars Tracking Chart

MobileFFmpeg Financial Contributors on Open Collective GitHub release Bintray CocoaPods Build Status

FFmpeg for Android, iOS and tvOS

1. Features

  • Includes both FFmpeg and FFprobe

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

  • Supports

    • Android, iOS and tvOS

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

    • 28 external libraries

      chromaprint, fontconfig, freetype, fribidi, gmp, gnutls, kvazaar, lame, libaom, libass, libiconv, libilbc, libtheora, libvorbis, libvpx, libwebp, libxml2, opencore-amr, openh264, opus, sdl, shine, snappy, soxr, speex, tesseract, twolame, wavpack

    • 4 external libraries with GPL license

      vid.stab, x264, x265, xvidcore

    • Concurrent execution

  • Exposes both FFmpeg library and MobileFFmpeg wrapper library capabilities

  • Includes cross-compile instructions for 44 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, openh264, 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
  • Camera access on supported devices
  • Builds shared native libraries (.so)
  • Creates Android archive with .aar extension
  • Supports API Level 16+

1.2 iOS

  • Builds armv7, armv7s, arm64, arm64e, i386 and x86_64 architectures
  • Supports bzip2, zlib, iconv system libraries and AudioToolbox, CoreImage, VideoToolbox, AVFoundation system frameworks
  • Objective-C API
  • Camera access
  • ARC enabled library
  • Built with -fembed-bitcode flag
  • Creates static framework and static universal (fat) library (.a)
  • Supports iOS SDK 9.3 or later

1.3 tvOS

  • Builds arm64 and x86_64 architectures
  • Supports bzip2, zlib, iconv system libraries and AudioToolbox, CoreImage, VideoToolbox system frameworks
  • Objective-C API
  • ARC enabled library
  • Built with -fembed-bitcode flag
  • Creates static framework and static universal (fat) library (.a)
  • Supports tvOS SDK 9.2 or later

2. Using

Published binaries are available at Github, JCenter and CocoaPods.

There are eight different mobile-ffmpeg packages. Below you can see which system libraries and external libraries are enabled in each of them.

Please remember that some parts of FFmpeg are licensed under the GPL and only GPL licensed mobile-ffmpeg packages include them.

  • 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

  • Since v4.2, chromaprint, sdl and tesseract libraries are not included in binary releases. You can still build them and include in your releases

  • AVFoundation is not available on tvOS, VideoToolbox is not available on tvOS LTS releases

  • Since v4.3.1, iOS and tvOS releases started to use iconv system library instead of iconv external library

2.1 Android

  1. Add MobileFFmpeg dependency to your build.gradle in mobile-ffmpeg-<package name> format

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

    import com.arthenica.mobileffmpeg.Config;
    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 and the output below.", rc));
        Config.printLastCommandOutput(Log.INFO);
    }
    
  3. Execute FFprobe commands.

    import com.arthenica.mobileffmpeg.Config;
    import com.arthenica.mobileffmpeg.FFprobe;
    
    int rc = FFprobe.execute("-i file1.mp4");
    
    if (rc == RETURN_CODE_SUCCESS) {
        Log.i(Config.TAG, "Command execution completed successfully.");
    } else {
        Log.i(Config.TAG, String.format("Command execution failed with rc=%d and the output below.", rc));
        Config.printLastCommandOutput(Log.INFO);
    }
    
  4. Check execution output later.

    int rc = Config.getLastReturnCode();
    
    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 the output below.", rc));
        Config.printLastCommandOutput(Log.INFO);
    }
    
  5. Stop an ongoing FFmpeg operation.

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

    MediaInformation info = FFprobe.getMediaInformation("<file path or uri>");
    
  7. Record video using Android camera.

    FFmpeg.execute("-f android_camera -i 0:0 -r 30 -pixel_format bgr0 -t 00:00:05 <record file path>");
    
  8. List enabled external libraries.

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

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

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

    Config.setFontDirectory(this, "<folder with fonts>", Collections.EMPTY_MAP);
    

2.2 iOS / tvOS

  1. Add MobileFFmpeg dependency to your Podfile in mobile-ffmpeg-<package name> format

    • iOS
    pod 'mobile-ffmpeg-full', '~> 4.3.1'
    
    • tvOS
    pod 'mobile-ffmpeg-tvos-full', '~> 4.3.1'
    
  2. Execute FFmpeg commands.

    #import <mobileffmpeg/MobileFFmpegConfig.h>
    #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 and output=%@.\n", rc, [MobileFFmpegConfig getLastCommandOutput]);
    }
    
  3. Execute FFprobe commands.

    #import <mobileffmpeg/MobileFFmpegConfig.h>
    #import <mobileffmpeg/MobileFFprobe.h>
    
    int rc = [MobileFFprobe execute: @"-i file1.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 and output=%@.\n", rc, [MobileFFmpegConfig getLastCommandOutput]);
    }
    
  4. Check execution output later.

    int rc = [MobileFFmpegConfig getLastReturnCode];
    NSString *output = [MobileFFmpegConfig 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);
    }
    
  5. Stop an ongoing FFmpeg operation.

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

    MediaInformation *mediaInformation = [MobileFFprobe getMediaInformation:@"<file path or uri>"];
    
  7. Record video and audio using iOS camera. This operation is not supported on tvOS since AVFoundation is not available on tvOS.

    [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];
    
  8. List enabled external libraries.

    NSArray *externalLibraries = [MobileFFmpegConfig getExternalLibraries];
    
  9. Enable log callback.

    [MobileFFmpegConfig setLogDelegate:self];
    
    - (void)logCallback: (int)level :(NSString*)message {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"%@", message);
        });
    }
    
  10. 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);
        });
    }
    
  11. Set log level.

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

    [MobileFFmpegConfig setFontDirectory:@"<folder with fonts>" with:nil];
    

2.3 Manual Installation

2.3.1 Android

You can import MobileFFmpeg aar packages in Android Studio using the File -> New -> New Module -> Import .JAR/.AAR Package menu.

2.3.2 iOS / tvOS

iOS and tvOS frameworks can be installed manually using the Importing Frameworks guide.
If you want to use universal binaries please refer to Using Universal Binaries guide.

2.4 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, an iOS test application under the
ios/test-app folder and a tvOS test application under the tvos/test-app folder.

All applications are identical and supports command execution, video encoding, accessing https, encoding audio,
burning subtitles, video stabilization and pipe operations.

3. Versions

MobileFFmpeg version number is aligned with FFmpeg since version 4.2.

In previous versions, MobileFFmpeg version of a release and FFmpeg version included in that release was different.
The following table lists FFmpeg versions used in MobileFFmpeg releases.

  • dev part in FFmpeg version number indicates that FFmpeg source is pulled from the FFmpeg master branch.
    Exact version number is obtained using git describe --tags.

Main metrics

Overview
Name With Ownertanersener/mobile-ffmpeg
Primary LanguageC
Program languageShell (Language Count: 53)
PlatformAndroid, iOS, tvOS
License:GNU General Public License v3.0
所有者活动
Created At2018-02-27 13:49:45
Pushed At2025-01-06 18:33:05
Last Commit At2021-10-07 09:42:47
Release Count24
Last Release Namev4.4 (Posted on )
First Release Namev1.0 (Posted on )
用户参与
Stargazers Count4k
Watchers Count107
Fork Count864
Commits Count831
Has Issues Enabled
Issues Count664
Issue Open Count0
Pull Requests Count36
Pull Requests Open Count0
Pull Requests Close Count16
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private