问题标签 [cmsamplebuffer]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ios - 从 CMSampleBuffer 中提取数据以创建深层副本
我正在尝试创建一个由 AVCaptureVideoDataOutputSampleBufferDelegate 中的 captureOutput 返回的 CMSampleBuffer 的副本。
由于 CMSampleBuffers 来自 (15) 个缓冲区的预分配池,因此如果我附加对它们的引用,它们将无法被重新收集。这会导致所有剩余的帧都被丢弃。
为了保持最佳性能,一些样本缓冲区直接引用可能需要由设备系统和其他捕获输入重用的内存池。对于未压缩的设备本机捕获来说,这种情况经常发生,其中内存块被复制得越少越好。如果多个样本缓冲区引用此类内存池的时间过长,则输入将不再能够将新样本复制到内存中,并且这些样本将被丢弃。
如果您的应用程序由于保留提供的 CMSampleBufferRef 对象太久而导致样本被丢弃,但它需要长时间访问样本数据,请考虑将数据复制到新缓冲区,然后释放样本缓冲区(如果它以前被保留)以便它引用的内存可以被重用。
显然我必须复制 CMSampleBuffer 但 CMSampleBufferCreateCopy() 只会创建一个浅拷贝。因此我得出结论,我必须使用 CMSampleBufferCreate()。我填了12!构造函数需要的参数,但遇到了我的 CMSampleBuffers 不包含 blockBuffer 的问题(不完全确定那是什么,但它似乎很重要)。
这个问题被问了好几次,但没有回答。
CMImageBuffer 或 CVImageBuffer 的深层复制并在 Swift 2.0 中创建 CMSampleBuffer 的副本
一个可能的答案是“我终于想出了如何使用它来创建深度克隆。所有的复制方法都重用了堆中的数据,这些数据会锁定 AVCaptureSession。所以我必须将数据提取到 NSMutableData 对象中,然后创建了一个新的样本缓冲区。” 归功于 Rob 在 SO 上。但是,我不知道如何正确地做到这一点。
如果您有兴趣,这是 的输出print(sampleBuffer)
。没有提到 blockBuffer,也就是 CMSampleBufferGetDataBuffer 返回 nil。有一个 imageBuffer,但是使用 CMSampleBufferCreateForImageBuffer 创建一个“副本”似乎也没有释放 CMSampleBuffer。
编辑:自从发布了这个问题以来,我一直在尝试更多复制内存的方法。
我做了用户Kametrixom尝试过的同样的事情。这是我对同一想法的尝试,首先复制 CVPixelBuffer 然后使用 CMSampleBufferCreateForImageBuffer 创建最终的样本缓冲区。但是,这会导致以下两个错误之一:
- memcpy 指令上的 EXC_BAD_ACCESS。AKA 尝试访问应用程序内存之外的段错误。
- 或者,内存将成功复制,但
CMSampleBufferCreateReadyWithImageBuffer()
将失败,结果代码为 -12743,“指示给定媒体的格式与给定格式描述不匹配。例如,格式描述与 CVImageBuffer 配对失败 CMVideoFormatDescriptionMatchesImageBuffer。”
您可以看到我和 Kametrixom 都曾CMSampleBufferGetFormatDescription(sampleBuffer)
尝试复制源缓冲区的格式描述。因此,我不确定为什么给定媒体的格式与给定的格式描述不匹配。
ios - 通过带有 alpha 混合的 cicontext 渲染到样本缓冲区?
在 captureOutput 我在样本缓冲区中获取视频帧,我想在捕获的帧之上混合另一个 CIImage 。渲染应该直接进入传递的样本缓冲区。目前我使用这个:
基本上代码可以工作,但有两个问题:
m_overlayImage 的 alpha 分量被忽略,即 m_overlayImage 的半透明部分被渲染函数渲染为黑色。为什么 ?如何解决?
有什么方法可以将 m_overlayImage 绘制到 sampleBuffer 中的某个像素位置。目前我只能画到(0,0),即左下角。问题是根据文档,“边界”被应用于覆盖图像而不是样本缓冲区。如何将我的 m_overlayImage 渲染到样本缓冲区中的某个位置?
谢谢克里斯
swift - macOS - 如何在 Swift 中向 CMSampleBuffer 添加文本?
我是macOS
开发新手。
我试图在我的视频中逐帧添加一些属性文本,
但不知道如何处理CMSampleBuffer
。
谷歌了一些文章,但没有得到任何东西,
我应该将其转换为其他图像,然后添加文本吗?
这是我的代码:
谢谢!
macos - CMBlockBuffer ownership in CMSampleBuffer
I'm writing code to decompress a native annex-B H.264 stream, and I'm going through the process of parsing the stream, creating a CMVideoFormatDescription from the SPS/PPS NALUs, and wrapping the other NALUs I extract from the stream in CMSampleBuffers.
I'm suffering from a mental block on how to handle the CMBlockBuffer and CMSampleBuffer memory for the decoder. I believe my issue is more of a lack of thorough understanding of how CF handles memory than anything else, so my question is really more about that, but I'm hoping the context is helpful.
If I create a CMBlockBuffer like this:
and add it to a CMSampleBuffer like this:
How should I handle the block buffer? Does the SampleBuffer retain the memory of the block buffer, or do I need to do something to make sure it is not deallocated?
Also, pertaining to the asynchronous decode process, is there a sensible way to know when the decoder is done with the CMSampleBuffer so I can dispose of it?
My intuition tells me the CMSampleBuffer would retain the CMBlockBuffer, and the VTDecodeSession would retain the CMSampleBuffer until it's done decoding, but this is undocumented territory I'm wandering in so looking for some direction. The results I'm getting imply my intuition might be wrong, so I need rule out memory management as an issue to keep my sanity...
ios - 来自 AVCaptureVideoDataOutput 的 CMSampleBuffer 意外发现 nil
我正在尝试将从 AVCaptureVideoDataOutput 委托(作为 CMSampleBuffer)获得的帧转换为 UIImage。但是我得到了一个fatal error: unexpectedly found nil while unwrapping an Optional value
可以有人告诉我我的代码有什么问题吗?我假设我的 sampleBufferToUIImage 函数有问题。
将 CMSampleBuffer 转换为 UIImage 的函数:
我正在阅读框架的代表:
设置 AVSession:
image - 将 CVPixelBufferRef 样本从 4:3 转换为 16:9
我尝试在视频捕获管道中将 4:3 帧转换为 16:9 帧。转换后的帧需要进一步处理。因此我需要将覆盖框架保持为CVImageBufferRef
. 我查看了这个堆栈溢出线程,并从中借鉴了一些想法
iOS - Scale and crop CMSampleBufferRef/CVImageBufferRef
这是我所做的:
但是经过这个方法。如果我们从 Xcode 检查cropPixelBuffer。它看起来像一个损坏的图像。
我想这可能是因为颜色格式是 NV12 yuv 像素格式 谢谢你的帮助
ios - 像素格式:kCVPixelFormatType_32BGRA 与 AVVideoCodecJPEG
我试图找出哪个更好地捕捉JPEG
AVFoundation -> PhotoCaptureDelegate
我可以用:
或者
我注意到使用AVVideoCodecJPEG,我可以使用压缩质量;但是,如果我正在PhotoCaptureDelegate中的CMSampleBuffer执行任何 TIFF 转换或其他任务,我将无法使用。
然而,如果我只想以新的方式保存到 JPEG(猜测最有效的方式,我必须使用AVVideoCodecJPEG来做:
哪个更好用?
cocoa-touch - 拆分包含音频的 CMSampleBufferRef
我在录制时将录音分成不同的文件......
问题是,captureOutput 视频和音频样本缓冲区不对应 1:1(这是合乎逻辑的)
所以我需要CMSampleBufferRef
根据时间分割音频并将第一段用于第一个视频,将缓冲区的第二部分用于第二个视频
导出时也可以做一些事情,AVMutableComposition
但AVAssetExportSession
问题是关于 中的缓冲区级别captureOutput:
,因此记录器文件不需要更多处理
更新:
看起来像 3 个选项,尚未成功实施
1)CMSampleBufferCopySampleBufferForRange
看起来CMSampleBufferCopySampleBufferForRange
是要走的路,但我正在努力计算最后一个参数sampleRange
......
2)CMSampleBufferCreateCopyWithNewTiming
用这个很迷失
3)看起来有一种方法可以通过提供kCMSampleBufferAttachmentKey_TrimDurationAtStart, kCMSampleBufferAttachmentKey_TrimDurationAtEnd
使用来修剪缓冲区CMSetAttachment
avfoundation - 无法将像素缓冲区随机附加到 AVAssetWriterInputPixelBufferAdaptor
我正在使用AVAssetWriter
并AVAssetWriterInputPixelBufferAdaptor
添加CMSampleBuffer
从记录的蒙版图像AVCaptureSession
,但有时在尝试追加处理时出现此pixelBuffer
错误AVAssetWriterInputPixelBufferAdaptor
:
错误域=AVFoundationErrorDomain 代码=-11800“操作无法完成” UserInfo={NSUnderlyingError=0x170845af0 {错误域=NSOSStatusErrorDomain 代码=-16364“(空)”},NSLocalizedFailureReason=发生未知错误(-16364),NSLocalizedRecoverySuggestion =XXXXDEFAULTVALUEXXXX, NSLocalizedDescription=操作无法完成}