I'm here again looking for help with AVFoundation. Sorry for my not perfect English.
I'm programming video editor now. At first i load video from library and put it to AVAsset instance. Then, every time when user select some video area and set speed parameter there, i do something like this:
AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *track = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
[track insertTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(startOfEditedFrame, 600))
ofTrack:[self.videoAsset tracksWithMediaType:AVMediaTypeVideo][0] atTime:mixComposition.duration error:&error];
[track insertTimeRange:CMTimeRangeFromTimeToTime(CMTimeMakeWithSeconds(startOfEditedFrame, 600), CMTimeMakeWithSeconds(endOfEditedFrame, 600))
ofTrack:[self.videoAsset tracksWithMediaType:AVMediaTypeVideo][0] atTime:mixComposition.duration error:nil];
[track scaleTimeRange:CMTimeRangeFromTimeToTime(CMTimeMakeWithSeconds(startOfEditedFrame, 600), CMTimeMakeWithSeconds(endOfEditedFrame, 600))
toDuration:CMTimeMultiplyByFloat64(CMTimeMakeWithSeconds(endOfEditedFrame - startOfEditedFrame, 600), 1/[self.speeds[self.currentFrameStartIndex] floatValue])];
[track insertTimeRange:CMTimeRangeFromTimeToTime(CMTimeMakeWithSeconds(endOfEditedFrame, 600), self.videoAsset.duration)
ofTrack:[self.videoAsset tracksWithMediaType:AVMediaTypeVideo][0] atTime:mixComposition.duration error:nil];
self.videoAsset = mixComposition;
First time it's working OK, but second time i have "insertTimeRange" mistakes and zero duration of composition. Please, let me know if you have any ideas what goes wrong here or any suggestions how to do it differently/more correctly.