當編碼在iOS上的視頻,大部分的解決方案包括此步驟:爲什麼我們需要在appendPixelBuffer之後暫停線程:withPresentationTime:?
while(encoding) {
if(assetWriterInput.readyForMoreMediaData) {
[adaptor appendPixelBuffer:buffer withPresentationTime:presentTime];
if(buffer)
CVBufferRelease(buffer);
[NSThread sleepForTimeInterval:0.05]; // <=== This line slows down encoding
}
}
如果我不睡覺的線程,結果視頻會顯得生澀,即使readyForMoreMediaData總是返回YES。如果我暫停線程,結果看起來很完美。
但我不明白「readyForMoreMediaData」的目的,如果我們需要暫停線程嗎?看起來我可以將睡眠時間縮短到0.03,而不會導致看起來不穩定,但它仍然會減慢編碼過程。
任何幫助將不勝感激,謝謝!
對不起,我應該說我使用OpenGL繪製對象,並將結果編碼爲視頻。我不使用相機或現有視頻作爲源。我需要一個適配器,因爲我需要一個pixelBufferPool。我會嘗試「recommendedVideoSettingsForAssetWriterWithOutputFileType」。謝謝 – Xys
我認爲recommendedVideoSettingsForAssetWriterWithOutputFileType只是用於「AVCaptureVideoDataOutput」,但我不使用這個 – Xys
如果你想看更多的代碼,這裏有一篇文章解釋它:https://stackoverflow.com/a/9704392/5120292 – Xys