1

Currently I am in a big problem, I'm using AssetsPickerViewController to get images and videos from the gallery to later upload it to the server in a web query.

AssetsPickerViewController: https://github.com/DragonCherry/AssetsPickerViewController

My problem is that when I get the data from the video to upload it to the server, it is too big, a video of about 30 seconds has a weight of more than 50MB which I think is the reason for the error:

Connection to assetsd was interrupted or assetsd died
Message from debugger: Terminated due to memory issue

I think the way I could solve this problem would be to reduce the weight of the video but I still can not find how to do it.

I thank you in advance for your help.

Angel
  • 402
  • 3
  • 8
  • To reduce the overall file size of a video you would need to transcode it on the device using AVFoundation. You can reduce the quality of the video, frame rate, frame size, adjust audio/video quality seperately etc. When I last done it I created a 'high' resolution video (lower resolution than the recording) and uploaded that. then on the server I created medium and low quality versions too – Scriptable Mar 21 '18 at 14:41
  • Thanks for your comment Scriptable, it seems to be a good proposal, could you give me an example on the internet about how to use AVFoundation to reduce the weight of the video? – Angel Mar 21 '18 at 14:52
  • There are quite a few but most show the code in objective-c https://stackoverflow.com/questions/11751883/how-can-i-reduce-the-file-size-of-a-video-created-with-uiimagepickercontroller you could also reference this library. https://github.com/NextLevel/NextLevel – Scriptable Mar 21 '18 at 14:58

1 Answers1

2

It sounds to me like you're trying to load the entire video into memory before you upload it, which is a bad idea for large files. One alternative would be to use a URLSessionUploadTask, which uses a file URL instead of raw data:

let videoFileURL = <get a file URL>
let request = URLRequest(url: URL(string: "https://mygreatsite.com")!)
URLSession.shared.uploadTask(with: request, fromFile: videoFileURL) { data, response, error in
    // handle
}.resume()
dalton_c
  • 6,876
  • 1
  • 33
  • 42
  • This is a good suggestion for handling large files, but there are good reasons that the OP (and eventually the user) might strongly prefer to reduce the file size before sending it to the server. – Caleb Mar 21 '18 at 14:45
  • Thank you very much for your answer, I think it's a good method to try to solve my problem, I just have a question, on the server maybe using PHP, how can I get the data? Since with uploadTask I do not observe parameters with which to identify variables later – Angel Mar 21 '18 at 14:48