我已从多个分割(2mb)中的服务器下载40mb视频文件。我正在使用NSURLConnection
我希望将20分割为单个视频文件。怎么做是有iphone框架中的任何API可以有人用代码解释我。
这是我的connectionDidFinishLoading方法
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *fileName = [NSString stringWithFormat:@"%@",
filePath];
[contentData writeToFile:fileName atomically:YES];
}
如果我这样写,我只得到最后一个分割文件。我的意思是2mb数据只有一个指导我如何做到这一点?
答案 0 :(得分: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];
答案 1 :(得分:-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)];
}