I am trying to select a video from UIPickerViewController, compress the video into about 1.5MB, and post it to a server.
I am already able to select an image and post successfully. I am also able to select a video and post it successfully. The problem is that since the video file is about 27MB, it is too big to playback once sent. So when trying to play back the video from the server, the time shows "--". If I select a smaller video, it will post and play back perfectly fine.
I know that the problem is size because I used another app to compress the video and then used my app to send it to the server. It worked perfectly.
I have spent over 5 hours on this problem and can't seem to figure it out myself. (Just saying that I have tried to solve it and find the answers myself)
I have tried implementing these techniques:
https://gist.github.com/daltheman/4716ec10d6d0f71aba56
https://snackcoffee.me/2015/11/29/zlib-swift-2/
IOS Video Compression Swift iOS 8 corrupt video file
and a few others that are no longer in my tabs. Some of which were in Objective-C but I couldn't seem to translate them well.
TL;DR Is there a function like UIImageJPEGRepresentation for videos in AVFoundation? Can you please post a basic code example of picking an image from UIPicker and changing its file size to 1.5MB?