Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why videos selected via UIImagePickerController high and medium settings can result in same quality attributes on the results?

Why are are videos selected with UIImagePickerController high and medium video quality settings resulting in exactly the same video attributes, at least on devices like the iPhone4 and iPad3?

Details:

We are using UIImagePickerController to let our app users pick images or videos from the photo library and then transfer them up to their servers. We let the users select the video quality of high, medium or low which we map directly to the UIImagePickerControllerQualityTypeHigh, UIImagePickerControllerQualityTypeMedium and UIImagePickerControllerQualityTypeLow videoQuality constants.

When a 10 second or so video, shot outside of our app with the camera, is picked and sent on the 3GS (iOS 5.0) we see a distinct difference with each quality setting, for example:

  • low: 226KB at 144x192, codec: AAC H.264
  • medium: 1.1MB at 360x480, codec: AAC H.264
  • high: 5MB at 480x640, codec: AAC H.264

When we try the same on the iPhone4 or iPad3 (we happen to have those devices handy; not sure it happens on only those devices) we are seeing that the low setting generates an equivalent low-res result, but the high and medium setting give us the same results, something like this:

  • low: 194KB at 144x192, codec: AAC H.264
  • medium: 2.87MB at 720x1280, codec: AAC H.264
  • high: 2.87MB at 720x1280, codec: AAC H.264

(Note that the medium and high results are identical.)

The original from the device is 12.8 MB at 720x1280, codec: AAC H.264 at a higher bit rate.

Can any explain what's going on here? I'd like to be able to explain it to our customers, even better point at something in Apple's doc that covers this.

Thanks in advance for any help...

like image 332
Chris Markle Avatar asked Apr 26 '12 21:04

Chris Markle


1 Answers

The video quality setting only applies when capture videos and not picking them from the video picker. The setting is clearly listed under the capture settings section below.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

You can use the code below to export the video in the original form. Just pass the URL value of the selected video and the function will return the path for the exported video.

+(NSString*) videoAssetURLToTempFile:(NSURL*)url
{
    NSString * surl = [url absoluteString];
    NSString * ext = [surl substringFromIndex:[surl rangeOfString:@"ext="].location + 4];
    NSTimeInterval ti = [[NSDate date]timeIntervalSinceReferenceDate];
    NSString * filename = [NSString stringWithFormat: @"%f.%@",ti,ext];
    NSString * tmpfile = [NSTemporaryDirectory() stringByAppendingPathComponent:filename];

    NSURL *outputURL = [NSURL fileURLWithPath:tmpfile];

    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
    exportSession.outputURL = outputURL;
    exportSession.shouldOptimizeForNetworkUse = YES;
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;
    [exportSession exportAsynchronouslyWithCompletionHandler:^(void) 
    {
        NSLog(@"Export Complete %d %@ %@", exportSession.status, exportSession.error, outputURL);
        [exportSession release];
    }];

    return tmpfile;
}
like image 181
washfaq Avatar answered Oct 06 '22 01:10

washfaq