Search code examples
iphoneiosvideouiimagepickercontrolleralasset

ALAsset Video Compression


I've looked through SO and couldn't find a working answer for this question. I have created a custom image picker using ALAssets, but now that it's not the regular imagepicker there is no auto-compression of video.

This is how I am getting the video NSData from the asset:

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

Now the problem is, when I choose a large video file, the app crashes, because it receives memory warnings. Is there anyway to compress the video or even trim so the video file wouldn't be so large?


Solution

  • I had the same problem with large videos. You should repeatedly copy just a small amount of bytes into the buffer from the asset and append it into the video data.