ビデオのフォーマットを変更する良い方法は何ですか?
複数のビデオをまとめてマージし、AVAssetExportSession を使用してエクスポートするために、次のようなことを行っています。
AVMutableComposition *mixComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
NSError * error = nil;
AVURLAsset *assetClip;
AVAssetTrack *clipVideoTrack;
AVAssetTrack *clipAudioTrack;
for (int i = [clipPaths count]-1; i >= 0; i--) {
assetClip = [AVURLAsset URLAssetWithURL:[clipPaths objectAtIndex:i] options:nil];
clipVideoTrack = [[assetClip tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
clipAudioTrack = [[assetClip tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
[compositionVideoTrack insertTimeRange:clipVideoTrack.timeRange ofTrack:clipVideoTrack atTime:kCMTimeZero error:&error];
[compositionAudioTrack insertTimeRange:clipAudioTrack.timeRange ofTrack:clipAudioTrack atTime:kCMTimeZero error:&error];
}
NSString *cachesFolder = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingString:@"/"];
NSString *finalPath = [cachesFolder stringByAppendingPathComponent:[self.currentFileName stringByAppendingString:@".mov"]];
// Remove video file if it exists
NSFileManager *fileManager = [NSFileManager defaultManager];
if([fileManager fileExistsAtPath:finalPath]) {
[fileManager removeItemAtPath:finalPath error:&error];
}
NSURL *lastURL = [NSURL fileURLWithPath:finalPath];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.outputURL = lastURL;
[exporter exportAsynchronouslyWithCompletionHandler:^(void){
switch(exporter.status) {
case AVAssetExportSessionStatusFailed:
NSLog(@"exporting failed");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(@"exporting completed");
[[NSNotificationCenter defaultCenter] postNotificationName:@"didCompleteMovieMerging" object:nil];
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"export cancelled");
break;
}
}];
私はあなたが使用できることを見ました
AVMutableVideoComposition* videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.renderSize = CGSizeMake(320, 320);
videoComposition.frameDuration = CMTimeMake(1, 30);
AVAssetExportSession の代わりに、これらの両方を連携させる方法が見つかりません。