我想我提出的问题与其他帖子不同之处在于,我不是缩放视图,而是一个资源层指令(AVMutableVideoCompositionLayerInstruction)进行缩放。因此,设置锚点、view.center、CG Rect缩放都无效。
除了使用CGAffineTransformMakeTranslation将资源移动以使其看起来像是居中对齐,但这种方法精度极低,我不能想出如何使它从中心点缩放。是否有我遗漏的属性?文档和指南并不十分有用,但也许我错过了某些内容。
代码如下。非常感谢大家!!! :)
另外,对于那些寻找使用CGTransforms导出avasset的方法的人,下面的代码是完成此操作的所有步骤;当然需要填写细节,例如CMTimeRanges,但希望这有助于帮助有困惑的人弄清楚这个麻烦的东西。
除了使用CGAffineTransformMakeTranslation将资源移动以使其看起来像是居中对齐,但这种方法精度极低,我不能想出如何使它从中心点缩放。是否有我遗漏的属性?文档和指南并不十分有用,但也许我错过了某些内容。
代码如下。非常感谢大家!!! :)
另外,对于那些寻找使用CGTransforms导出avasset的方法的人,下面的代码是完成此操作的所有步骤;当然需要填写细节,例如CMTimeRanges,但希望这有助于帮助有困惑的人弄清楚这个麻烦的东西。
-(void) goAssetsExport {
AVMutableComposition *composition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *firstTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.frameDuration = CMTimeMake(1,30);
videoComposition.renderScale = 1.0;
videoComposition.renderSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height);
NSURL *movieURL = [[NSBundle mainBundle] URLForResource:[NSString stringWithFormat:@"%@", [preloadEffectsArray objectAtIndex:i]] withExtension:@"mov"];
AVURLAsset *firstAsset = [AVURLAsset URLAssetWithURL:movieURL options:nil];
AVAssetTrack *firstAssetTrack = [[firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
[firstTrack insertTimeRange:CMTimeRangeMake(firstTrackRangeMin, duration) ofTrack:firstAssetTrack atTime:firstTrackRangeMin error:nil];
AVMutableVideoCompositionInstruction *transitionInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
AVMutableVideoCompositionLayerInstruction *fromLayer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:firstTrack];
//**This is where problem might be?**//
CGAffineTransform Scaler = CGAffineTransformMakeScale(scaleNumber,scaleNumber);
CGAffineTransform Mover = CGAffineTransformMakeTranslation(scaleNumber * -100, scaleNumber * -150);
[fromLayer setTransform:CGAffineTransformConcat(Scaler,Mover) atTime:firstTrackRangeMin];
transitionInstruction.layerInstructions = [NSArray arrayWithObject:fromLayer];
videoComposition.instructions = instructionArray;
[self exportVideo:composition withInstructionComposition:videoComposition];
}