1

Program: I am currently using an UIImagePickerController that lets the user select a video on their device. It then retrieves the URL for the video and stores it.

Problem: When a user selects a video, it compresses the video. How can I disable the compressing part? Because I am only interested in the url, and if the video is large it takes a long time.

I found this answer - https://stackoverflow.com/a/48643954/9764182

However, for me the "VideoExportPreset" property takes a string.

Code: I don't think my code will be helpful, I do have a function that is subscribed to the finished picking event of the picker. However, the compression happens before that event is fired.

MediaPicker = new UIImagePickerController();
MediaPicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
MediaPicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary);
MediaPicker.ImageExportPreset = UIImagePickerControllerImageUrlExportPreset.Current;
MediaPicker.VideoQuality = UIImagePickerControllerQualityType.High;
MediaPicker.FinishedPickingMedia += Handle_FinishedPickingMedia;
MediaPicker.Canceled += Handle_Canceled;
t3ch3
  • 71
  • 11

1 Answers1

4

AVAssetExportSessionPreset provides a convenience enum that you can use to get the NSString from and then you can convert it to a C# string.

Example:

var MediaPicker = new UIImagePickerController
{
    ~~~~
    VideoExportPreset = AVAssetExportSessionPreset.Passthrough.GetConstant().ToString(),
    ~~~~
};
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • Hi, thank you for the answer and explanation, it has reduced the compression time by a lot! Do you know if there is anyway to disable it all together? – t3ch3 Jul 25 '18 at 12:36
  • @t3ch3 Passthrough is the fastest, if it is still encoding something, make sure that you are not setting *other* properties that might be causing iOS to do something to the file. – SushiHangover Jul 25 '18 at 12:41
  • It definitely reduced the time of the compression progress bar, however, on iOS 12.1 > the file appears to have the codec changed. I have 3 ios devices, one of which runs iOS 11.3. The video can still be played on Windows or Android, however, setting the VideoExportPreset to Passthrough doesn't work when playing the video on Windows 10 or Android. I wish I could read a deep dive somewhere on apple documentation regarding what exactly happens behind the scenes by setting the export to passthrough. – gcadmes Jan 31 '20 at 15:06
  • @gcadmes Did you check the container format, I'm "assuming" you are now getting a `hvc1`-based mpeg file. – SushiHangover Jan 31 '20 at 15:49
  • @SushiHangover I didn't check the container format. Is there an API for that? How can I check? – gcadmes Feb 07 '20 at 14:41