priore

Convert video to MP4 from a URL

Apr 23rd, 2015
861
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <AssetsLibrary/AssetsLibrary.h>
  2. #import <AVFoundation/AVFoundation.h>
  3.  
  4. // temp filename
  5. NSString *fname = [NSString stringWithFormat:@"%.f.mp4", [NSDate timeIntervalSinceReferenceDate]];
  6. NSURL *videoURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:fname]];
  7.  
  8. // convert to MP4
  9. AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
  10. AVAssetExportSession *session = [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetPassthrough];
  11. session.outputFileType = AVFileTypeMPEG4;
  12. session.outputURL = videoURL;
  13. [session exportAsynchronouslyWithCompletionHandler:^{
  14.     NSLog("Video converted!");
  15. }];
RAW Paste Data