當我創建使用this tutorial一個視頻,我嘗試移動AVAssetTrack* firstTrack
使用AVMutableVideoCompositionInstruction
爲包含一些CGAffineTransform
個AVMutableVideoCompositionLayerInstruction
(不包括動畫,所以我不能使用CAAnimation
S),在變換一下就忽略忽略。AVMutableVideoCompositionInstruction是在AVMutableVideoComposition
有誰知道這個問題,並知道如何解決它?
在此先感謝!
此信息可能有所幫助:在導出時,我使用AVAssetExportPreset1280x720作爲預設。所以我認爲(可能是錯誤的)this不是問題。
編輯:代碼被分割成各種函數,但我試圖把所有東西都合併到一個代碼中。我希望沒有忘記任何東西或弄亂了某些東西。
// The layer I want to move
CALayer* layerToMove = nil;
// A layer containing just the black background
CALayer* backgroundLayer = nil;
// The videos duration
double duration = 12.0;
AVMutableComposition *exportAsset = [[AVMutableComposition alloc] init];
[exportAsset setNaturalSize:layerToMove.frame.size];
AVMutableCompositionTrack* dstTrack = [self addBlackVideoTrackOfDuration:duration toComposition:exportAsset];
AVMutableVideoCompositionInstruction * MainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
MainInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, exportAsset.duration);
CGAffineTransform Scale = CGAffineTransformMakeScale(0.1f,0.1f);
CGAffineTransform Move = CGAffineTransformMakeTranslation(230,230);
AVMutableVideoCompositionLayerInstruction *FirstlayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:dstTrack];
[FirstlayerInstruction setTransform:CGAffineTransformConcat(Scale,Move) atTime:kCMTimeZero];
[MainInstruction setLayerInstructions:@[FirstlayerInstruction]];
CALayer* compositionLayer = [CALayer layer];
compositionLayer.bounds = layerToMove.frame;
compositionLayer.anchorPoint = CGPointMake(0, 0);
compositionLayer.position = CGPointMake(0, 0);
[compositionLayer setFrame:layerToMove.frame];
[compositionLayer setBounds:layerToMove.frame];
[compositionLayer addSublayer:backgroundLayer];
[compositionLayer addSublayer:layerToMove];
AVVideoCompositionCoreAnimationTool *animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:layerToMove inLayer:compositionLayer];
CMTime frameDuration = CMTimeMakeWithSeconds(1.0/25,
1000);
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
[videoComposition setFrameDuration:frameDuration];
[videoComposition setInstructions:@[MainInstruction]];
[videoComposition setAnimationTool:animationTool];
[videoComposition setRenderSize:layerToMove.frame.size];
[videoComposition setRenderScale:1.0];
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:exportAsset presetName:AVAssetExportPreset1280x720];
[exportSession setOutputFileType:AVFileTypeQuickTimeMovie];
[exportSession setOutputURL:nil/*Any url*/];
[exportSession setVideoComposition:videoComposition];
// The export is complete
[exportSession exportAsynchronouslyWithCompletionHandler:^
{
/*Whatever*/
}];
你可以發佈你現有的代碼? –
這是非常多的代碼分裂在各種功能,但我會盡力把它發佈每一個重要的行。給我幾分鐘。 – 0x6368
我在視頻拼貼應用程序中有CGAffineTransform。它工作正常。你也可以使用CoreAnimationTool來改變AVExportSession的視頻層的位置。你能告訴我你的代碼嗎? –