iOS:在附加到 AVAssetWriterInput 之前裁剪 CMSampleBufferRef
我目前正在尝试 CoreImage,学习如何将 CIFilters 应用于相机源。目前,我成功地获取相机源,应用过滤器并将源以视频的形式写入 AVAssetWriter,但我遇到的一个问题是,在过滤过程中,我实际上裁剪了图像数据以便它始终具有正方形尺寸(项目的其他方面需要)
我的过程如下:
- 使用 AVCaptureSession 捕获 feed
- 从捕获输出中获取 CMSampleBufferRef 并获取 CVPixelBufferRef
- 获取CVPixelBufferRef,并使用基地址作为其数据创建 CGBitmapContext(以便我们可以覆盖它)
- 将 CVPixelBufferRef 转换为 CIImage(使用 CIImage 构造函数之一)
- 将滤镜应用于 CIImage
- 将 CIImage 转换为 CGImageRef
- 将 CGImageRef 绘制到 CGBitmapContext (导致示例缓冲区内容被覆盖)
- 将 CMSampleBufferRef 附加到 AVAssetWriterInput。
如果不将 CGImageRef 绘制到上下文,这就是我得到的:
将 CGImageRef 绘制到上下文后,这就是我得到的:
理想情况下,我只想能够告诉 CMSampleBufferRef 它有新尺寸,以便省略附加信息。但我想知道是否必须完全创建一个新的 CMSampleBufferRef。
任何帮助将不胜感激!
I'm currently experimenting with CoreImage, learning how to apply CIFilters to a camera feed. Presently I'm succeeded in taking a camera feed, applying a filter and writing the feed to an AVAssetWriter in the form of a video, but one issue I'm having with it is that during the filtering process, I actually crop the image data so that it always has square dimensions (needed for other aspects of the project)
My process is as follows:
- Capture feed using AVCaptureSession
- Take the CMSampleBufferRef from the capture output and acquire the CVPixelBufferRef
- Get the Base Address of the CVPixelBufferRef, and create a CGBitmapContext using the base address as its data (so we can overwrite it)
- Convert the CVPixelBufferRef to CIImage (using one of the CIImage constructors)
- Apply the filters to the CIImage
- Convert the CIImage to CGImageRef
- Draw the CGImageRef to the CGBitmapContext (resulting in the sample buffers content to be overwritten)
- Append the CMSampleBufferRef to the AVAssetWriterInput.
Without drawing the CGImageRef to the context, this is what I get:
After drawing the CGImageRef to the context, this is what I get:
Ideally, I just want to be able to tell the CMSampleBufferRef that it has new dimensions, so that the additional information is omitted. But I'm wondering if I'll have to create a new CMSampleBufferRef altogether.
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论