Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Objective-C</strong></p> <pre><code>-(void)cropVideo:(NSURL*)videoToTrimURL{ AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoToTrimURL options:nil]; AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *outputURL = paths[0]; NSFileManager *manager = [NSFileManager defaultManager]; [manager createDirectoryAtPath:outputURL withIntermediateDirectories:YES attributes:nil error:nil]; outputURL = [outputURL stringByAppendingPathComponent:@"output.mp4"]; // Remove Existing File [manager removeItemAtPath:outputURL error:nil]; exportSession.outputURL = [NSURL fileURLWithPath:outputURL]; exportSession.shouldOptimizeForNetworkUse = YES; exportSession.outputFileType = AVFileTypeQuickTimeMovie; CMTime start = CMTimeMakeWithSeconds(1.0, 600); // you will modify time range here CMTime duration = CMTimeMakeWithSeconds(15.0, 600); CMTimeRange range = CMTimeRangeMake(start, duration); exportSession.timeRange = range; [exportSession exportAsynchronouslyWithCompletionHandler:^(void) { switch (exportSession.status) { case AVAssetExportSessionStatusCompleted: [self writeVideoToPhotoLibrary:[NSURL fileURLWithPath:outputURL]]; NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error); break; case AVAssetExportSessionStatusFailed: NSLog(@"Failed:%@",exportSession.error); break; case AVAssetExportSessionStatusCancelled: NSLog(@"Canceled:%@",exportSession.error); break; default: break; } //[exportSession release]; }]; } </code></pre> <p><strong>In Swift 4.0</strong></p> <pre><code> static func cropVideo(atURL url:URL) { let asset = AVURLAsset(url: url) let exportSession = AVAssetExportSession.init(asset: asset, presetName: AVAssetExportPresetHighestQuality)! var outputURL = URL(string:NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last!) let fileManager = FileManager.default do { try fileManager.createDirectory(at: outputURL!, withIntermediateDirectories: true, attributes: nil) } catch { } outputURL?.appendPathComponent("output.mp4") // Remove existing file do { try fileManager.removeItem(at: outputURL!) } catch { } exportSession.outputURL = outputURL exportSession.shouldOptimizeForNetworkUse = true exportSession.outputFileType = AVFileTypeQuickTimeMovie let start = CMTimeMakeWithSeconds(1.0, 600) // you will modify time range here let duration = CMTimeMakeWithSeconds(15.0, 600) let range = CMTimeRangeMake(start, duration) exportSession.timeRange = range exportSession.exportAsynchronously { switch(exportSession.status) { case .completed: break // case .failed: break // case .cancelled: break // default: break } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload