Я пытаюсь записать замедленное видео. Я использовал AVCaptureSession для записи видео с частотой 240 кадров в секунду и для эффекта замедленного движения я использую scaleTimeRange:
, вот код:
AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:URl options:nil];
//create mutable composition
AVMutableComposition *mixComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
NSError *videoInsertError = nil;
NSError *audioInsertError = nil;
BOOL videoInsertResult = [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
atTime:kCMTimeZero
error:&videoInsertError];
BOOL audioInsertResult = [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
atTime:kCMTimeZero
error:&audioInsertError];
if (!videoInsertResult || nil != videoInsertError) {
//handle error
return;
}
if (!audioInsertResult || nil != audioInsertError) {
//handle error
return;
}
//slow down whole video by 3.0
double videoScaleFactor = 3.0;
CMTime videoDuration = videoAsset.duration;
[compositionVideoTrack scaleTimeRange:CMTimeRangeMake(CMTimeMake(1, videoDuration.timescale), CMTimeMake(videoDuration.value - 1, videoDuration.timescale))
toDuration:CMTimeMake(videoDuration.value*videoScaleFactor, videoDuration.timescale)];
но вывод не похож на родную замедленную камеру iOS, как улучшить качество плавности.