Avoid Video Compression when Selecting Movie with UIImagePickerController?
Asked Answered
O

5

19

I'm using UIImagePickerController to allow my user to select a video from the asset library.

When the user selects the "Choose" button on the second screen, the view displays a progress bar and a "Compressing Video..." message.

Why is this happening?

Is there some way I can avoid this compression operation?

Odor answered 1/7, 2010 at 15:5 Comment(4)
Still haven't found a solution to this. Anyone have any ideas?Odor
Take a look at my answers below. It doesn't look like developers can affect the compression.Mlle
Avalanchis -- this was answered 2 years ago. Possible to get an accept?Mlle
I'm having the same problem. Does anyone know if there is another way to import the video without using UIImagePickerController - to avoid the compression?Chouest
M
15

Answer: There is currently no way to control how UIImagePickerController compresses the picked video.

I just did some quick tests. Using a test app I created, I picked the same video two times -- once with the videoQuality property set to UIImagePickerControllerQualityTypeHigh and once with it set to UIImagePickerControllerQualityTypeLow. The resulting files that were copied over are exactly the same size, 15.1MB with a frame size of 360x480. The original was 72.5MB with a frame size of 480x640. Apparently this property doesn't affect the compression used at all.

Mlle answered 5/5, 2011 at 5:29 Comment(4)
Is there any news about this? Would really appreciate that the users didnt have to wait for the "compressing" dialog when picking video to be uploaded.Starfish
I agree. Your best bet is to file a radar with Apple.Mlle
Well it's a year later now and nothing has changed - iOS 6 still does not allow for importing the media URL directly :(Attainture
@Answerbot I totally agree. I also tried other qualities and it doesn't affect the result at all.Borecole
I
4

Set the videoQuality property of the UIImagePickerController to "High" (UIImagePickerControllerQualityTypeHigh = 0)

From the SDK documentation: "If displaying a recorded movie in the image picker, specifies that you do not want to reduce the video quality of the movie."

http://developer.apple.com/iphone/library/documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/doc/c_ref/UIImagePickerControllerQualityType

Imprecise answered 26/7, 2010 at 17:16 Comment(5)
Looks like on the iPhone 4 it will still compress even when set to "High" but the quality is much better then the default. I can see why they would compress at "High" since the original 720p video is encoded at more then 10 Mbit/sec!Imprecise
I have similar findings, even setting it to High results in some compression (and the 'Compressing Video' dialog).Mathison
In the docs for UIImagePickerControllerQualityTypeHigh the last line says: "If displaying a recorded movie in the image picker, specifies that you do not want to reduce the video quality of the movie.". This seems to indicate that for picking videos (rather than recording) this property affects how they are displayed in the image picker's edit screen.Mlle
I just did some quick tests. I picked the same video two times -- once with QualityTypeHigh and once with QualityTypeLow. The resulting files that were copied over are exactly the same size, 15.1MB with a frame size of 360x480 while the original was 72.5MB with a frame size of 480x640. Apparently this property doesn't affect the compression used at all.Mlle
Having the same problem on iPhone 4S. 1080p video is compressed to 720p. Does anyone know if this happens on iPhone 5 as well?Frantz
B
4

Since there is no way yet to avoid compression using UIImagePickerController, I wanted to include some ideas of how you can create your own image picker that will avoid compression.

This will allow access to the raw video files:

iOS 8

PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:nil];
for (PHAsset *asset in assetsFetchResult) {
    PHVideoRequestOptions *videoRequestOptions = [[PHVideoRequestOptions alloc] init];
    videoRequestOptions.version = PHVideoRequestOptionsVersionOriginal;

    [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:videoRequestOptions resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
        // the AVAsset object represents the original video file
    }];
}

Look at the PhotoKit documentation for accessing collections (moments) and other options.

Here is a sample app from Apple using PhotoKit that could be modified to be a photo picker: https://developer.apple.com/library/ios/samplecode/UsingPhotosFramework/Introduction/Intro.html

Here is a photo picker library on GitHub that uses PhotoKit that looks promising since it gives you the PHAsset objects for all the selected images/videos: https://github.com/guillermomuntaner/GMImagePicker

iOS 7 and below

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    if (group) {
        // If you want, you can filter just pictures or videos
        // I just need videos so I do this:
        [group setAssetsFilter:[ALAssetsFilter allVideos]];

        [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
            if (asset){
                // You can now add this ALAsset in your own video picker.
                // Note that you can only access the ALAsset as long as 
                // you maintain a reference to the ALAssetsLibrary

                // Or if you want to process the video, you can create an AVAsset:
                NSURL *url = asset.defaultRepresentation.url;
                AVAsset *videoAsset = [AVAsset assetWithURL:url];
            }
        }];
    }
} failureBlock:^(NSError *error) {
    NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}];
Brusque answered 23/11, 2015 at 19:19 Comment(0)
C
2

Starting from iOS 11, you can specify the videoExportPreset and set it to AVAssetExportPresetPassthrough:

picker.videoExportPreset = AVAssetExportPresetPassthrough

This will still show the "compressing" progress bar though, but will be much faster, especially for smaller videos.

Comestible answered 24/1, 2019 at 4:12 Comment(0)
I
0

For those giving the advice to use the videoQuality property, documentation is clearly stating that it is a video capture option, not a picker option.

As Jack is mentioning it below, it is also for transcoding. Looks like I read the doc too quickly because I didn't notice the transcoding mention.

Interregnum answered 7/11, 2014 at 10:8 Comment(1)
The documentation says "The video recording and transcoding quality."Market

© 2022 - 2024 — McMap. All rights reserved.