Swissdude
Swissdude

Reputation: 3556

insertEmptyTimeRange to AVMutableCompositionTrack not working

I'm stitching videos together in an AVMutableCompositionTrack, using this:

AVMutableVideoCompositionLayerInstruction *passThroughLayer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];

I'm also adding a CALayer with text and images to the composition, using an animationLayer.

At the beginning, I add 5 seconds of nothing to insert a title using insertEmptyTimeRange.

Up to here, everything's working fine.

Now I want to add some «nothing» to the end of the video, using insertEmptyTimeRange again - but that fails miserably.

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]));

The insert-points are correct (first NSLog), but the total duration won't get extended...

Any ideas what I could be doing wrong?

Upvotes: 3

Views: 1219

Answers (1)

Swissdude
Swissdude

Reputation: 3556

Turns out, it seems to be impossible to add an empty timerange to the end of an AVMutableComposition.

This answer saved my life: AVMutableComposition of a Solid Color with No AVAsset

Upvotes: 1

Related Questions