Search code examples
iosvideoavfoundationavmutablecomposition

Black frame at video end after AVMutableComposition creation


When creating an AVMutableComposition with 2 video AVMutableCompositionTrack objects displayed side by side if I trim the end or the start of the videos (so 2 different durations), I have a black frame instead of the last frame of the video when I play the final video after exporting the AVMutableVideoComposition object via a AVAssetExportSession object.

The below code show you how I insert the time range for the first video :

let start = CMTimeMakeWithSeconds(trimStart, 600)
let end  = CMTimeMakeWithSeconds(trimEnd, 600)

try videoTrack.insertTimeRange(CMTimeRangeMake(start, end), of: videoAssetTrack, at: kCMTimeZero)

Some help in order to keep the last frames displayed will be greatly appreciated


Solution

  • The second argument to CMTimeRangeMake is supposed to be a duration, but it looks like you're using a point in time. Does changing the code to CMTimeRangeMake(start, CMTimeSubtract(start, end)) help?