2013-04-24 1 views
3

나는 아래의 코드를 사용하여 ALAssets 라이브러리에서 비디오 데이터에 액세스하려고ALAssets 얻을 비디오 데이터

 ALAssetRepresentation *rep = [asset defaultRepresentation]; 
     Byte *buffer = (Byte*)malloc(rep.size); 
     NSError *error = nil; 
     NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:&error]; 
     NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES]; 

큰 영상을 얻기 위해 노력하고 있다면 그것은 작은 비디오뿐만 아니라 사진에 잘 작동, 단, 코드로 인해 캐치되지 않는 예외 'NSInvalidArgumentException'응용 프로그램 종료, 이유는

*

말을 충돌하는 '* - [NSConcreteData initWithBytes : 길이 : 사본 : freeWhenDone : bytesAreVM :] : 터무니없는 길이 : 4294967295, 최대 크기 : 2147483648 바이트 '

나는 무슨 일이 일어나고 있는지 알지 못합니다. 어떤 생각이라도?

미리 감사드립니다.

+0

예외가 발생할 때 rep.size의 값은 무엇입니까? – RegularExpression

+0

값은 522523356입니다. – Advaith

답변

1

해결책을 찾았습니다. 데이터를 버퍼링하기 때문에 대용량 파일을 업로드 할 때 크래시가 막대한 메모리 증가로 인한 것일 수 있습니다. 이제 파일 데이터를 5MB 덩어리로 읽었으며 충돌이 수정되었습니다. 아래 코드를 붙여 넣습니다.

- (NSData *)getDataPartAtOffset:(NSInteger)offset { 
__block NSData *chunkData = nil; 
if (fileAsset_){ 
    static const NSUInteger BufferSize = PART_SIZE; // 5 MB chunk 
    ALAssetRepresentation *rep = [fileAsset_ defaultRepresentation]; 
    uint8_t *buffer = calloc(BufferSize, sizeof(*buffer)); 
    NSUInteger bytesRead = 0; 
    NSError *error = nil; 

    @try 
    { 
     bytesRead = [rep getBytes:buffer fromOffset:offset length:BufferSize error:&error]; 
     chunkData = [NSData dataWithData:[NSData dataWithBytesNoCopy:buffer length:bytesRead freeWhenDone:NO]]; 
    } 
    @catch (NSException *exception) 
    { 
     free(buffer); 
     chunkData = nil; 
     // Handle the exception here... 
    } 

    free(buffer); 
} else { 
    NSLog(@"failed to retrive Asset"); 
} 
return chunkData; 

}

그리고 내가

int offset = 0; // offset that keep tracks of chunk data 

    do { 
     @autoreleasepool { 
      NSData *chunkData = [self getDataPartAtOffset:offset];; 

      if (!chunkData || ![chunkData length]) { // finished reading data 
       break; 
      } 

      // do your stuff here 

      offset +=[chunkData length]; 
     } 
    } while (1); 
관련 문제