处理视频和写入文件的最佳性能方法 - ios AVFoundation
Most performant method of processing video and writing to file - ios AVFoundation
我想读入磁盘上的视频资产并对其进行一系列处理,例如在每个单独的帧上使用 CICropFilter
并剪切一个遮罩,将一个视频分成几个较小的视频, 并从原始轨道中删除帧 "compress" 使其更像 gif。
我想出了几个可能的途径:
AVAssetWriter
和 AVAssetReader
在这种情况下,我将从文件中读取 CMSampleBuffer
s,执行我想要的操作,然后使用 AVAssetWriter
.
写回新文件
AVMutableComposition
在这里,给定 CMTimes
的列表,我可以轻松地剪切帧并重写视频,甚至为我想创建的每个新视频创建多个合成,然后使用 [=18= 导出所有这些].
我关心的指标:性能和功率。也就是说,我对在执行编辑时提供最高效率同时也让我可以灵活地做我想做的事情的方法很感兴趣。我想我所描述的那种视频编辑可以用这两种方法来完成,但实际上我想要最多 performant/with 最好的功能。
根据我的经验,AVAssetExportSession 比使用 AVAssetReader 和 AVAssetWriter 进行直接的格式 A -> 格式 B 类型转换的性能略高,但话虽如此,可能还不足以引起太大关注。
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。
最终,根据您的进展情况,您甚至可能想要编写自己的自定义合成器。
我想读入磁盘上的视频资产并对其进行一系列处理,例如在每个单独的帧上使用 CICropFilter
并剪切一个遮罩,将一个视频分成几个较小的视频, 并从原始轨道中删除帧 "compress" 使其更像 gif。
我想出了几个可能的途径:
AVAssetWriter
和AVAssetReader
在这种情况下,我将从文件中读取 CMSampleBuffer
s,执行我想要的操作,然后使用 AVAssetWriter
.
AVMutableComposition
在这里,给定 CMTimes
的列表,我可以轻松地剪切帧并重写视频,甚至为我想创建的每个新视频创建多个合成,然后使用 [=18= 导出所有这些].
我关心的指标:性能和功率。也就是说,我对在执行编辑时提供最高效率同时也让我可以灵活地做我想做的事情的方法很感兴趣。我想我所描述的那种视频编辑可以用这两种方法来完成,但实际上我想要最多 performant/with 最好的功能。
根据我的经验,AVAssetExportSession 比使用 AVAssetReader 和 AVAssetWriter 进行直接的格式 A -> 格式 B 类型转换的性能略高,但话虽如此,可能还不足以引起太大关注。
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。
最终,根据您的进展情况,您甚至可能想要编写自己的自定义合成器。