【发布时间】:2014-04-04 00:20:45
【问题描述】:
我在压缩视频数据中遇到问题(视频数据来自 ALASSET)。我想在上传到服务器之前压缩视频数据。我发现以下用于转换为低质量的函数,但输出是 NSURL 而不是 NSDATA。如何在上传之前压缩视频的 NSData。
这是我的上传功能:
ALAsset *alasset = [allVideos objectAtIndex:i];
ALAssetRepresentation *rep = [alasset defaultRepresentation];
NSString * videoName = [rep filename];
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
这是转换函数:
- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL
outputURL:(NSURL*)outputURL
handler:(void (^)(AVAssetExportSession*))handler
{
[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
exportSession.outputURL = outputURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
{
handler(exportSession);
[exportSession release];
}];
}
【问题讨论】:
-
为什么不直接将file-url 作为
outputURL:值传递,然后将文件加载到您的NSData实例中? -
@aroth:你能举例代码吗?谢谢
-
@user3214941 你找到一个好的解决方案了吗?我也面临同样的问题
标签: ios objective-c cocoa-touch video alassetslibrary