我想我的问题/问题与其他帖子不同之处在于,我不是在缩放视图,而是一个资产层指令(AVMutableVideoCompositionLayerInstruction)。所以设置锚点,view.center,CG重新缩放都不起作用。
除了用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];
}发布于 2014-05-15 16:24:44
CGAffineTransform在Quartz坐标系中工作,这是您应该从这里开始的点:
CGAffineTransform translate = CGAffineTransformMakeTranslation((x,y);
CGAffineTransform scale = CGAffineTransformMakeScale(q,z);
CGAffineTransform finalTransform = CGAffineTransformConcat(scale, CGAffineTransformConcat(translate, assetTrackForVideo1.preferredTransform));
[layerInstructionForVideo setTransform:finalTransform atTime:kCMTimeZero];
[layerInstructions addObject:layerInstructionForVideo];这种转变对我来说是可行的。
编辑:我的错误,忘记编辑所有的代码!
https://stackoverflow.com/questions/23572295
复制相似问题