Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.
Taner Şener edited this page Jul 27, 2020 · 7 revisions
  1. Add MobileFFmpeg dependency to your Podfile in mobile-ffmpeg-tvos-<package name> pattern.

    pod 'mobile-ffmpeg-tvos-full', '~> 4.4'
    
  2. Execute synchronous 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 asynchronous FFmpeg commands.

    #import <mobileffmpeg/MobileFFmpegConfig.h>
    #import <mobileffmpeg/MobileFFmpeg.h>
    
    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 <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]);
    }
    
  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.

    • Stop all executions
      [MobileFFmpeg cancel];
      
      
    • Stop a specific execution
      [MobileFFmpeg cancel:executionId];
      
  7. Get media information for a file.

    MediaInformation *mediaInformation = [MobileFFprobe getMediaInformation:@"<file path or uri>"];
    
  8. Enable log callback.

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

    [MobileFFmpegConfig ignoreSignal:SIGXCPU];
    
  11. 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]);
    }
    
  12. Set default log level.

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

    [MobileFFmpegConfig setFontDirectory:@"<folder with fonts>" with:nil];
    
Clone this wiki locally