0

我正在尝试录制慢动作视频,我使用 AVCaptureSession 以 240 fps 录制视频,对于慢动作效果,我使用 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原生慢动作相机如何提高平滑质量。

4

0 回答 0