Note that there are some explanatory texts on larger screens.

plurals
  1. POCrop CMSampleBufferRef
    primarykey
    data
    text
    <p>I am trying to crop image in <code>CMSampleBufferRef</code> to a specific size. I am making 5 steps - 1. Getting <code>PixelBuffer</code> from <code>SampleBuffer</code> 2. Converting <code>PixelBuffer</code> to <code>CIImage</code> 3. Cropping <code>CIImage</code> 4. Rendering <code>CIImage</code> back to <code>PixelBuffer</code> 5. Attaching <code>PixelBuffer</code> to <code>SampleBuffer</code>. So far I am having trouble with step 4 - rendering image back to <code>PixelBuffer</code> (can not check beyond this point) nothing is rendered to buffer (I check it using same <code>CIImage imageWithCVPixelBuffer</code> and get NULL as a return). Would greatly appreciate any tip or help.</p> <pre><code>CGRect cropRect = CGRectMake(0, 0, 640, 480); CIImage *ciImage = [CIImage imageWithCVPixelBuffer:(CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer)]; //options: [NSDictionary dictionaryWithObjectsAndKeys:[NSNull null], kCIImageColorSpace, nil]]; ciImage = [ciImage imageByCroppingToRect:cropRect]; CVPixelBufferRef pixelBuffer; CVPixelBufferCreate(kCFAllocatorSystemDefault, 640, 480, kCVPixelFormatType_32BGRA, NULL, &amp;pixelBuffer); CVPixelBufferLockBaseAddress( pixelBuffer, 0 ); CIContext * ciContext = [CIContext contextWithOptions: nil]; [ciContext render:ciImage toCVPixelBuffer:pixelBuffer]; CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 ); CMSampleTimingInfo sampleTime = { .duration = CMSampleBufferGetDuration(sampleBuffer), .presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer), .decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(sampleBuffer) }; CMVideoFormatDescriptionRef videoInfo = NULL; CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, &amp;videoInfo); CMSampleBufferRef oBuf; CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, true, NULL, NULL, videoInfo, &amp;sampleTime, &amp;oBuf); </code></pre>
    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.
 

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