从[UIImage],Swift创作电影 [英] create movie from [UIImage], Swift

查看:110
本文介绍了从[UIImage],Swift创作电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现导出[UIImage] ]作为电影,但它全部在ObjectiveC和我无法弄清楚Swift。

I've found export [UIImage] as movie, but its all in ObjectiveC and I can't figure it out for Swift.

我需要从[UIImage]创建一个视频

I need to create a video from [UIImage]

通过以上链接研究Zoul的答案。第1部分给写作者打电话

Working on Zoul's answer from above link. part 1) Wire the writer

到目前为止我有:

let paths = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
    let documentsURL = paths[0] as! NSURL
    let videoWriter:AVAssetWriter = AVAssetWriter(URL: documentsURL, fileType: AVFileTypeQuickTimeMovie, error: nil)

    var videoSettings: NSDictionary = NSDictionary(

我无法弄清楚他的正确Swift版本

I can't figure out the correct Swift version of his

NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt:640], AVVideoWidthKey,
[NSNumber numberWithInt:480], AVVideoHeightKey,
nil];






推荐答案

构建字典字面很简单:

import AVFoundation

let videoSettings = [
    AVVideoCodecKey: AVVideoCodecH264,
    AVVideoWidthKey: 640,
    AVVideoHeightKey: 480
]

至于其他一切,我建议你阅读Apple的 Swift编程语言首先建立基础,而不是依赖于SO或教程恰巧涵盖了你想做的事情。正如他们所说,教一个人钓鱼。

As for everything else, I would encourage you to read through Apple's The Swift Programming Language to establish fundamentals first, rather than relying on SO or tutorials that happen to cover what you want to do. "Teach a man to fish", as they say.

这篇关于从[UIImage],Swift创作电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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