2014-06-16 2 views
0

목적 C에 iOS 응용 프로그램을 개발 중입니다.다중 분할로 비디오 분할

필자의 요구 사항에 따라 비디오를 여러 부분으로 나누고 싶습니다.

나는 50 초의 비디오를 가지고 있고, 10 초씩 5 부분으로 나누고 싶다고 가정 해 보겠습니다.

혹시 의견이 있으시면 알려주세요.

+0

동영상을 여러 부분으로 나눌 수 있습니다. [1] : http://stackoverflow.com/questions/13987357/split-a-movie-into-two-parts-an-then-concatenate-one-of-the-movie-with- 또 다른 m – Raj

답변

0

좋은 지적입니다 솔루션은 ... 여기있는 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; 참고 : & 분할 나누기는 모두 정수 값입니다.

희망 ... 즐겨 ... ...