tanersener/mobile-ffmpeg

★ 4,141⑂ 0

FFmpeg for Android, iOS and tvOS. Not maintained anymore. Superseded by FFmpegKit.

4,141Star
0Fork
0Watch
0Issue
CLanguage
-License
Created · last push · repository size 0 KB · default branch -

README

MobileFFmpeg Financial Contributors on Open Collective GitHub release Maven Central CocoaPods Build Status

FFmpeg for Android, iOS and tvOS.

Not maintained anymore as explained in What’s next for MobileFFmpeg?. Superseded by FFmpegKit.

1. Features

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, vo-amrwbenc, wavpack rubberband, vid.stab, x264, x265, xvidcore chromaprint, expat, ffmpeg, fontconfig, freetype, fribidi, giflib, gmp, gnutls, kvazaar, lame, leptonica, libaom, libass, libiconv, libilbc, libjpeg, libjpeg-turbo, libogg, libpng, libsamplerate, libsndfile, libtheora, libuuid, libvorbis, libvpx, libwebp, libxml2, nettle, opencore-amr, openh264, opus, rubberband, sdl, shine, snappy, soxr, speex, tesseract, tiff, twolame, vid.stab, vo-amrwbenc, wavpack, x264, x265, xvidcore

1.1 Android

1.2 iOS

1.3 tvOS

2. Using

Prebuilt binaries are available at Github, Maven Central and CocoaPods.

2.1 Packages

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.

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
lame
libilbc
libvorbis
opencore-amr
opus
shine
soxr
speex
twolame
vo-amrwbenc
wavpack
fontconfig
freetype
fribidi
kvazaar
libaom
libass
libiconv
libtheora
libvpx
libwebp
snappy
fontconfig
freetype
fribidi
gmp
gnutls
kvazaar
lame
libaom
libass
libiconv
libilbc
libtheora
libvorbis
libvpx
libwebp
libxml2
opencore-amr
opus
shine
snappy
soxr
speex
twolame
vo-amrwbenc
wavpack
fontconfig
freetype
fribidi
gmp
gnutls
kvazaar
lame
libaom
libass
libiconv
libilbc
libtheora
libvorbis
libvpx
libwebp
libxml2
opencore-amr
opus
shine
snappy
soxr
speex
twolame
vid.stab
vo-amrwbenc
wavpack
x264
x265
xvidcore
android system libraries zlib
MediaCodec
ios system libraries zlib
AudioToolbox
AVFoundation
iconv
VideoToolbox
bzip2
tvos system libraries zlib
AudioToolbox
iconv
VideoToolbox
bzip2

2.2 Android

before jcenter()
    repositories {
        mavenCentral()
    }
    

1. Add MobileFFmpeg dependency to your build.gradle in mobile-ffmpeg- pattern.

    dependencies {
        implementation 'com.arthenica:mobile-ffmpeg-full:4.4'
    }
    

2. Execute synchronous 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 asynchronous FFmpeg commands.

    import com.arthenica.mobileffmpeg.Config;
    import com.arthenica.mobileffmpeg.FFmpeg;

long executionId = FFmpeg.executeAsync("-i file1.mp4 -c:v mpeg4 file2.mp4", new ExecuteCallback() {

@Override public void apply(final long executionId, final int returnCode) { if (returnCode == RETURN_CODE_SUCCESS) { Log.i(Config.TAG, "Async command execution completed successfully."); } else if (returnCode == RETURN_CODE_CANCEL) { Log.i(Config.TAG, "Async command execution cancelled by user."); } else { Log.i(Config.TAG, String.format("Async command execution failed with returnCode=%d.", returnCode)); } } });

4. 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); }

5. 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);
    }
    

6. Stop ongoing FFmpeg operations.

        FFmpeg.cancel();
        
        FFmpeg.cancel(executionId);
        

7. Get media information for a file.

    MediaInformation info = FFprobe.getMediaInformation("");
    

8. Record video using Android camera.

    FFmpeg.execute("-f android_camera -i 0:0 -r 30 -pixel_format bgr0 -t 00:00:05 ");
    

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. Ignore the handling of a signal.
    Config.ignoreSignal(Signal.SIGXCPU);
    

12. List ongoing executions.

    final List ffmpegExecutions = FFmpeg.listExecutions();
    for (int i = 0; i < ffmpegExecutions.size(); i++) {
        FFmpegExecution execution = ffmpegExecutions.get(i);
        Log.d(TAG, String.format("Execution %d = id:%d, startTime:%s, command:%s.", i, execution.getExecutionId(), execution.getStartTime(), execution.getCommand()));
    }
    

13. Set default log level.

    Config.setLogLevel(Level.AV_LOG_FATAL);
    

14. Register custom fonts directory.

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

2.3 iOS / tvOS

1. Add MobileFFmpeg dependency to your Podfile in mobile-ffmpeg- pattern.
    pod 'mobile-ffmpeg-full', '~> 4.4'
    
    pod 'mobile-ffmpeg-tvos-full', '~> 4.4'
    

2. Execute synchronous FFmpeg commands.

    #import 
    #import

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 asynchronous FFmpeg commands.

    #import 
    #import

