2014-07-15 42 views
0

我有一個錄製的視頻,我想將它作爲一個新的視頻以1.5的播放速度(快進)保存在ios sdk中。任何人都可以請建議我如何實現這一功能?在iOS中以1.5的播放速度保存視頻sdk

感謝 Yashesh

+0

你有沒有解決這個問題? –

+0

@Michel nope.but如果你有任何的參考或例子,請與我分享。 – Yashesh

+0

我打算做一個需要完成的項目。它可能會是一個緩慢的過程,但我現在可以想象的唯一事情是從原始幀到幀(將每個幀轉換爲關鍵幀),並將一些幀留在重複幀中。但我認爲這不可能是正確的。在開始編碼任何東西之前,我需要更多地考慮它。這似乎並不那麼容易,因爲這在開源視頻工具包中甚至在商業版本中都不可用。 –

回答

0

入住這

NSBundle *bundle = [NSBundle mainBundle]; 
    NSString *moviePath = [bundle pathForResource:titleOfButton ofType:@"mov"]; 
    NSURL *movieURL = [ NSURL fileURLWithPath:moviePath]; 

    MPMoviePlayerController *themovie = [[MPMoviePlayerController alloc]initWithContentURL: movieURL]; 
    [themovie play]; 
    [themovie setCurrentPlaybackRate:2.f]; 
+0

上面的代碼將播放2.0播放速度的視頻,我想以2.0播放速率保存該視頻。我怎樣才能做到這一點 ? – Yashesh

+0

我從照片庫獲取視頻..並採取了一些範圍的按鈕,給定的範圍像2x,-2x,4x,-4x ..我可以播放視頻與這一切vedio所有範圍,但我的要求是,如果我選擇-2x範圍並點擊完成按鈕將獲得只有-2倍的視頻範圍..這意味着我想保存它並從那得到..如何我可以這樣做..請任何機構回覆我..我一直在尋找從manydays –

2
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]; 
+0

加油!不錯的工作! – zszen