Vote count:
0
I'm merging videos in a loop and try to apply opacity and scaling with a AVMutableVideoCompositionLayerInstruction - alas, it's not working.
Any ideas what I'm doing wrong?
for(NSDictionary *clip in collection[@"clips"]){
AVMutableCompositionTrack *compositionVideoTrack = [theMutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionAudioTrack = [theMutableComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
CMTime clipStart = insertPoint;
NSString *movieName = [NSString stringWithFormat:@"collection_%li/recording_%li_%li.MOV", (long)editCollection, editCollection, [clip[@"clipID"] longValue]];
NSURL *assetUrl = [NSURL fileURLWithPath:[usefulStuff pathForFile: movieName]];
AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:assetUrl options:nil];
// Set Timerange
totalTime = CMTimeAdd(totalTime, [videoAsset duration]);
timeRange = CMTimeRangeMake(kCMTimeZero, [videoAsset duration]);
AVAssetTrack *clipVideoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVAssetTrack *clipAudioTrack = [[videoAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
NSError *error;
[compositionVideoTrack insertTimeRange:clipVideoTrack.timeRange ofTrack:clipVideoTrack atTime:insertPoint error:nil]; // Add video
[compositionAudioTrack insertTimeRange:clipAudioTrack.timeRange ofTrack:clipAudioTrack atTime:insertPoint error:&error]; // Add audio
AVMutableVideoCompositionLayerInstruction *passThroughLayerClip = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionVideoTrack];
compositionVideoTrack.preferredTransform = clipVideoTrack.preferredTransform;
CGAffineTransform scale = CGAffineTransformMakeScale(scaleFactorX, scaleFactorY);
[passThroughLayerClip setTransform:scale atTime:kCMTimeZero];
// Set Fade-In
insertPoint = CMTimeAdd(insertPoint, [videoAsset duration]);
[passThroughLayerClip setOpacity:0.0 atTime:[videoAsset duration]];
[layerInstructions addObject:passThroughLayerClip];
[transitionTimes addObject:[NSValue valueWithCMTime: insertPoint]];
AVMutableVideoCompositionInstruction *passThroughInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
passThroughInstruction.timeRange = CMTimeRangeMake(clipStart, videoAsset.duration);
passThroughInstruction.layerInstructions = [NSArray arrayWithObject:passThroughLayerClip];
[videoCompositionInstructions addObject:passThroughInstruction];
assetUrl = nil;
videoAsset = nil;
passThroughLayerClip = nil;
}
asked 29 secs ago
AVMutableVideoCompositionLayerInstruction doesn't get applied
Aucun commentaire:
Enregistrer un commentaire