2021-03-03 10:11:19 +02:00
# FFmpegKit for iOS, macOS and tvOS
### 1. Features
#### 1.1 iOS
2021-12-25 20:07:45 +02:00
- Supports `iOS SDK 12.1+` on Main releases and `iOS SDK 10+` on LTS releases
2021-03-04 02:31:47 +02:00
- Includes `armv7` , `armv7s` , `arm64` , `arm64-simulator` , `arm64e` , `i386` , `x86_64` , `x86_64-mac-catalyst` and
2021-03-03 10:11:19 +02:00
`arm64-mac-catalyst` architectures
- Objective-C API
- Camera access
- `ARC` enabled library
- Built with `-fembed-bitcode` flag
2021-12-25 20:07:45 +02:00
- Creates shared `frameworks` and `xcframeworks`
2021-03-03 10:11:19 +02:00
#### 1.2 macOS
2021-12-25 20:07:45 +02:00
- Supports `macOS SDK 10.15+` on Main releases and `macOS SDK 10.12+` on LTS releases
2021-03-04 02:31:47 +02:00
- Includes `arm64` and `x86_64` architectures
2021-03-03 10:11:19 +02:00
- Objective-C API
- Camera access
- `ARC` enabled library
- Built with `-fembed-bitcode` flag
2021-12-25 20:07:45 +02:00
- Creates shared `frameworks` and `xcframeworks`
2021-03-03 10:11:19 +02:00
#### 1.3 tvOS
2021-12-25 20:07:45 +02:00
- Supports `tvOS SDK 11.0+` on Main releases and `tvOS SDK 10.0+` on LTS releases
2021-03-04 02:31:47 +02:00
- Includes `arm64` , `arm64-simulator` and `x86_64` architectures
2021-03-03 10:11:19 +02:00
- Objective-C API
- `ARC` enabled library
- Built with `-fembed-bitcode` flag
2021-12-25 20:07:45 +02:00
- Creates shared `frameworks` and `xcframeworks`
2021-03-03 10:11:19 +02:00
### 2. Building
2021-12-25 20:07:45 +02:00
Run `ios.sh` /`macos.sh`/`tvos.sh` inside the project root to build `ffmpeg-kit` and `ffmpeg` shared libraries
for a platform.
2021-03-03 10:11:19 +02:00
Optionally, use `apple.sh` to combine bundles created by these three scripts in a single bundle.
2021-03-04 02:31:47 +02:00
Please note that `FFmpegKit` project repository includes the source code of `FFmpegKit` only. `ios.sh` , `macos.sh` and
`tvos.sh` need network connectivity and internet access to `github.com` in order to download the source code of
`FFmpeg` and external libraries enabled.
2021-03-03 10:11:19 +02:00
2021-03-04 02:31:47 +02:00
#### 2.1 Prerequisites
2021-03-03 10:11:19 +02:00
2021-03-04 02:31:47 +02:00
`ios.sh` , `macos.sh` and `tvos.sh` require the following tools and packages.
2021-03-03 10:11:19 +02:00
##### 2.1.1 iOS
2021-12-25 20:07:45 +02:00
- **Xcode 8.0** or later
- **iOS SDK 10** or later
2021-03-03 10:11:19 +02:00
- **Command Line Tools**
##### 2.1.2 macOS
2021-12-25 20:07:45 +02:00
- **Xcode 8.0** or later
- **macOS SDK 10.12** or later
2021-03-03 10:11:19 +02:00
- **Command Line Tools**
##### 2.1.3 tvOS
2021-12-25 20:07:45 +02:00
- **Xcode 8.0** or later
- **tvOS SDK 10.0** or later
2021-03-03 10:11:19 +02:00
- **Command Line Tools**
2021-03-04 02:31:47 +02:00
##### 2.1.4 Packages
Use your package manager (brew, etc.) to install the following packages.
```
2022-05-21 01:36:53 +03:00
autoconf automake libtool pkg-config curl cmake gcc gperf texinfo yasm nasm bison autogen git wget gettext meson ninja
2021-03-04 02:31:47 +02:00
```
2021-03-03 10:11:19 +02:00
#### 2.2 Options
2021-03-04 02:31:47 +02:00
Use `--enable-<library name>` flag to support additional external or system libraries and
2021-03-03 10:11:19 +02:00
`--disable-<architecture name>` to disable architectures you don't want to build.
```
./ios.sh --enable-fontconfig --disable-armv7
2021-03-04 02:31:47 +02:00
2021-03-03 10:11:19 +02:00
./macos.sh --enable-freetype --enable-macos-avfoundation --disable-arm64
2021-03-04 02:31:47 +02:00
2021-03-03 10:11:19 +02:00
./tv.sh --enable-dav1d --enable-libvpx --disable-arm64-simulator
```
Run `--help` to see all available build options.
#### 2.3 LTS Binaries
Use `--lts` option to build lts binaries for each architecture.
#### 2.4 Build Output
All libraries created can be found under the `prebuilt` directory.
- `iOS` `xcframeworks` for `Main` builds are located under the `bundle-apple-xcframework-ios` folder.
- `macOS` `xcframeworks` for `Main` builds are located under the `bundle-apple-xcframework-macos` folder.
- `tvOS` `xcframeworks` for `Main` builds are located under the `bundle-apple-xcframework-tvos` folder.
- `iOS` `frameworks` for `Main` builds are located under the `bundle-apple-framework-ios` folder.
- `iOS` `frameworks` for `LTS` builds are located under the `bundle-apple-framework-ios-lts` folder.
- `macOS` `frameworks` for `Main` builds are located under the `bundle-apple-framework-macos` folder.
- `macOS` `frameworks` for `LTS` builds are located under the `bundle-apple-framework-macos-lts` folder.
- `tvOS` `frameworks` for `Main` builds are located under the `bundle-apple-framework-tvos` folder.
- `tvOS` `frameworks` for `LTS` builds are located under the `bundle-apple-framework-tvos-lts` folder.
### 3. Using
#### 3.1 Objective API
2021-03-04 02:31:47 +02:00
1. Add `FFmpegKit` dependency to your `Podfile` in `ffmpeg-kit-<platform>-<package name>` pattern. Use one of the
2022-09-27 23:14:51 +03:00
`FFmpegKit` package names given in the project [README ](https://github.com/arthenica/ffmpeg-kit ).
2021-03-03 10:11:19 +02:00
- iOS
2021-10-06 22:33:23 +03:00
```yaml
2021-12-29 13:53:56 +02:00
pod 'ffmpeg-kit-ios-full', '~> 4.5.1'
2021-03-03 10:11:19 +02:00
```
- macOS
2021-10-06 22:33:23 +03:00
```yaml
2021-12-29 13:53:56 +02:00
pod 'ffmpeg-kit-macos-full', '~> 4.5.1'
2021-03-03 10:11:19 +02:00
```
- tvOS
2021-10-06 22:33:23 +03:00
```yaml
2021-12-29 13:53:56 +02:00
pod 'ffmpeg-kit-tvos-full', '~> 4.5.1'
2021-03-03 10:11:19 +02:00
```
2021-03-04 02:31:47 +02:00
2. Execute synchronous `FFmpeg` commands.
2021-03-03 10:11:19 +02:00
2021-10-06 22:33:23 +03:00
```objectivec
2021-03-03 10:11:19 +02:00
#include < ffmpegkit / FFmpegKit . h >
2021-03-04 02:31:47 +02:00
FFmpegSession *session = [FFmpegKit execute:@"-i file1.mp4 -c:v mpeg4 file2.mp4"];
ReturnCode *returnCode = [session getReturnCode];
2021-03-03 10:11:19 +02:00
if ([ReturnCode isSuccess:returnCode]) {
2021-03-04 02:31:47 +02:00
2021-03-03 10:11:19 +02:00
// SUCCESS
2021-03-04 02:31:47 +02:00
2021-03-03 10:11:19 +02:00
} else if ([ReturnCode isCancel:returnCode]) {
2021-03-04 02:31:47 +02:00
2021-03-03 10:11:19 +02:00
// CANCEL
2021-03-04 02:31:47 +02:00
2021-03-03 10:11:19 +02:00
} else {
2021-03-04 02:31:47 +02:00
2021-03-03 10:11:19 +02:00
// FAILURE
NSLog(@"Command failed with state %@ and rc %@.%@", [FFmpegKitConfig sessionStateToString:[session getState]], returnCode, [session getFailStackTrace]);
2021-03-04 02:31:47 +02:00
2021-03-03 10:11:19 +02:00
}
```
2021-03-04 02:31:47 +02:00
3. Each `execute` call (sync or async) creates a new session. Access every detail about your execution from the
session created.
2021-10-06 22:33:23 +03:00
```objectivec
2021-03-04 02:31:47 +02:00
FFmpegSession *session = [FFmpegKit execute:@"-i file1.mp4 -c:v mpeg4 file2.mp4"];
// Unique session id created for this execution
long sessionId = [session getSessionId];
// Command arguments as a single string
NSString *command = [session getCommand];
// Command arguments
NSArray *arguments = [session getArguments];
// State of the execution. Shows whether it is still running or completed
SessionState state = [session getState];
// Return code for completed sessions. Will be null if session is still running or ends with a failure
ReturnCode *returnCode = [session getReturnCode];
NSDate *startTime =[session getStartTime];
NSDate *endTime =[session getEndTime];
long duration =[session getDuration];
// Console output generated for this execution
NSString *output = [session getOutput];
// The stack trace if FFmpegKit fails to run a command
NSString *failStackTrace = [session getFailStackTrace];
// The list of logs generated for this execution
NSArray *logs = [session getLogs];
// The list of statistics generated for this execution
NSArray *statistics = [session getStatistics];
```
4. Execute asynchronous `FFmpeg` commands by providing session specific `execute` /`log`/`session` callbacks.
2021-03-03 10:11:19 +02:00
2021-10-06 22:33:23 +03:00
```objectivec
2021-12-29 13:53:56 +02:00
FFmpegSession* session = [FFmpegKit executeAsync:@"-i file1.mp4 -c:v mpeg4 file2.mp4" withCompleteCallback:^(FFmpegSession* session){
2021-03-03 10:11:19 +02:00
SessionState state = [session getState];
ReturnCode *returnCode = [session getReturnCode];
// CALLED WHEN SESSION IS EXECUTED
NSLog(@"FFmpeg process exited with state %@ and rc %@.%@", [FFmpegKitConfig sessionStateToString:state], returnCode, [session getFailStackTrace]);
} withLogCallback:^(Log *log) {
// CALLED WHEN SESSION PRINTS LOGS
} withStatisticsCallback:^(Statistics *statistics) {
// CALLED WHEN SESSION GENERATES STATISTICS
}];
```
2021-03-04 02:31:47 +02:00
5. Execute `FFprobe` commands.
- Synchronous
2021-03-03 10:11:19 +02:00
2021-10-06 22:33:23 +03:00
```objectivec
2021-03-03 10:11:19 +02:00
FFprobeSession *session = [FFprobeKit execute:ffprobeCommand];
2021-03-04 02:31:47 +02:00
2021-03-03 10:11:19 +02:00
if ([ReturnCode isSuccess:[session getReturnCode]]) {
NSLog(@"Command failed. Please check output for the details.");
}
```
2021-03-04 02:31:47 +02:00
- Asynchronous
2021-10-06 22:33:23 +03:00
```objectivec
2021-12-29 13:53:56 +02:00
[FFprobeKit executeAsync:ffmpegCommand withCompleteCallback:^(FFprobeSession* session) {
2021-03-04 02:31:47 +02:00
CALLED WHEN SESSION IS EXECUTED
}];
```
6. Get media information for a file.
2021-03-03 10:11:19 +02:00
2021-10-06 22:33:23 +03:00
```objectivec
2021-03-04 02:31:47 +02:00
MediaInformationSession *mediaInformation = [FFprobeKit getMediaInformation:"< file path or uri > "];
MediaInformation *mediaInformation =[mediaInformation getMediaInformation];
2021-03-03 10:11:19 +02:00
```
2021-03-04 02:31:47 +02:00
7. Stop ongoing `FFmpeg` operations.
2021-03-03 10:11:19 +02:00
- Stop all executions
2021-10-06 22:33:23 +03:00
```objectivec
2021-03-03 10:11:19 +02:00
[FFmpegKit cancel];
```
- Stop a specific session
2021-10-06 22:33:23 +03:00
```objectivec
2021-03-03 10:11:19 +02:00
[FFmpegKit cancel:sessionId];
```
2021-03-04 02:31:47 +02:00
8. Get previous `FFmpeg` and `FFprobe` sessions from session history.
2021-03-03 10:11:19 +02:00
2021-10-06 22:33:23 +03:00
```objectivec
2021-03-04 02:31:47 +02:00
NSArray* sessions = [FFmpegKitConfig getSessions];
for (int i = 0; i < [sessions count]; i++) {
id< Session > session = [sessions objectAtIndex:i];
2021-03-03 10:11:19 +02:00
NSLog(@"Session %d = id: %ld, startTime: %@, duration: %ld, state:%@, returnCode:%@.\n",
i,
[session getSessionId],
[session getStartTime],
[session getDuration],
[FFmpegKitConfig sessionStateToString:[session getState]],
[session getReturnCode]);
}
2021-03-04 02:31:47 +02:00
```
9. Enable global callbacks.
2021-12-29 13:53:56 +02:00
- Session type specific Complete Callbacks, called when an async session has been completed
2021-03-04 02:31:47 +02:00
2021-10-06 22:33:23 +03:00
```objectivec
2021-12-29 13:53:56 +02:00
[FFmpegKitConfig enableFFmpegSessionCompleteCallback:^(FFmpegSession* session) {
...
}];
[FFmpegKitConfig enableFFprobeSessionCompleteCallback:^(FFprobeSession* session) {
...
}];
[FFmpegKitConfig enableMediaInformationSessionCompleteCallback:^(MediaInformationSession* session) {
2021-03-04 02:31:47 +02:00
...
}];
```
- Log Callback, called when a session generates logs
2021-10-06 22:33:23 +03:00
```objectivec
2021-03-04 02:31:47 +02:00
[FFmpegKitConfig enableLogCallback:^(Log *log) {
...
}];
```
- Statistics Callback, called when a session generates statistics
2021-10-06 22:33:23 +03:00
```objectivec
2021-03-04 02:31:47 +02:00
[FFmpegKitConfig enableStatisticsCallback:^(Statistics *statistics) {
...
}];
```
10. Ignore the handling of a signal. Required by `Mono` and frameworks that use `Mono` , e.g. `Unity` and `Xamarin` .
2021-10-06 22:33:23 +03:00
```objectivec
2021-03-04 02:31:47 +02:00
[FFmpegKitConfig ignoreSignal:SIGXCPU];
```
11. Register system fonts and custom font directories.
2021-10-06 22:33:23 +03:00
```objectivec
2021-04-03 21:17:42 +03:00
[FFmpegKitConfig setFontDirectoryList:[NSArray arrayWithObjects:@"/System/Library/Fonts", @"< folder with fonts > ", nil] with:nil];
2021-03-04 02:31:47 +02:00
```
2021-03-03 10:11:19 +02:00
### 4. Test Application
2021-03-04 02:31:47 +02:00
You can see how `FFmpegKit` is used inside an application by running `iOS` , `macOS` and `tvOS` test applications
2022-09-27 23:14:51 +03:00
developed under the [FFmpegKit Test ](https://github.com/arthenica/ffmpeg-kit-test ) project.