你有沒有遇到過的問題不正確CVPixelBufferRef時相同的視頻copyPixelBufferForItemTime
是不正確iOS上?AVPlayerItemVideoOutput copyPixelBufferForItemTime給出了iOS上的特定視頻
我有AVPlayerItemVideoOutput
,聯繫到合適AVPlayerItem
。 我打電話copyPixelBufferForItemTime
,收到CVPixelBufferRef
然後從中檢索的OpenGL紋理。
CVPixelBufferRef pb = [_playerVideoOutput copyPixelBufferForItemTime:currentTime itemTimeForDisplay:nil];
對於這個sample video有錯誤與CVPixelBufferRef:
int bpr = (int)CVPixelBufferGetBytesPerRow(pb);
int width_real = (int)CVPixelBufferGetWidth(pb);
int width_working = (int)CVPixelBufferGetBytesPerRow(pb)/4;
Mac的輸出:
BPR =
width_real = 596
width_working =
iOS的輸出:
BPR =
width_real = 596
width_working =
CVPixelBufferGetPixelFormatType
返回兩個平臺上的BGRA
。
編輯 在創建iOS上的質感,我通過CVPixelBufferGetBaseAddress
讀取像素緩衝區中的數據,並使用所提供的尺寸CVPixelBufferGetWidth
/CVPixelBufferGetHeight
:
- (GLuint)createTextureFromMovieFrame:(CVPixelBufferRef)movieFrame
{
int bufferWidth = (int) CVPixelBufferGetWidth(movieFrame);
int bufferHeight = (int) CVPixelBufferGetHeight(movieFrame);
// Upload to texture
CVPixelBufferLockBaseAddress(movieFrame, 0);
CVOpenGLTextureRef texture=0;
GLuint tex = 0;
#if TARGET_OS_IOS==1
void * data = CVPixelBufferGetBaseAddress(movieFrame);
CVReturn err = 0;
tex = algotest::MyGL::createRGBATexture(bufferWidth, bufferHeight, data, algotest::MyGL::KLinear);
#else
CVReturn err = CVOpenGLTextureCacheCreateTextureFromImage(kCFAllocatorDefault,
getGlobalTextureCache(), movieFrame, 0, &texture);
#endif
CVPixelBufferUnlockBaseAddress(movieFrame, 0);
return tex;
}
所以width_working
只是爲了調試。由於它不匹配width_real
,並通過既不width_working
不width_real
不工作,我想這是與像素緩衝區的錯誤。
看起來你錯誤地處理了iOS情況下的每行填充(當width_real * 4!= CVPixelBufferGetBytesPerRow(pb)'。你能說明你是如何創建紋理的?你到底在做什麼'width_working'? –
@RhythmicFistman看起來我誤將變量命名:)'width_working'用於調試。更新了帖子。 –