insertEmptyTimeRange 到 AVMutableCompositionTrack 不工作

insertEmptyTimeRange to AVMutableCompositionTrack not working

我正在使用 AVMutableCompositionTrack 将视频拼接在一起:

AVMutableVideoCompositionLayerInstruction *passThroughLayer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];

我还使用 animationLayer 将带有文本和图像的 CALayer 添加到合成中。

一开始,我使用insertEmptyTimeRange添加了5秒的空来插入标题。

到目前为止,一切正常。

现在我想再次使用 insertEmptyTimeRange 在视频末尾添加一些 «nothing»,但失败得很惨。

CMTime creditsDuration = CMTimeMakeWithSeconds(5, 600);

    CMTimeRange creditsRange = CMTimeRangeMake([[compositionVideoTrack asset] duration], creditsDuration);

    [compositionVideoTrack insertEmptyTimeRange:creditsRange];
    [compositionAudioTrack insertEmptyTimeRange:creditsRange];

    NSLog(@"credit-range %f from %f", CMTimeGetSeconds(creditsRange.duration), CMTimeGetSeconds(creditsRange.start));
    NSLog(@"Total duration %f", CMTimeGetSeconds([[compositionVideoTrack asset] duration]));

insert-points 是正确的(第一个 NSLog),但总持续时间不会延长...

知道我哪里做错了吗?

事实证明,似乎不可能在 AVMutableComposition 的末尾添加一个空的时间范围。

这个答案救了我一命:AVMutableComposition of a Solid Color with No AVAsset