AVAssetWriterInput 和 readyForMoreMediaData
AVAssetWriterInput 的 readyForMoreMediaData 是否在后台线程中更新?如果readyForMoreMediaData为NO,我可以在主线程中阻塞并等待直到该值更改为YES吗?
我通过将数据推送到 AVAssetWriterInput 来使用它(即不使用 requestMediaDataWhenReadyOnQueue),并且我设置了 ExpectsMediaDataInRealTime,并且 99.9% 的时间我可以在其上调用appendSampleBuffer(或appendPixelBuffer),速度与我的应用程序生成帧的速度一样快。
除非您在 AVAssetWriter 会话中将设备 (iPhone 3GS) 置于睡眠状态 15 分钟左右,否则这种方法可以正常工作。唤醒设备后,appendPixelBuffer 有时会收到错误消息:“当readyForMoreMediaData 为NO 时,无法附加像素缓冲区”。因此我的问题是如何最好地响应readyForMoreMediaData=NO以及我是否可以在主线程中稍等一下,如下所示:
while ( ![assetWriterInput readyForMoreMediaData] )
{
Sleep for a few milliseconds
}
Is AVAssetWriterInput's readyForMoreMediaData updated in a background thread? If readyForMoreMediaData is NO, can I block in the main thread and wait until the value changes to YES?
I'm using an AVAssetWriterInput by pushing data to it (i.e. without using requestMediaDataWhenReadyOnQueue) and I've set expectsMediaDataInRealTime, and 99.9% of the time I can just call appendSampleBuffer (or appendPixelBuffer) on it as fast as my app can generate frames.
This works fine unless you put the device (iPhone 3GS) to sleep for 15 minutes or so in the middle of an AVAssetWriter session. After waking up the device, appendPixelBuffer sometimes gets an error saying, "A pixel buffer cannot be appended when readyForMoreMediaData is NO". Hence my question - how best to respond to readyForMoreMediaData=NO and if I can just wait a bit in the main thread like so:
while ( ![assetWriterInput readyForMoreMediaData] )
{
Sleep for a few milliseconds
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
小心不要只是阻塞线程,这是我之前所做的,但不起作用:
上述方法有时会在我的 iPad2 上失败。这样做反而解决了问题:
Be careful not to just block the thread, here is what I was doing before that was not working:
The above approach would fail sometimes on my iPad2. Doing this instead fixed the problem:
找不到类似的东西,所以我把它留在这里。 Swift 4 解决方案。
最好使用精确的技术来解决这个问题。 Fe 使用 NSCondition:
下一步:
不要忘记最后使观察者无效
Don't find something similar, so I left it here. Swift 4 solution.
Would better using precise technique to solve that problem. F.e. using NSCondition:
Next:
Don't forget to invalidate observer in the end
轮询不是明智的解决方案。
您应该使用 requestMediaDataWhenReadyOnQueue
Polling is not the advisable solution.
You should be using requestMediaDataWhenReadyOnQueue