2

我想播放 Marge 视频,但有一段时间先播放,然后第二个中断到第一个视频........

 CMTimeRange timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(30, 10));

AVMutableVideoCompositionLayerInstruction *to = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionCommentaryTrack];
   [to setOpacity:.5 atTime:kCMTimeZero];
 [to setTransform:CGAffineTransformScale(compositionCommentaryTrack.preferredTransform, .5, .5) atTime:kCMTimeZero];


 AVMutableVideoCompositionLayerInstruction *from = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionVideoTrack];
[from setOpacity:.5 atTime:kCMTimeZero];
[from setTransform:CGAffineTransformScale(compositionVideoTrack.preferredTransform, .6, .6) atTime:kCMTimeZero];

// Video Compostion
  AVMutableVideoCompositionInstruction *transition = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
  transition.backgroundColor = [[UIColor clearColor] CGColor];
  transition.timeRange = timeRange;
   transition.layerInstructions = [NSArray arrayWithObjects:to, from, nil];
  videoComposition.instructions = [NSArray arrayWithObjects:transition,  nil];
  videoComposition.frameDuration = CMTimeMake(1, 30);
  videoComposition.renderSize = CGSizeMake(320, 360);
  videoComposition.renderScale = 1.0;
4

0 回答 0