我一直在努力進行視頻編輯,我已成功完成以下工作: 1.合併多個視頻。 2.調整視頻的速度。 3.剪輯視頻。移動觸摸iOS上的視頻覆蓋
現在我需要顯示在視頻圖像,然後搬過來說video.I的形象有兩個問題:
問題1: 我已經成功地完成了覆蓋部分即添加圖像在video.But如何我應該移動這個圖像嗎?
問題2: 此外,我無法通過它檢查視頻的預覽圖像。我能夠檢查當且僅當我保存該視頻在某個路徑然後使用該路徑播放。
下面是我用來完成覆蓋任務的代碼:
composition_ = [[AVMutableComposition alloc]init];
AVMutableCompositionTrack *compositionTrack = [composition_ addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *assetTrack = [[self.asset tracksWithMediaType:AVMediaTypeVideo]firstObject];
[compositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, self.asset.duration) ofTrack:assetTrack atTime:kCMTimeZero error:nil];
AVMutableVideoCompositionInstruction *videoCompositionInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
videoCompositionInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, self.asset.duration);
AVMutableVideoCompositionLayerInstruction *videoCompositionLayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionTrack];
videoCompositionInstruction.layerInstructions = @[videoCompositionLayerInstruction];
[videoCompositionLayerInstruction setTransform:assetTrack.preferredTransform atTime:kCMTimeZero];
[videoCompositionLayerInstruction setOpacity:0.0 atTime:self.asset.duration];
CGSize naturalSize = CGSizeMake(assetTrack.naturalSize.height, assetTrack.naturalSize.width);
videoComposition_ = [AVMutableVideoComposition videoComposition];
videoComposition_.renderSize = CGSizeMake(naturalSize.width, naturalSize.height);
videoComposition_.instructions = @[videoCompositionInstruction];
videoComposition_.frameDuration = CMTimeMake(1, 30);
//start image code from here
CALayer *overlayLayer = [CALayer layer];
overlayLayer.contents = (__bridge id _Nullable)([[UIImage imageNamed:@"overlay_icon.png"]CGImage]);
overlayLayer.frame = CGRectMake(naturalSize.width/2 , naturalSize.height/2, naturalSize.width/8, naturalSize.height/8);
overlayLayer.opacity = 0.5;
[overlayLayer setMasksToBounds:YES];
overlayLayer.backgroundColor = [[UIColor redColor]CGColor];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0 , 0, naturalSize.width, naturalSize.height);
videoLayer.frame = CGRectMake(0 , 0, naturalSize.width, naturalSize.height);
videoLayer.backgroundColor = [[UIColor redColor]CGColor];
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:overlayLayer];
videoComposition_.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
其實我面臨同樣的問題。你能給我提供你的示例代碼嗎? @Reckoner –
當然,我會明天提供你的代碼 – Reckoner
謝謝你的好友....我等待它:) @Reckoner –