Advertisement
priore

Convert video to MP4 from a URL

Apr 23rd, 2015
1,363
0
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. }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement