Reputation: 1002
Im using LLSimpleCamera to capture video in my app:
https://github.com/omergul123/LLSimpleCamera
It works great! I love it, however, I'm also using Parse as my backend and the max file size is 10MB. This shouldn't be a problem because the videos I'm capturing as an AVSession are all under 10 seconds so it shouldn't be that large.
Is there a way to compress video or is there something in the LLSimple camera i'm not seeing that's creating this video to be so large.
For example my 4 second videos are resulting in PFFile's larger than 10 MB like 10.6 MB!
Heres the code im using with that LLSimpleCamera library to upload it:
- (void)uploadMessage {
NSData *fileData;
NSString *fileName;
NSString *fileType;
fileData = [NSData dataWithContentsOfURL:self.videoUrl];
fileName = @"video.mov";
fileType = @"video";
NSLog(@"filesize = %@",[NSByteCountFormatter stringFromByteCount:fileData.length countStyle:NSByteCountFormatterCountStyleFile]);
float fileSize = (float)fileData.length;
NSLog(@"filesize = %f", fileSize);
if(fileSize <= 10485760) {
PFFile *file = [PFFile fileWithName:fileName data:fileData];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An error occurred!"
message:@"Please try sending your message again."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else {
PFObject *message = [PFObject objectWithClassName:@"Scenes"];
[message setObject:file forKey:@"file"];
[message setObject:fileType forKey:@"fileType"];
[message setObject:[[PFUser currentUser] objectId] forKey:@"userId"];
[message setObject:[[PFUser currentUser] username] forKey:@"userName"];
[message setObject:[[PFUser currentUser] objectForKey:@"loggedInVenueId"] forKey:@"venueId"];
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An error occurred!"
message:@"Please try sending your message again."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else {
// Everything was successful!
}
}];
}
}];
}else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Video too big!"
message:@"Please try sending your message again."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
[self.navigationController popViewControllerAnimated:YES];
}
Upvotes: 3
Views: 498
Reputation: 2717
I have written my own Camera library before and my apps upload long video files on Parse, all of them below 10 MB. The trick to make sure your video files do not exceed the 10 MB limit is to control two main factors affecting video file size, namely the recording Quality and Resolution
It is quite easy to control these two main factors by setting your recording input session property documented by Apple for an AVCaptureSession
:
NSString *const AVCaptureSessionPresetPhoto;
NSString *const AVCaptureSessionPresetHigh;
NSString *const AVCaptureSessionPresetMedium;
NSString *const AVCaptureSessionPresetLow;
NSString *const AVCaptureSessionPreset320x240;
NSString *const AVCaptureSessionPreset352x288;
NSString *const AVCaptureSessionPreset640x480;
NSString *const AVCaptureSessionPreset960x540;
NSString *const AVCaptureSessionPreset1280x720;
NSString *const AVCaptureSessionPresetiFrame960x540;
NSString *const AVCaptureSessionPresetiFrame1280x720;
I think your 4 second videos which go over 10MB are full HD videos recorded with session preset set to AVCaptureSessionPresetHigh
. You better choose a lower one when you initialise LLSimpleCamera
library, for example:
[[LLSimpleCamera alloc] initWithQuality:AVCaptureSessionPresetMedium
position:CameraPositionBack
videoEnabled:YES];
Upvotes: 3