当应用程序在渲染过程中进入后台时,AVASsetWriter失败 [英] AVAssetWriter fails when Application enters Background during Rendering

查看:111
本文介绍了当应用程序在渲染过程中进入后台时,AVASsetWriter失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在渲染从用户照片中检索到的图像生成的视频.我已经用AVAssetwriterInput设置了一个AVAssetwriter并具有一个AVAssetWriterInputPixelBufferAdaptor.我可以将我从用户库中检索到的ALAsset对象转换为CVPixelBuffers并将它们添加到Video中,然后将其另存为mp4.将所有图像添加到视频是在后台线程上完成的,该线程每帧将一个Notification发送到主线程,因此可以更新界面.所有这些都运行良好,并且我从应用程序中获得了可用的电影文件.

In my app I am rendering a Video generated from images I retrieve from the users photos. I have set up an AVAssetwriter with a AVAssetwriterInput has an AVAssetWriterInputPixelBufferAdaptor. I'm able to transform the ALAsset objects I retrieve from the users library to CVPixelBuffers and add them to the Video, which then is saved as an mp4. Adding all the images to the video is done on a background thread which sends a Notification to the main thread every frame, so the interface can be updated. All this works well, and I get a usable Movie file out of the app.

我现在的问题是,当用户进入另一个应用程序时,再次激活后,ALAssetWriter的状态更改为失败",我无法向影片文件添加更多图像.首先,我认为我可能不得不在编写器上结束当前的Session并重新打开一个新的Session,一旦该应用再次激活,但这似乎无济于事.

My problem now is, that when the user enters another application, after becoming active again the status of the ALAssetWriter changes to "failed", an I am not able to add any more images to the movie file. First I thought I might have to end the current Session on the writer and reopen a new one, once the app has become active again, but that doesn't seem to help.

我只是想知道当我希望用户输入其他应用程序时的通用方法.最好的解决方案是,如果渲染可以在后台继续进行.我想我需要UIApplication中的后台线程.但是现在我很高兴,如果在恢复我的应用程序之后渲染能够继续进行.

I was just wondering how the general approach would be when I'd like the user to enter other applications. The best solution would be, if the rendering could continue in the background. I suppose I'd need a background thread from the UIApplication. But for now I'd be happy, if rendering could just continue after resuming my app.

我现在不会发布任何代码,因为它确实很多,而且我的问题可能是概念性的.如果您需要查看代码,我将其发布.

I won't post any code for now, because it's really a lot, and my question possibly is conceptual. If you need to see code, I'll post it.

在iOS 4.3和iOS 5上进行了测试.我已经在其他应用程序(例如iTimelapse)上看到了背景渲染,但是我不确定它们使用哪个框架.

Edit 1: Tested on iOS 4.3 and iOS 5. I've seen background rendering on other apps such as iTimelapse, but I'm not sure which frameworks they use.

Edit2:现在,我得到了一个苹果devforum成员的信息,即AVAssetWriter在后台不起作用.那么,还有其他能够渲染快速时间视频的框架吗?

I now have the information of an apple devforum member, that AVAssetWriter does not work in the background. So is there any other framework out there capable of rendering quicktime videos?

推荐答案

事实证明,AVAssetWriter不能在被暂停的应用程序中生存.您可以通过请求背景时间来增加10分钟的渲染时间,但是之后,AssetWriter会失败.如果您在电话上使用某些服务,也会发生同样的情况.例如,拨打或接听电话也会使AVAssetWriter失败.

Turns out that AVAssetWriter just won't survive the app being suspended. You can add an extra 10 Minutes of rendertime by requesting background time, but after that the AssetWriter fails. Same happens if you use certain services on the phone. For example making or answering a call will make the AVAssetWriter fail as well.

这篇关于当应用程序在渲染过程中进入后台时,AVASsetWriter失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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