압축 된 비디오 데이터에 문제가 있습니다 (비디오 데이터는 ALASSET에서 가져옴). 서버에 업로드하기 전에 비디오 데이터를 압축하고 싶습니다. 나는 낮은 품질로 변환하기 위해 아래의 함수를 찾았으나 출력은 NSDATA가 아닌 NSURL입니다. 업로드하기 전에 비디오의 NSData를 어떻게 압축 할 수 있습니까?iOS에서 업로드하기 전에 비디오 데이터를 압축하는 방법
이 내 업로드 기능입니다 :
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] (http://stackoverflow.com/questions/4960375/accessing-local-file-using-nsurl)을 'outputURL :'값으로 전달한 다음 파일을 NSData 인스턴스에로드 하시겠습니까? – aroth
@aroth : 예제 코드를 작성할 수 있습니까? 감사합니다 – user3214941
@ user3214941 좋은 해결책을 찾았습니까? 나는 같은 문제에 직면하고있다. – FabKremer