https://blog.csdn.net/sinat_31872425/article/details/50593124

  1.  
    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:sourceUrl options:nil];
  2.  
     
  3.  
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
  4.  
     
  5.  
    NSLog(@”%@”,compatiblePresets);
  6.  
     
  7.  
    if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]) {
  8.  
     
  9.  
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality];
  10.  
     
  11.  
    NSDateFormatter *formater = [[NSDateFormatter alloc] init];//用时间给文件全名,以免重复
  12.  
     
  13.  
    [formater setDateFormat:@”yyyy-MM-dd-HH:mm:ss”];
  14.  
     
  15.  
    NSString * resultPath = [NSHomeDirectory() stringByAppendingFormat:@”/Documents/output-%@.mp4″, [formater stringFromDate:[NSDate date]]];
  16.  
     
  17.  
    NSLog(@”resultPath = %@”,resultPath);
  18.  
     
  19.  
    exportSession.outputURL = [NSURL fileURLWithPath:resultPath];
  20.  
     
  21.  
    exportSession.outputFileType = AVFileTypeMPEG4;
  22.  
     
  23.  
    exportSession.shouldOptimizeForNetworkUse = YES;
  24.  
     
  25.  
    [exportSession exportAsynchronouslyWithCompletionHandler:^(void)
  26.  
     
  27.  
    {
  28.  
     
  29.  
    switch (exportSession.status) {
  30.  
     
  31.  
    case AVAssetExportSessionStatusUnknown:
  32.  
     
  33.  
    NSLog(@”AVAssetExportSessionStatusUnknown”);
  34.  
     
  35.  
    break;
  36.  
     
  37.  
    case AVAssetExportSessionStatusWaiting:
  38.  
     
  39.  
    NSLog(@”AVAssetExportSessionStatusWaiting”);
  40.  
     
  41.  
    break;
  42.  
     
  43.  
    case AVAssetExportSessionStatusExporting:
  44.  
     
  45.  
    NSLog(@”AVAssetExportSessionStatusExporting”);
  46.  
     
  47.  
    break;
  48.  
     
  49.  
    case AVAssetExportSessionStatusCompleted:
  50.  
     
  51.  
    NSLog(@”AVAssetExportSessionStatusCompleted”);
  52.  
     
  53.  
    break;
  54.  
     
  55.  
    case AVAssetExportSessionStatusFailed:
  56.  
     
  57.  
    NSLog(@”AVAssetExportSessionStatusFailed”);
  58.  
     
  59.  
    break;
  60.  
     
  61.  
    }
  62.  
     
  63.  
    }];
  64.  
     
  65.  
    }

版权声明:本文为sundaysgarden原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/sundaysgarden/articles/9403467.html