ios - 在iOS SDK中以1.5播放速度保存视频

标签 ios xcode video video-processing playback

我有一个录制的视频,我想将其另存为ios sdk中具有1.5播放速度(快进)的新视频。谁能建议我如何实现此功能?

谢谢
亚什什

最佳答案

AVURLAsset* videoAsset = nil; //self.inputAsset;

//create mutable composition
AVMutableComposition *mixComposition = [AVMutableComposition composition];

AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
                                                                               preferredTrackID:kCMPersistentTrackID_Invalid];
NSError *videoInsertError = nil;
BOOL videoInsertResult = [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
                                                        ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
                                                         atTime:kCMTimeZero
                                                          error:&videoInsertError];
if (!videoInsertResult || nil != videoInsertError) {
    //handle error
    return;
}

//slow down whole video by 2.0
double videoScaleFactor = 2.0;
CMTime videoDuration = videoAsset.duration;

[compositionVideoTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero, videoDuration)
                           toDuration:CMTimeMake(videoDuration.value*videoScaleFactor, videoDuration.timescale)];

//export
AVAssetExportSession* assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition
                                                                     presetName:AVAssetExportPresetLowQuality];

关于ios - 在iOS SDK中以1.5播放速度保存视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24752214/

相关文章:

c# - 在 Xamarin 中绑定(bind) PayPalMobile iOS 库

ios - NSTimer 无法在 NSThread 函数中启动或运行?

ios - 为 SKSpriteNode 子类创建初始化程序

iphone - XCode iPhone OS 部署目标工具

node.js - 使用 nodejs 具有音频录制功能的视频和音频混合器

video - FFmpeg 缩放不是平滑居中(而是锯齿形)

ios - 自动布局 : Align two button side by side and move to right side when there is no image

xcode - 文件 <myproject>.xcodeproj 不存在

ios - 使用 Xcode 7.1 的 iOS 9 中的 NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813)

html - 使用 HTML5 视频标签播放视频