In my app users records videos and upload it on their youtube channels. I have notice that for a video of 4 seconds my app needs twice the time of the official Youtube app to upload a video. I'm using the ios rest Framework from google, so i think that's a difference in weight beetween my 4 seconds video and a 4 seconds video uploaded by official youtube app. So i wanna reduce my video file weight, but at the same time i wanna stay with a resolution of 1920x1080, so how i can i do it? I have to work on every single frame, to get a lower quality? I have to lower the bitrate?
My actual approch is to record a full quality video and save it as a file in documents directory. Then i retake the video to trying to compress.
I have tried:
- (void)compressVideo:(NSURL*)inputURL
outputURL:(NSURL*)outputURL2
handler:(void (^)(AVAssetExportSession*))completion {
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:urlAsset presetName:AVAssetExportPreset1920x1080];
exportSession.outputURL = outputURL2;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.shouldOptimizeForNetworkUse = YES;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
//completion(exportSession);
NSData *prima = [NSData dataWithContentsOfURL:self.outputURL];
NSLog(@"Size of new Video before compression is (bytes):%lu",(unsigned long)[prima length]);
NSData *newDataForUpload = [NSData dataWithContentsOfURL:outputURL2];
NSLog(@"Size of new Video after compression is (bytes):%lu",(unsigned long)[newDataForUpload length]);
[self performSegueWithIdentifier:@"registraToSaved" sender:nil];
}];
}
but this code itself reduce the weight only if i change the size of the video. I have read about solutions like this: How can I reduce the file size of a video created with UIImagePickerController? but they works with AssetWriter and in the library i use to record the video this object is not used. There's a way to use a similar concept with LLSimpleCamera library ? Or maybe there is a way do modify my compressVideo method to achive this result?
EDIT
this is the way i have tested the upload. I can record video directly in my app (using LLSimpleCamera library), so : record a 4 seconds video by my app -> upload to youtube by my app and google rest library . To make a match with the official youtube app i have recorded the same subject for 4 seconds by youtube app and then , always by youtube app, i have uploaded to my channel. Probably those two recorded video have not the same exact weight, but the difference are surely minimal. Anyway the upload time with my app is very long , so i have started to think that youtube create a smaller file for a 4 seconds recorded video 1920x1080 than my app