1 Star 0 Fork 0

jiahangOK / mobile-ffmpeg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

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

FFmpeg for Android, iOS and tvOS

1. Features

  • 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-dev 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

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

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
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
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
wavpack
x264
x265
xvidcore
android system libraries zlib
MediaCodec
ios system libraries zlib
AudioToolbox
AVFoundation
CoreImage
VideoToolbox
bzip2
tvos system libraries zlib
AudioToolbox
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

  • 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

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'
    }
  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();
    
    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));
        FFmpeg.printLastCommandOutput(Log.INFO);
    }
  4. Stop an ongoing operation.

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

    MediaInformation info = FFmpeg.getMediaInformation("<file path or uri>");
  6. 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>");
  7. List enabled external libraries.

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

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

    Config.setLogLevel(Level.AV_LOG_FATAL);
  11. 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'
    • tvOS
    pod 'mobile-ffmpeg-tvos-full', '~> 4.3'
  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. 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];
  7. List enabled external libraries.

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

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

    [MobileFFmpegConfig setLogLevel:AV_LOG_FATAL];
  11. 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.
MobileFFmpeg Version FFmpeg Version Release Date
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.

  • Main releases include complete functionality of the library and support the latest SDK/API features.

  • LTS releases are customized to support a wider range of devices. They are built using older API/SDK versions, so some features are not available on them.

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 Architectures arm64
arm64e
x86-64
armv7
arm64
i386
x86-64
tvOS SDK 10.2 9.2
tvOS Architectures arm64
x86-64
arm64
x86-64

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.

  1. Android builds require these additional packages.

    • Android SDK 4.1 Jelly Bean (API Level 16) or later
    • Android NDK r20 or later with LLDB and CMake
  2. iOS builds need these extra packages and tools.

    • Xcode 7.3.1 or later
    • iOS SDK 9.3 or later
    • Command Line Tools
  3. tvOS builds need these extra packages and tools.

    • Xcode 7.3.1 or later
    • tvOS SDK 9.2 or later
    • Command Line 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 and/or architectures. Please refer to wiki pages of android.sh, ios.sh and tvos.sh to see all available build options.

5.2.1 Android
export ANDROID_HOME=<Android SDK Path>
export ANDROID_NDK_ROOT=<Android NDK Path>
./android.sh
5.2.2 iOS
./ios.sh
5.2.3 tvOS
./tvos.sh
5.2.4 Building LTS Binaries

Use --lts option to build lts binaries for each platform.

5.3 Build Output

All libraries created by the top level build scripts (android.sh, ios.sh and tvos.sh) can be found under the prebuilt directory.

  • Android archive (.aar file) is located under the android-aar folder
  • iOS frameworks are located under the ios-frameworkfolder
  • iOS universal binaries are located under the ios-universalfolder
  • tvOS frameworks are located under the tvos-frameworkfolder
  • tvOS universal binaries are located under the tvos-universalfolder

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

5.5 External Libraries

build directory includes build scripts of all external libraries. Two scripts exist for each external library, one for Android and one for iOS / tvOS. Each of these two scripts contains options/flags used to cross-compile the library on the specified mobile platform.

CPU optimizations (ASM) are enabled for most of the external libraries. Details and exceptions can be found under the ASM Support wiki page.

6. Documentation

A more detailed documentation is available at Wiki.

7. Contributors

7.1 Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

7.2 Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

7.2.1 Individuals

7.2.2 Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

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

openh264 source code included in this repository is licensed under the 2-clause BSD License but this license does not cover the MPEG LA licensing fees. If you build mobile-ffmpeg with openh264 and distribute that library, then you are subject to pay MPEG LA licensing fees. Refer to OpenH264 FAQ page for the details. Please note that mobile-ffmpeg does not publish a binary with openh264 inside.

strip-frameworks.sh script included and distributed (until v4.x) is published under the Apache License version 2.0.

In test applications; embedded fonts are licensed under the SIL Open Font License, other digital assets are published in the public domain.

Please visit License page for the details.

9. Contributing

If you have any recommendations or ideas to improve it, please feel free to submit issues or pull requests. Any help is appreciated.

10. See Also

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

暂无描述 展开 收起
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/jiahangok/mobile-ffmpeg.git
git@gitee.com:jiahangok/mobile-ffmpeg.git
jiahangok
mobile-ffmpeg
mobile-ffmpeg
master

搜索帮助