iOS:如何使用AVAssetWriter用一系列图像制作电影 [英] iOS: How to make a movie with a series of images using AVAssetWriter

查看:307
本文介绍了iOS:如何使用AVAssetWriter用一系列图像制作电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里和其他论坛上都以不同的形式多次问过这个问题.有些问题得到了回答,有些则没有.答卷者或作者声称在某些地方取得了成功.我已经实现了那些声称成功的示例,但是还没有看到相同的结果.

I have seen this question asked many times in different forms both here and in other forums. Some of the questions get answered, some do not. There are a few where the answerer or author claims to have had success. I have implemented the examples from those that claim success, but have yet to see the same results.

当从AVCaptureSession获得样本缓冲区时,我能够成功使用AVAssetWriter(和AVAssetWriterInputPixelBufferAdaptor)同时写入图像数据和音频数据.但是,如果我有以其他方式生成的CGImageRef,并从头开始"构建了CVPixelBufferRef,则AVAssetWriterInputPixelBufferAdaptor的appendPixelBuffer:withPresentationTime方法成功执行了几帧,然后失败了.生成的电影文件当然是无效的.

I am able to successfully use AVAssetWriter (and AVAssetWriterInputPixelBufferAdaptor) to write image data and audio data simultaneously when the sample buffers are obtained from an AVCaptureSession. However, if I have CGImageRef's that were generated in some other way, and build a CVPixelBufferRef "from scratch", the appendPixelBuffer:withPresentationTime method of AVAssetWriterInputPixelBufferAdaptor succeeds for a few frames and then fails for all subsequent frames. The resulting movie file is of course not valid.

您可以在以下位置看到我的示例代码: http://pastebin.com/FCJZJmMi

You can see my example code at: http://pastebin.com/FCJZJmMi

这些图像有效,并通过在调试窗口中显示它们进行验证(请参阅第50-53行).该应用程序已通过Instruments进行了测试,并且在应用程序的整个运行过程中内存利用率都很低.它不会收到任何内存警告.

The images are valid, and are verified by displaying them in a debug window (see lines 50-53). The app has been tested with Instruments, and memory utilization is low throughout the running of the app. It does not get any memory warnings.

据我所知,我已经遵循了可用的文档.为什么示例代码失败?需要做什么来修复它?

As far as I can tell I have followed the documentation that is available. Why does the example code fail? What needs to be done to fix it?

如果有人成功获取了AVAssetWriterInputPixelBufferAdaptor来处理自己的图像,请发出提示.

If anybody has successfully gotten AVAssetWriterInputPixelBufferAdaptor to work with their own images, please chime in.

推荐答案

要做此工作需要做两件事.

There are two things that were required to make this work.

如果要调试自己的AVAssetWriterInputPixelBufferAdaptor,请确保不要跳过CMTime,也不要重复CMTime(每次慢速恰好有一帧).

If you are debugging your own AVAssetWriterInputPixelBufferAdaptor be careful to make sure you don't skip CMTime's and also make sure you don't ever repeat a CMTime (have exactly one frame per time slow ALWAYS).

这篇关于iOS:如何使用AVAssetWriter用一系列图像制作电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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