2016-03-28 1 views
0

Ich versuche, die Größe von AVAssetExportSession zu 10mb zu begrenzen. Ohne Einstellung fileLengthLimit ist der "Export abgeschlossen". Nach der Einstellung fileLengthLimit = 10*1024*1024 ist der "Export fehlgeschlagen: kann nicht geöffnet werden".Einstellung `fileLengthLimit` von` AVAssetExportSession` verursacht: "Export fehlgeschlagen: kann nicht geöffnet werden"

- (void) splitVideo{ 
    AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:output options:nil]; 
    CMTime videoDuration = videoAsset.duration; 

    CMTime start = CMTimeMakeWithSeconds(0, 1); 
    CMTimeRange range = CMTimeRangeMake(start, videoDuration); 

    NSString *outputPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"output1.mp4"]; 
    [self cutVideo:output withRange:range withOutput:outputPath]; 
} 

- (void) cutVideo:(NSURL *)url withRange:(CMTimeRange)range withOutput:(NSString*)path{ 

    AVAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil]; 
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:asset]; 
    if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]) { 
     AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] 
              initWithAsset:asset presetName:AVAssetExportPresetPassthrough]; 

     NSURL *finalUrl = [NSURL fileURLWithPath:path]; 
     exportSession.outputURL = finalUrl; 
     exportSession.outputFileType = AVFileTypeMPEG4; 
     exportSession.fileLengthLimit = 10*1024*1024; 
     exportSession.timeRange = range; 

     [exportSession exportAsynchronouslyWithCompletionHandler:^{ 
      dispatch_async(dispatch_get_main_queue(), ^{ 

      }); 
      if ([exportSession status] == AVAssetExportSessionStatusCompleted){ 
       NSLog(@"Export completed"); 
      }else if ([exportSession status] == AVAssetExportSessionStatusFailed){ 
       NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]); 
      }else if ([exportSession status] == AVAssetExportSessionStatusCancelled){ 
       NSLog(@"Export canceled"); 
      } 
      }]; 
    } 
} 

Die Videos sind um 25mb exportiert.

Antwort

0

I ersetzt

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetPassthrough] 

mit:

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality]; 

AVAssetExportPresetPassthrough - „Diese Exportoption bewirkt, dass die Medien aller Spuren durch genau an den Ausgang weitergegeben werden wie in der Quelle gespeichert Anlage "

Verwandte Themen