Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid compression after selecting video from UIImagePickerController in ios

Tags:

I am using UIImagePickerController to select video from Gallery and it compress that video.I want to disable Compression but I don't find the way to do this. I also tried with ELCImagePickerController it is showing video but it is looking like an image only there is no video icon or time duration like it shows in UIImagePickercontroller.How can I do it?

Thanks.

like image 423
DeviPhone26 Avatar asked Nov 25 '13 11:11

DeviPhone26


People also ask

How do I stop my iPhone from compressing videos?

How do I stop my iPhone from compressing videos 2021? To reduce the resolution and frame rate that your capture device uses for recording video, go to Settings > Camera > Record Video, as well as Settings > Camera > Record Slo-mo.

Does iPhone automatically compress videos?

The iPhone and iPad have incredible cameras. They take amazing videos, but did you know that iOS automatically compresses the video files (reduce quality) before it lets you upload to a website or transfer to another device? It does this because most of the time users don't need or want the highest quality videos.

Why does my video get compressed?

Compression is directly related to file size; smaller files will have less quality. Because so much video content is uploaded to YouTube, they have to heavily compress videos in order to still be able to provide the storage and bandwidth needed.

Does compressing lose video quality?

Although video compression shrinks files, it may also impact video quality. Video encoding, however, compresses your video files without compromising quality. With encoded videos, the gigabytes of data become mere megabytes. And your content becomes compatible with many devices and platforms.


2 Answers

With iOS 11 you can set the property videoExportPreset to AVAssetExportPresetPassthrough to get the original:

if #available(iOS 11.0, *) {     picker.videoExportPreset = AVAssetExportPresetPassthrough } 

The "Video compression..." label just flashes for a few milliseconds and then the export is done.

@Diego Renau almost had the correct answer.

like image 120
Jan Avatar answered Oct 13 '22 06:10

Jan


It doesn't look like it's possible to avoid compression using the UIImagePickerController. See this answer:

https://stackoverflow.com/a/5893066/406152

I've tried using imagePicker.videoQuality = UIImagePickerControllerQualityTypeHigh; but it still does compression. Ugh.

EDIT:

However, you can roll your own. 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); }]; 
like image 22
jDutton Avatar answered Oct 13 '22 07:10

jDutton