Swift Can Not Save .M3U8 File to Gallery

swift can not save .m3u8 file to gallery

M3U8 is an audio/video playlist file and it cannot be saved to the gallery.

m3u8 file AVAssetImageGenerator error

You won't be able to get still images for a live stream using AVAssetImageGenerator. Instead, you can use

AVPlayerItemVideoOutput

With AVPlayerItemVideoOutput you can get an image that is appropriate to display at a specified time for a given .m3u8 stream using the following method: - (CVPixelBufferRef)copyPixelBufferForItemTime:(CMTime)itemTime itemTimeForDisplay:(CMTime *)outItemTimeForDisplay Then, you can convert the returned CVPixelBufferRef into an image (or other) for display.

Load image form Gallery in swift from path given by UIImagePickerViewController?

Save image in Document Directory taken from Gallery or Camera.

 func origionalImage(origionalImage: UIImage!, editedImage: UIImage!, userInfo info: [NSObject : AnyObject]!) {

let imageData = NSData(data:UIImagePNGRepresentation(origionalImage)!)
let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let docs: String = paths[0]

let imageName = self.randomStringWithLength(6) as String
//imageName can save in sqlite to load image later
let fullPath = String("\(docs)/\(imageName).png")
print(fullPath)
let result = imageData.writeToFile(fullPath, atomically: true)
print("FILE WRITTEN SUCCESS=>:\(result)")
}

Load Image from Database

        let tempDBObject = self.petListArray[indexPath.row] as! Database
cell?.petName.text = tempDBObject.Hname
//Doc Path
let documentDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first! as String
let imagePath = String("\(documentDirectory)/\(tempDBObject.Hpath!)")
if imagePath == "" {
}else{
cell?.petImageView.image = UIImage(contentsOfFile: imagePath)
}

How can I capture an image when AVPlayer playing m3u8 stream?

AVAssetImageGenerator may require local assets. Maybe you'd have more luck adding an AVPlayerItemVideoOutput to your AVPlayer, seeking to the desired spot and calling copyPixelBufferForItemTime:itemTimeForDisplay: on the videoOutput.

Can we manually download/cache the transport stream while streaming m3u8 file

Something similar has been implemented here: https://github.com/StyleShare/HLSCachingReverseProxyServer

It downloads the segments while streaming, if the segment is available locally, it will use that instead.



Related Topics



Leave a reply



Submit