2

I m recording a video and converting it to base64 string to send it to server.But uploading of video is taking a lot of time. Is there any compression library that can be used with swift. I tried bridging ffmpeg but that is creating a lot of issue of missing files. AVURLAsset is not working for me. Any suggestions on how to compress audio and video files.

func imagePickerControllerDidCancel(picker: UIImagePickerController) {
        self.imagePickerController.dismissViewControllerAnimated(true, completion: nil)
    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        let mediaType = info[UIImagePickerControllerMediaType] as! NSString
        self.imagePickerController.dismissViewControllerAnimated(true) {
            // 3
            if mediaType == kUTTypeMovie {

                guard let path = (info[UIImagePickerControllerMediaURL] as! NSURL).path else { return }

                if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(path) {
                    UISaveVideoAtPathToSavedPhotosAlbum(path,    self, #selector(GalleryView.video(_:didFinishSavingWithError:contextInfo:)), nil)

                }
            }else{
                //Image
                let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
                let imageData:NSData = UIImageJPEGRepresentation(selectedImage,0.5)!
                var strBase64:String = imageData.base64EncodedStringWithOptions(.EncodingEndLineWithLineFeed)
                strBase64 = strBase64.stringByReplacingOccurrencesOfString("+", withString: "%2B")
                self.uploadGalleryDataInServer("1", ext: "jpeg", content: strBase64)
            }
        }
    }

    func video(videoPath: NSString, didFinishSavingWithError error: NSError?, contextInfo info: AnyObject) {
        if let _ = error {
        }else{
           print("videoPath = \(videoPath)")
            let data = NSData(contentsOfFile: videoPath as String)

            var strBase64:String = NSData(contentsOfFile: videoPath as String)!.base64EncodedStringWithOptions(.EncodingEndLineWithLineFeed)
            strBase64 = strBase64.stringByReplacingOccurrencesOfString("+", withString: "%2B")


            self.uploadGalleryDataInServer("2", ext: ".mp4", content: strBase64)
        }
    }
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
iosDev_1205
  • 778
  • 1
  • 9
  • 23

0 Answers0