快速获取修剪过的视频的缩略图

快速获取修剪过的视频的缩略图

本文介绍了快速获取修剪过的视频的缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:
当我尝试这样做时
self.my.image = UIImage(contentsOfFile: "\(self.sharedelegate.editthumbforvideo)"),
self.my 的值.image 总是打印 nil.self.videodelegate.editthumbforvideo 数据类型是 (UIImage)my.image(UIImageview).

Here is my code:
When I try to do this
self.my.image = UIImage(contentsOfFile: "\(self.sharedelegate.editthumbforvideo)"),
the value of self.my.image is always printing nil.self.videodelegate.editthumbforvideo datatype is (UIImage) and my.image is (UIImageview).

不知道如何解决这个问题,无法获得修剪后的视频的缩略图.

Don't know how to overcome this issue and can't get thumbnail image of trimmed video.

提前致谢

            let url=NSURL(fileURLWithPath: videoPath as String)
            let asset: AVAsset = AVAsset(URL: url)
            let imageGenerator = AVAssetImageGenerator(asset: asset);
            imageGenerator.appliesPreferredTrackTransform = true

            let timestamp = CMTime(seconds: 0.0, preferredTimescale:        60)
            var actualTime : CMTime = CMTimeMake(0, 0)
            let myImage = try?( imageGenerator.copyCGImageAtTime(timestamp, actualTime: &actualTime))
            self.image=UIImage(CGImage: myImage!)
            print("my print...\(self.image)")
            self.videodelegate.editthumbforvideo = self.image
            self.my.image = UIImage(contentsOfFile: "\(self.sharedelegate.editthumbforvideo)")

推荐答案

您可以通过编写以下代码来创建缩略图,

You can create thumbnail by writing below code,

var err: NSError? = nil
let url=NSURL(fileURLWithPath: videoPath as String)
let asset = AVURLAsset(URL: url, options: nil)
let imgGenerator = AVAssetImageGenerator(asset: asset)
let cgImage = imgGenerator.copyCGImageAtTime(CMTimeMake(0, 1), actualTime: nil, error: &err)

let uiImage = UIImage(CGImage: cgImage)
let imageView = UIImageView(image: uiImage)

希望对您有所帮助.

这篇关于快速获取修剪过的视频的缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 04:38