IOS: how to convert video files to NSData

I want to post a video on my iPhone to my Google Drive. I already did with the images, but with the video, this is another problem ...

There is no problem for images, I convert my asset to NSData using this method:

data = UIImagePNGRepresentation(result!)! 

And I put the image on my disk!

But, for the video, I tried many different ways, but no, I can’t.

How can i do this?

Thanks a lot!

+9
source share
2 answers

I did it!

This solution:

  PHCachingImageManager().requestAVAssetForVideo(asset, options: nil, resultHandler: {(asset: AVAsset?, audioMix: AVAudioMix?, info: [NSObject : AnyObject]?) in dispatch_async(dispatch_get_main_queue(), { let asset = asset as? AVURLAsset var data = NSData(contentsOfURL: asset.URL) }) }) 

And after that, you have a nice NSData variable that you can use to put your video in the cloud!

+21
source

Please add Bellow solution its work for me

if you skip option.isNetworkAccessAllowed = true, you will get an error message for the shared URL.

 private let options: PHVideoRequestOptions = PHVideoRequestOptions() option.isNetworkAccessAllowed = true PHImageManager.default().requestAVAsset(------- 
0
source

All Articles