Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios swift中的视频文件压缩_Ios_Swift_Video_Ffmpeg_Lossless Compression - Fatal编程技术网

Ios swift中的视频文件压缩

Ios swift中的视频文件压缩,ios,swift,video,ffmpeg,lossless-compression,Ios,Swift,Video,Ffmpeg,Lossless Compression,我正在录制一段视频,并将其转换为base64字符串以发送到服务器。但上传视频需要花费大量时间。 是否有可与swift一起使用的压缩库。 我尝试桥接ffmpeg,但这会造成很多文件丢失的问题。AVURLAsset不适合我。 关于如何压缩音频和视频文件的任何建议 func imagePickerControllerDidCancel(picker: UIImagePickerController) { self.imagePickerController.dismissViewCon

我正在录制一段视频,并将其转换为base64字符串以发送到服务器。但上传视频需要花费大量时间。 是否有可与swift一起使用的压缩库。 我尝试桥接ffmpeg,但这会造成很多文件丢失的问题。AVURLAsset不适合我。 关于如何压缩音频和视频文件的任何建议

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)
        }
    }

如果您现在还没有在swift中得到答案,请参考此答案