0

I was able to successfully compile & import ffmpeg into my existing iOS app. However now I want to ru the following commands to clip and crop a video. How do I interact with the ffmpeg library from iOS?

This command words for me via command line:

./ffmpeg -i input.mp4 -ss 157 -t 10 -vf crop=250:250:200:100 -strict -2 clipped.mp4

2 Answers2

0

You can trim video using AVFoundation

AVAsset *anAsset = <#Get an asset#>;
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality]) {
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
        initWithAsset:anAsset presetName:AVAssetExportPresetLowQuality];

}


    exportSession.outputURL = <#A file URL#>;
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;

    CMTime start = CMTimeMakeWithSeconds(1.0, 600);
    CMTime duration = CMTimeMakeWithSeconds(3.0, 600);
    CMTimeRange range = CMTimeRangeMake(start, duration);
    exportSession.timeRange = range;

    [exportSession exportAsynchronouslyWithCompletionHandler:^{

        switch ([exportSession status]) {
            case AVAssetExportSessionStatusFailed:
                NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
                break;
            case AVAssetExportSessionStatusCancelled:
                NSLog(@"Export canceled");
                break;
            default:
                break;
        }
    }];

Reference:https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/01_UsingAssets.html

Zahid
  • 552
  • 3
  • 11
  • I would like to specifically use ffmpeg because I am doing multiple things with the video other than jus trimming. I need to crop, trim and later also convert formats of the video. – sudoExclaimationExclaimation Aug 23 '15 at 23:30
0

You probably know this already but you can use the ffmpeg libraries directly in iOS, rather than the command line format - the answer below seems a well accepted approach:

Assuming this is not want you want, and you actually want it use a ffmpeg 'wrapper' then there are a few available on GitHub. I have not used these personally although I have used the same technique on Android and it worked fine, so long as you remember you are using a program that was originally designed to be a standalone command line invocation and test thoroughly:

Community
  • 1
  • 1
Mick
  • 24,231
  • 1
  • 54
  • 120