2014-06-16 66 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; 注意:确实&拆分均为整数值

希望这是有帮助的....享受...