Skip to content
This repository was archived by the owner on Jan 6, 2025. 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-<package name> pattern.

    pod 'mobile-ffmpeg-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. Record video and audio using iOS camera.

    [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:@"<folder with fonts>" with:nil]; 

Clone this wiki locally