2

可能重复:
在 iPhone 应用程序中合并两个视频文件

我已经从服务器下载了 40mb 的视频文件,分为多个拆分(2mb)。我正在使用NSURLConnection我想将 20 分割为单个视频文件。如何做到这一点在 iphone 框架中有任何 API 可以有人用代码解释我。这是我的 connectionDidFinishLoading 方法

 - (void)connectionDidFinishLoading:(NSURLConnection *)connection {

NSString *fileName = [NSString stringWithFormat:@"%@",
                                      filePath];
[contentData writeToFile:fileName atomically:YES];

}

如果我这样写,我只有最后一个拆分文件。我的意思是 2mb 数据只有一些指导我如何做到这一点?

4

2 回答 2

1

我不确定 writeToFile 在这种情况下是否有效,

但是要以附加模式添加文件,请使用以下代码,

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:@"Notes.txt"];
NSString *savedString = textview.text;
NSFileHandle *myHandle = [NSFileHandle fileHandleForWritingAtPath:logPath];
[myHandle seekToEndOfFile];
[myHandle writeData:[savedString dataUsingEncoding:NSUTF8StringEncoding]];

删除代码,

[contentData writeToFile:fileName atomically:YES];
于 2012-09-10T11:54:18.587 回答
-1
- (void) mergeVideos{
///... after getting hold or your assets....firstAsset, secondAsset

AVMutableComposition* mixComposition = [AVMutableComposition composition];

AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo 
                                                                  preferredTracfirst:kCMPersistentTracfirst_Invalid];
[firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAsset.duration) 
                    ofTrack:[[firstAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] 
                     atTime:kCMTimeZero error:nil];

AVMutableCompositionTrack *secondTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo 
                                                                   preferredTracfirst:kCMPersistentTracfirst_Invalid];

[secondTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, secondAsset.duration)
                     ofTrack:[[secondAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] 
                      atTime:kCMTimeZero error:nil];    

[secondTrack setPreferredTransform:CGAffineTransformMakeScale(0.25f,0.25f)]; 
}
于 2012-09-10T12:28:13.497 回答