本文介绍了AVAssetWriterInput和readyForMoreMediaData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AVAssetWriterInput的readyForMoreMediaData是否在后台线程中更新?如果readyForMoreMediaData为NO,我可以在主线程中阻塞并等到值变为YES吗?

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?

我通过向其推送数据来使用AVAssetWriterInput(即没有使用requestMediaDataWhenReadyOnQueue)并且我设置了expectedMediaDataInRealTime,并且99.9%的时间我可以在其上调用appendSampleBuffer(或appendPixelBuffer),就像我的应用程序可以生成帧一样快。

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.

除非你让设备(iPhone 3GS)在AVAssetWriter会话中间休眠15分钟左右,否则这样可以正常工作。唤醒设备后,appendPixelBuffer有时会收到错误消息,当readyForMoreMediaData为NO时,无法追加像素缓冲区。因此我的问题 - 如何最好地回应readyForMoreMediaData = NO,如果我可以在主线程中稍等一下,那么:

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
}


推荐答案

小心不要只是阻止线程,这是我之前没做的工作:

Be careful not to just block the thread, here is what I was doing before that was not working:

while (adaptor.assetWriterInput.readyForMoreMediaData == FALSE) {
  [NSThread sleepForTimeInterval:0.1];
}

上述方法有时会在我的iPad2上失败。这样做可以解决问题:

The above approach would fail sometimes on my iPad2. Doing this instead fixed the problem:

while (adaptor.assetWriterInput.readyForMoreMediaData == FALSE) {
  NSDate *maxDate = [NSDate dateWithTimeIntervalSinceNow:0.1];
  [[NSRunLoop currentRunLoop] runUntilDate:maxDate];
}

这篇关于AVAssetWriterInput和readyForMoreMediaData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 02:31