在swift中从本地视频创建缩略图 [英] Creating thumbnail from local video in swift

查看:184
本文介绍了在swift中从本地视频创建缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用本地视频文件在swift中创建缩略图?

How to create thumbnail in swift from a local video file ?

例如,如果视频文件路径位于此处:

For example if the video file path is located here :

file:/ //Users/Dev/Library/Developer/CoreSimulator/Devices/F33222DF-D8F0-448B-A127-C5B03C64D0DC/​​data/Containers/Data/Application/4BC62DBF-0108-453C-9324-5BC0E356FE24/tmp/trim.059D11E6-F0EF- 43DB-9E97-CA4F1F95D6B6.MOV

谢谢。

推荐答案

通过以下编辑进行翻译:

Translated with some edits from:

使用AVFoundation的视频的第一帧

    var err: NSError? = nil
    let asset = AVURLAsset(URL: NSURL(fileURLWithPath: "/that/long/path"), options: nil)
    let imgGenerator = AVAssetImageGenerator(asset: asset)
    let cgImage = imgGenerator.copyCGImageAtTime(CMTimeMake(0, 1), actualTime: nil, error: &err)
    // !! check the error before proceeding
    let uiImage = UIImage(CGImage: cgImage)
    let imageView = UIImageView(image: uiImage)
    // lay out this image view, or if it already exists, set its image property to uiImage

这篇关于在swift中从本地视频创建缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