2014-03-03 2 views
2

압축 된 비디오 데이터에 문제가 있습니다 (비디오 데이터는 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]; 
    }]; 
} 
+1

[file-url] (http://stackoverflow.com/questions/4960375/accessing-local-file-using-nsurl)을 'outputURL :'값으로 전달한 다음 파일을 NSData 인스턴스에로드 하시겠습니까? – aroth

+0

@aroth : 예제 코드를 작성할 수 있습니까? 감사합니다 – user3214941

+0

@ user3214941 좋은 해결책을 찾았습니까? 나는 같은 문제에 직면하고있다. – FabKremer

답변

-3

이 완벽하게 나를 위해 노력하고 있습니다.

asset = [[AssetItem alloc] initWithURL:movieURL]; 
      NSLog(@"Start"); 
      asset.exportSession.shouldOptimizeForNetworkUse = TRUE; 
      asset.preset = AVAssetExportPresetMediumQuality; 
      asset.exportSession.outputFileType = @"public.mpeg-4"; 
      [asset exportAssetWithCompletionHandler:^(NSError *error){ 
       dispatch_async(dispatch_get_main_queue(), ^{ 
        if (error != nil) 
        { 
         UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[error localizedDescription] 
                      message:[error localizedFailureReason] delegate:self 
                    cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; 
         [alertView show]; 
        } 
       }); 
      }]; 

희망이 도움이 될 것입니다. 감사합니다. Yashesh

+0

'AssetItem'은 어떤 종류의 수업인가? 나는'AVAsset' 만 알고있다. 쓰레드 스타터와 똑같은 코드를 시도했지만 항상 "완료 할 수 없습니다"오류가 발생했습니다. 불행히도이 오류는 매우 명확하지 않습니다. – dannyyy

+0

https://developer.apple.com/library/ios/samplecode/AVMovieExporter/Listings/AVMovieExporter_AssetItem_h.html – Yashesh

+1

-1 -이 정보는 불완전합니다. 주석에 제공된 링크에서 Apple 샘플 코드를 다운로드하면 "AssetItem"은 실제로 "NSObject"의 하위 클래스입니다. – Shailesh

관련 문제