2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

videoAtPathIsCompatibleWithSavedPhotosAlbum:NOなmp4のカメラロール保存

Posted at

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");
    }
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?