long executionId = [MobileFFmpeg executeAsync:@"-i file1.mp4 -c:v mpeg4 file2.mp4" withCallback:self];

  • (void)executeCallback:(long)executionId :(int)returnCode {
if (rc == RETURN_CODE_SUCCESS) { NSLog(@"Async command execution completed successfully.\n"); } else if (rc == RETURN_CODE_CANCEL) { NSLog(@"Async command execution cancelled by user.\n"); } else { NSLog(@"Async command execution failed with rc=%d.\n", rc); } }

4. Execute FFprobe commands.

    #import 
    #import

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]); }

5. 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); }

6. Stop ongoing FFmpeg operations.

        [MobileFFmpeg cancel];

        [MobileFFmpeg cancel:executionId];
        

7. Get media information for a file.

    MediaInformation *mediaInformation = [MobileFFprobe getMediaInformation:@""];
    

8. 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];
    

9. Enable log callback.

    [MobileFFmpegConfig setLogDelegate:self];
  • (void)logCallback:(long)executionId :(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. Ignore the handling of a signal.

    [MobileFFmpegConfig ignoreSignal:SIGXCPU];
    

12. List ongoing executions.

    NSArray* ffmpegExecutions = [MobileFFmpeg listExecutions];
    for (int i = 0; i < [ffmpegExecutions count]; i++) {
        FFmpegExecution* execution = [ffmpegExecutions objectAtIndex:i];
        NSLog(@"Execution %d = id: %ld, startTime: %@, command: %@.\n", i, [execution getExecutionId], [execution getStartTime], [execution getCommand]);
    }
    

13. Set default log level.

    [MobileFFmpegConfig setLogLevel:AV_LOG_FATAL];
    

14. Register custom fonts directory.

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

2.4 Manual Installation

2.4.1 Android

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

2.4.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.5 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 stabilisation, pipe operations and concurrent command execution.

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.

Exact version number is obtained using git describe --tags.

| MobileFFmpeg Version | FFmpeg Version | Release Date | | :----: | :----: |:----: | | 4.4 | 4.4-dev-416 | Jul 25, 2020 | | 4.4.LTS | 4.4-dev-416 | Jul 24, 2020 | | 4.3.2 | 4.3-dev-2955 | Apr 15, 2020 | | 4.3.1 | 4.3-dev-1944 | Jan 25, 2020 | | 4.3.1.LTS | 4.3-dev-1944 | Jan 25, 2020 | | 4.3 | 4.3-dev-1181 | Oct 27, 2019 | | 4.2.2 | 4.2-dev-1824 | July 3, 2019 | | 4.2.2.LTS | 4.2-dev-1824 | July 3, 2019 | | 4.2.1 | 4.2-dev-1156 | Apr 2, 2019 | | 4.2 | 4.2-dev-480 | Jan 3, 2019 | | 4.2.LTS | 4.2-dev-480 | Jan 3, 2019 | | 3.1 | 4.1-10 | Dec 11, 2018 | | 3.0 | 4.1-dev-1517 | Oct 25, 2018 | | 2.2 | 4.0.3 | Nov 10, 2018 | | 2.1.1 | 4.0.2 | Sep 19, 2018 | | 2.1 | 4.0.2 | Sep 5, 2018 | | 2.0 | 4.0.1 | Jun 30, 2018 | | 1.2 | 3.4.4 | Aug 30, 2018| | 1.1 | 3.4.2 | Jun 18, 2018 | | 1.0 | 3.4.2 | Jun 6, 2018 |

4. LTS Releases

Starting from v4.2, MobileFFmpeg binaries are published in two different variants: Main Release and LTS Release.

This table shows the differences between two variants.

| | Main Release | LTS Release | | :----: | :----: | :----: | | Android API Level | 24 | 16 | | Android Camera Access | Yes | - | | Android Architectures | arm-v7a-neon
arm64-v8a
x86
x86-64 | arm-v7a
arm-v7a-neon
arm64-v8a
x86
x86-64 | | Xcode Support | 10.1 | 7.3.1 | | iOS SDK | 12.1 | 9.3 | | iOS AVFoundation | Yes | - | | iOS Architectures | arm64
arm64e1
x86-64
x86-64-mac-catalyst2 | armv7
arm64
i386
x86-64 | | tvOS SDK | 10.2 | 9.2 | | tvOS Architectures | arm64
x86-64 | arm64
x86-64 |

1 - Included until v4.3.2

2 - Included since v4.3.2

5. Building

Build scripts from master and development branches are tested periodically. See the latest status from the table below.

| branch | status | | :---: | :---: | | master | Build Status | | development | Build Status |

5.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 git
    
Some of these packages are not mandatory for the default build. Please visit Android Prerequisites, iOS Prerequisites and tvOS Prerequisites for the details.

2. Android builds require these additional packages.

3. iOS builds need these extra packages and tools. 4. tvOS builds need these extra packages and tools.

5.2 Build Scripts

Use android.sh, ios.sh and tvos.sh to build MobileFFmpeg for each platform.

All three scripts support additional options and can be customized to enable/disable specific external libraries an

More Video Trending projects

1

Genymobile / scrcpy

C★ 149,650⑂ 0
2

harry0703 / MoneyPrinterTurbo

Python★ 123,776⑂ 0
3

obsproject / obs-studio

C★ 76,223⑂ 0
4

FFmpeg / FFmpeg

C★ 64,235⑂ 0
5

calesthio / OpenMontage

Python★ 59,205⑂ 0
6

heygen-com / hyperframes

TypeScript★ 50,163⑂ 0