當我從- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
一個框架,我找回了以下數據:縱向模式下這些額外的字節來自iPhone相機是什麼?
- BytesPerRow:1,472長度:706560高度:480寬度:360格式: BGRA
這是從正面iPhone 6以上的相機。 這是沒有意義的,因爲每行的字節應該是(寬*通道)(在這種情況下通道是4)。但是,它是(寬度+ 8)*通道。這額外的8個字節來自哪裏?
這裏是我的代碼: 輸出附加到我的方向設置爲縱向
bool attachOutputToSession(AVCaptureSession *session, id cameraDelegate)
{
assert(cameraDelegate);
AVCaptureVideoDataOutput *m_videoOutput = [[AVCaptureVideoDataOutput alloc] init];
//create a queue for capturing frames
dispatch_queue_t captureQueue = dispatch_queue_create("captureQueue", DISPATCH_QUEUE_SERIAL);
//Use the AVCaptureVideoDataOutputSampleBufferDelegate capabilities of CameraDelegate:
[m_videoOutput setSampleBufferDelegate:cameraDelegate queue:captureQueue];
//setup the video outputs
m_videoOutput.alwaysDiscardsLateVideoFrames = YES;
NSNumber *framePixelFormat = [NSNumber numberWithInt:kCVPixelFormatType_32BGRA];//This crashes with 24RGB b/c that isn't supported on iPhone
m_videoOutput.videoSettings = [ NSDictionary dictionaryWithObject:framePixelFormat forKey:(id)kCVPixelBufferPixelFormatTypeKey];
//Check if it already has an output from a previous session
if ([session canAddOutput:m_videoOutput])
{
[session addOutput:m_videoOutput];
}
//set connection settings
for (AVCaptureConnection *connection in m_videoOutput.connections)
{
if (connection.isVideoMirroringSupported)
connection.videoMirrored = true;
if (connection.isVideoOrientationSupported)
connection.videoOrientation = AVCaptureVideoOrientationPortrait;
}
return true;
}
當我設置爲LandscapeRight我沒有這個問題的方向會話。每行的字節數等於寬度*通道。
這裏就是我得到上面提到的數字:
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:imageBuffer];
CVPixelBufferLockBaseAddress(imageBuffer,0);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
}
32BRGA是一個單一的平面格式,所以沒有理由搞亂CVPixelBufferGetBytesPerRowOfPlane。只需使用CVPixelBufferGetBytesPerRow即可獲得步伐。 – user1055568 2015-02-12 18:50:27
你是對的,這工作得很好。但是,我正在處理只佔用字節,寬度,高度和總大小的圖像結構。所以對我來說很重要的一點是如何計算這個數據,而不是我以後的數據。 – spfursich 2015-02-13 22:03:17