ios - 处理视频和写入文件的最佳性能方法 - ios AVFoundation

标签 ios swift avfoundation avasset

我想读入磁盘上的视频资源并对其进行一系列处理,例如在每个单独的帧上使用 CICropFilter 并剪切一个 mask ,将一个视频分成几个较小的视频视频,并从原始轨道中删除帧以“压缩”它并使其更像 gif。

我想出了几个可能的途径:

  1. AVAssetWriterAVAssetReader

在这种情况下,我将从文件中读取 CMSampleBuffer,执行我想要的操作,然后使用 AVAssetWriter 写回新文件。

  1. AVMutableComposition

在这里,给定一个 CMTimes 列表,我可以轻松地剪切帧并重写视频,甚至为我想创建的每个新视频创建多个合成,然后使用 导出所有这些AVAssetExportSession.

我关心的指标:性能和功率。也就是说,我对在执行编辑时提供最高效率同时也让我可以灵活地做我想做的事情的方法很感兴趣。我想我所描述的那种视频编辑可以用这两种方法来完成,但实际上我想要最高性能/最好的功能。

最佳答案

根据我的经验,AVAssetExportSession 比使用 AVAssetReader 和 AVAssetWriter 进行直接的格式 A -> 格式 B 类型转换的性能略高,但是话虽如此,可能还不足以让您过于担心。

根据苹果自己的文档https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40010188 :

You use an export session to reencode an existing asset into a format defined by one of a small number of commonly-used presets. If you need more control over the transformation, in iOS 4.1 and later you can use an asset reader and asset writer object in tandem to convert an asset from one representation to another. Using these objects you can, for example, choose which of the tracks you want to be represented in the output file, specify your own output format, or modify the asset during the conversion process.

鉴于您问题的性质,您似乎还没有太多使用 AVFoundation 框架的经验。我的建议是从 AVAssetExportSession 开始,然后当你遇到障碍时,向下移动到堆栈的更深处,进入 AVAssetReader 和 AVAssetWriter。

最终,根据您采取的程度,您甚至可能想要编写自己的自定义合成器。

关于ios - 处理视频和写入文件的最佳性能方法 - ios AVFoundation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36708562/

相关文章:

iphone - iOS - 代码仅在插入断点时才有效

ios - iOS上的Twitter-如何授予发布推文的权限?

iphone - 无法在单元测试中设置 NSMutableDictionary 中的值

ios - Swift - 动画方向

ios - AppDelegate问题

Swift 无法确定 switch 子句是否详尽无遗

android - 在 iOS 和 Android 之间同步应用程序数据

javascript - 解析云代码 - 在发送响应之前仅检索某些列。

ios - 如何过滤检测到的人脸位置和大小?

iPhone 歌词访问