2014-06-16 115 views
0

我正在開發目標C中的iOS應用程序。在多個分區中分割視頻

根據我的要求,我想將視頻分成多個部分。

假設我有一個50秒的視頻,我想分成5份,每份10秒。

如果你們有任何想法,請指教我。

+0

可能[this] [1]幫助你分割視頻在多個部分。 [1]:http://stackoverflow.com/questions/13987357/split-a-movie-into-two-parts-an-then-concatenate-one-of-the-movie-with-另一個-m的 – Raj

回答

0

尼斯Question.The的解決方案是在這裏...在viewDidLoad方法

-(void)splitSecondVideo 
{ 
if (did<splitdivide){ 

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:_videourl options:nil]; 

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:asset presetName:AVAssetExportPresetHighestQuality]; 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *myPathDocs; 
CMTime starttime; 
CMTime duration; 

    myPathDocs = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"SplitFinalVideo%d.mov",did]]; 
    double endt=CMTimeGetSeconds([asset duration]); 
    NSLog(@"All Duration : %f",endt); 
    double divide=CMTimeGetSeconds([asset duration])/splitdivide; 
    NSLog(@"All Duration : %f",divide); 

    starttime = CMTimeMakeWithSeconds(divide*did, 1); 
    duration = CMTimeMakeWithSeconds(divide, 1); 

NSFileManager *fileManager=[[NSFileManager alloc]init]; 
NSError *error; 
if ([fileManager fileExistsAtPath:myPathDocs] == YES) { 
    [fileManager removeItemAtPath:myPathDocs error:&error]; 
} 

exportSession.outputURL = [NSURL fileURLWithPath:myPathDocs]; 
exportSession.shouldOptimizeForNetworkUse = YES; 
exportSession.outputFileType = AVFileTypeQuickTimeMovie; 
// Trim to half duration 

CMTimeRange secondrange = CMTimeRangeMake(starttime, duration); 

exportSession.timeRange = secondrange; 
[exportSession exportAsynchronouslyWithCompletionHandler:^(void) 
{ 
    [self exportDidFinish:exportSession]; 
    did++; 

    [self splitSecondVideo]; 

}]; 

}} 

- (void)exportDidFinish:(AVAssetExportSession*)session { 
if (session.status == AVAssetExportSessionStatusCompleted) { 
    NSURL *outputURL = session.outputURL; 
    NSLog(@"Before Exported"); 
    [self SaveVideoAtPathWithURL:outputURL]; 
}} 

其中做= 0.0。 & splitdivide是您想要創建視頻部分的值。在您的問題splitdivide = 5; 注意:確實&拆分均爲整數值

希望這是有幫助的....享受...