Laz*_*Laz 5 ios cmsamplebufferref ciimage
我正在尝试将图像裁剪CMSampleBufferRef为特定大小。我正在做 5 个步骤 - 1.PixelBuffer从SampleBuffer2. 转换PixelBuffer为CIImage3. 裁剪CIImage4. 渲染CIImage回PixelBuffer5. 附加PixelBuffer到SampleBuffer. 到目前为止,我在第 4 步遇到了问题 - 将图像渲染回PixelBuffer(无法检查超出这一点)没有任何内容渲染到缓冲区(我使用相同的检查CIImage imageWithCVPixelBuffer并获得 NULL 作为返回)。非常感谢任何提示或帮助。
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, &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, &videoInfo);
CMSampleBufferRef oBuf;
CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, true, NULL, NULL, videoInfo, &sampleTime, &oBuf);
Run Code Online (Sandbox Code Playgroud)
所以我找到了我遇到问题的原因。显然,我必须在初始化像素缓冲区时通过创建字典并将其传递给初始化程序来添加 kCVPixelBufferIOSurfacePropertiesKey 键。如果有人偶然发现这个问题,这里有一个代码:
CFDictionaryRef empty; // empty value for attr value.
CFMutableDictionaryRef attrs;
empty = CFDictionaryCreate(kCFAllocatorDefault, // our empty IOSurface properties dictionary
NULL,
NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
attrs = CFDictionaryCreateMutable(kCFAllocatorDefault,
1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(attrs,
kCVPixelBufferIOSurfacePropertiesKey,
empty);
Run Code Online (Sandbox Code Playgroud)
然后你只需将此字典作为参数传递给 CVPixelBufferCreate
我在这里找到了这个解决方案:http://allmybrain.com/2011/12/08/rendering-to-a-texture-with-ios-5-texture-cache-api/
| 归档时间: |
|
| 查看次数: |
4604 次 |
| 最近记录: |