AVAssetExportSessionでcompatible:NOのmp4をcompatible:YESなmp4にexportする
- (void) saveMovie{
NSString* tempPath=[[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:tempPath];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: [AVURLAsset URLAssetWithURL:url options:nil] presetName:AVAssetExportPresetMediumQuality];
exporter.outputURL=[NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"test.mp4"]];
exporter.outputFileType = AVFileTypeMPEG4;
[exporter exportAsynchronouslyWithCompletionHandler:^
{
dispatch_async(dispatch_get_main_queue(), ^{
[self exportDidFinish:exporter];
});
}];
}
- (void)exportDidFinish:(AVAssetExportSession*)session
{
NSURL *outputURL = session.outputURL;
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputURL]) {
[library writeVideoAtPathToSavedPhotosAlbum:outputURL
completionBlock:^(NSURL *assetURL, NSError *error){
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
NSLog(@"Error: %@", error);
}else{
NSLog(@"success!");
}
});
}];
}else{
NSLog(@"no compatible");
}
}