问题
I have simple video compression code in low quality conversion.I am testing my code in iphone 4 with IOS-4.2.1.The problem is when I test my code on device without break points the code failed to create video(it just a zero kb file or empty file created) but when I use breakpoint checking line by line this code slowly it will make a perfect compressed video which also runs on quicktime player in mac.After compression I make zip of this video file.
NSURL *videoURL=[[self.videourlarray objectAtIndex:i] valueForKey:UIImagePickerControllerReferenceURL];
NSURL *outputURL = [NSURL fileURLWithPath:videoFile];
[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
exportSession.outputURL = outputURL;
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
{
NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
[exportSession release];
}];
thanx for any help...
回答1:
I think you need to make sure you're not messing with the threads.. (AVFoundation guide says that the exporter is not guaranteed to run on any particular thread).
Use a block like this.
[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
});
}];
I would personally call a delegate from the block, but I presume your simple log statement is just for this example and you already know that :)
回答2:
I had the same problem. After hours of debuging, I found out that my extension of the audio file was .M4A
all uppercase. Lowercasing the letters will fix the problem
来源:https://stackoverflow.com/questions/6592218/avassetexportsession-with-and-without-break-points