0

I am trying to record slow motion video I have used AVCaptureSession to record the video at 240 fps and for slow motion effect I am using scaleTimeRange:

here is the code:

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

but the output is not like iOS native slow motion camera how to improve the smoothness quality.

  • Possible duplicate of [How to do Slow Motion video in IOS](https://stackoverflow.com/questions/17296999/how-to-do-slow-motion-video-in-ios) – Kuldeep Mar 20 '19 at 09:12
  • @Kuldeep I followed that but the result was not upto the mark the smoothness was missing so i am seeking is there any other way to do it – Harsh Srivastava Mar 20 '19 at 09:53

0 Answers0