Note that there are some explanatory texts on larger screens.

plurals
  1. POAVAssetExportSession outputfile
    text
    copied!<p>How should the AVAssetExportSession output file look like? I'm trying to compress a video from an ALAsset item and it doesn't work. I'm guessing the output file has something to do with it.</p> <p>Here's the code i'm using:</p> <pre><code>NSString *destinationPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie"]; [self convertVideoToLowQualityWithInputURL:asset.defaultRepresentation.url outputURL:[NSURL URLWithString:destinationPath]]; - (void)convertVideoToLowQualityWithInputURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL { if([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithContentsOfURL:outputURL encoding: 0 error:Nil]]) [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil]; AVURLAsset *assetAV = [AVURLAsset URLAssetWithURL:inputURL options:nil]; NSLog(@"url string from asset: %@", assetAV.URL); NSLog(@"output url: %@", [outputURL absoluteString]); [[NSFileManager defaultManager] createFileAtPath:[outputURL path] contents:nil attributes:nil]; NSLog(@"duration: %lld", assetAV.duration.value); //it logs a valid value, so it's all good so far AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:assetAV presetName:AVAssetExportPresetLowQuality]; exportSession.outputURL = outputURL; exportSession.outputFileType = AVFileTypeQuickTimeMovie; [exportSession exportAsynchronouslyWithCompletionHandler:^(void) { if (exportSession.status == AVAssetExportSessionStatusCompleted) { NSLog(@"success"); } else { NSLog(@"error: %@", [exportSession error]); //error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x2023b720 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x2023bb70 "The operation couldn’t be completed. (OSStatus error -12780.)", NSLocalizedFailureReason=An unknown error occurred (-12780)} } }]; } </code></pre> <p>Can someone please help me?</p> <p>UPDATE:</p> <p>Found the solution. As I thought the problem was the output file so here is the code for generating a valid one:</p> <pre><code> NSUInteger count = 0; NSString *filePath = nil; do { NSString *extension = ( NSString *)UTTypeCopyPreferredTagWithClass(( CFStringRef)AVFileTypeQuickTimeMovie, kUTTagClassFilenameExtension); NSString *fileNameNoExtension = [[asset.defaultRepresentation.url URLByDeletingPathExtension] lastPathComponent]; NSString *fileName = [NSString stringWithFormat:@"%@-%@-%u",fileNameNoExtension , AVAssetExportPresetLowQuality, count]; filePath = NSTemporaryDirectory(); filePath = [filePath stringByAppendingPathComponent:fileName]; filePath = [filePath stringByAppendingPathExtension:extension]; count++; } while ([[NSFileManager defaultManager] fileExistsAtPath:filePath]); NSURL *outputURL = [NSURL fileURLWithPath:filePath]; </code></pre>
 

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