Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is how I do it on iOS in my captureOutput after I get a raw video frame from AVCaptureSession(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange):</p> <pre><code>- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { CVImageBufferRef videoFrame = CMSampleBufferGetImageBuffer(sampleBuffer); CFRetain(sampleBuffer); CVPixelBufferLockBaseAddress(videoFrame, 0); size_t _width = CVPixelBufferGetWidth(videoFrame); size_t _height = CVPixelBufferGetHeight(videoFrame); const uint8* plane1 = (uint8*)CVPixelBufferGetBaseAddressOfPlane(videoFrame,0); const uint8* plane2 = (uint8*)CVPixelBufferGetBaseAddressOfPlane(videoFrame,1); size_t plane1_stride = CVPixelBufferGetBytesPerRowOfPlane (videoFrame, 0); size_t plane2_stride = CVPixelBufferGetBytesPerRowOfPlane (videoFrame, 1); size_t plane1_size = plane1_stride * CVPixelBufferGetHeightOfPlane(videoFrame, 0); size_t plane2_size = CVPixelBufferGetBytesPerRowOfPlane (videoFrame, 1) * CVPixelBufferGetHeightOfPlane(videoFrame, 1); size_t frame_size = plane1_size + plane2_size; uint8* buffer = new uint8[ frame_size ]; uint8* dst_u = buffer + plane1_size; uint8* dst_v = dst_u + plane1_size/4; // Let libyuv convert libyuv::NV12ToI420(/*const uint8* src_y=*/plane1, /*int src_stride_y=*/plane1_stride, /*const uint8* src_uv=*/plane2, /*int src_stride_uv=*/plane2_stride, /*uint8* dst_y=*/buffer, /*int dst_stride_y=*/plane1_stride, /*uint8* dst_u=*/dst_u, /*int dst_stride_u=*/plane2_stride/2, /*uint8* dst_v=*/dst_v, /*int dst_stride_v=*/plane2_stride/2, _width, _height); CVPixelBufferUnlockBaseAddress(videoFrame, 0); CFRelease( sampleBuffer) // TODO: call your method here with 'buffer' variable. note that you need to deallocated the buffer after using it } </code></pre> <p>I made the code a bit more descriptive for clarity.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload