我正在尝试执行深度克隆CMSampleBuffer来存储AVCaptureSession. kCMSampleBufferError_InvalidMediaFormat (OSStatus -12743)当我运行该函数时收到错误CMSampleBufferCreateForImageBuffer。我不明白我是如何CVImageBuffer与CMSampleBuffer格式描述不匹配的。有人知道我哪里出错了吗?她是我的测试代码。
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
let allocator: CFAllocator = CFAllocatorGetDefault().takeRetainedValue()
func cloneImageBuffer(imageBuffer: CVImageBuffer!) -> CVImageBuffer? {
CVPixelBufferLockBaseAddress(imageBuffer, 0)
let bytesPerRow: size_t = CVPixelBufferGetBytesPerRow(imageBuffer)
let width: size_t = CVPixelBufferGetWidth(imageBuffer)
let height: size_t = CVPixelBufferGetHeight(imageBuffer)
let baseAddress = CVPixelBufferGetBaseAddress(imageBuffer)
let pixelFormatType = CVPixelBufferGetPixelFormatType(imageBuffer)
let data = NSMutableData(bytes: baseAddress, length: bytesPerRow * height)
CVPixelBufferUnlockBaseAddress(imageBuffer, 0)
var clonedImageBuffer: CVPixelBuffer?
let refCon = NSMutableData()
if …Run Code Online (Sandbox Code Playgroud) 有人可以帮助我在 XCode 中运行 Instruments 时跟踪这些 CoreVideo 内存泄漏吗?
基本上,当我按下自定义动画 jpeg 播放器上的“录制视频”按钮时,就会发生内存泄漏。由于 Leaks Instruments 没有指向我的任何调用,因此我无法确切地说出我的代码的哪一部分正在泄漏。顺便说一句,我正在使用 iPad 设备来测试泄漏。
以下是来自 Leaks Instruments 的消息:
这是我处理服务器流式传输的每个运动 jpeg 帧的代码:
-(void)processServerData:(NSData *)data{
/*
//render the video in the UIImage control
*/
UIImage *image =[UIImage imageWithData:data];
self.imageCtrl.image = image;
/*
//check if we are recording
*/
if (myRecorder.isRecording) {
//create initial sample: todo:check if this is still needed
if (counter==0) {
self.buffer = [Recorder pixelBufferFromCGImage:image.CGImage size:myRecorder.imageSize];
CVPixelBufferPoolCreatePixelBuffer (NULL, myRecorder.adaptor.pixelBufferPool, &buffer);
if(buffer)
{
CVBufferRelease(buffer); …Run Code Online (Sandbox Code Playgroud) 我试图将视频帧大小更改为方形,即100 x 100.以下是代码:
- (void) changeSize :(NSURL *) url
{
//Create audio/video Settings
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt: 100], AVVideoWidthKey,
[NSNumber numberWithInt:100], AVVideoHeightKey,
nil];
NSDictionary * audioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSData data], AVChannelLayoutKey, nil];
//Read Asset
AVURLAsset *myAsset = [AVURLAsset URLAssetWithURL:url options:nil];
NSArray *videoTracks = [myAsset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *audioTrack = [[myAsset tracksWithMediaType:AVMediaTypeAudio]objectAtIndex:0];
AVAssetReader *assetReader = [[AVAssetReader alloc]initWithAsset:myAsset error:nil];
AVAssetReaderOutput *videoOutput = [AVAssetReaderVideoCompositionOutput assetReaderVideoCompositionOutputWithVideoTracks:videoTracks videoSettings:nil]; …Run Code Online (Sandbox Code Playgroud) iphone avfoundation video-editing core-video video-recording
在iOS 5中,引入了OpenGL ES Texture缓存,以提供从摄像机视频数据到OpenGL的直接方式,而无需复制缓冲区.会话414中简要介绍了纹理缓存--Windows 2011中iOS 5的OpenGL ES的进展.
我发现了一篇有趣的文章,最后进一步滥用了这个概念,并glReadPixels通过简单地锁定纹理,然后直接访问缓冲区来绕过调用.
glReadPixels由于iPad 2中使用的基于图块的渲染器(即使只使用1x1纹理),因此速度非常慢.但是,所描述的方法似乎处理得比glReadPixels.
文章中提出的方法是否有效,是否可以用于提升依赖的应用程序glReadPixels?
由于OpenGL与CPU并行处理图形数据,因此在CVPixelBufferLockBaseAddress不与OpenGL交谈的情况下,如何在完成渲染时知道调用?
核心视频专家,我正在为.mov文件创建自定义视频播放器。我正在使用.mov解析器,并使用QTCoreVideo101示例来尝试播放视频。
我的问题是显示链接getFrameForTime我不知道如何使用时间值来找到正确的帧。
CVTimeStamp中包含的值对我来说没有任何意义。以下是1秒视频请求的值示例。谁能解释我如何使用这些值在.mov文件中找到正确的帧?
前三个请求-CVTimeStamp的值
视频时间:489150134353920.000000主机时间:2026048145326080.000000视频时间比例:241500000.000000速率标量:1.000000视频刷新时间:4028320.000000
视频时间:489150201462784.000000主机时间:2026048279543808.000000视频时间比例:241500000.000000速率标量:0.999985视频刷新时间:4028320.000000
视频时间:489156643913728.000000主机时间:2026074988871680.000000视频时间比例:241500000.000000速率标量:1.000000视频刷新时间:4028320.000000
所以我已经设置了 CVPixelBuffer 并在 iOS 上成功地将它们绑定到 OpenGL FBO。但是现在尝试在 OSX 上做同样的事情让我陷入困境。
来自 CVOpenGLTextureCacheCreateTextureFromImage 的纹理返回为 GL_TEXTURE_RECTANGLE 而不是 GL_TEXTURE_2D 目标。
我找到了 kCVOpenGLBufferTarget 键,但它似乎应该与 CVOpenGLBufferCreate 而不是 CVPixelBufferCreate 一起使用。
甚至可以使用 CVPixelBufferCreate 在 OSX 上获得 GL_TEXTURE_2D 目标纹理,如果是这样,如何?
FWIW 列出了 CV PBO 设置:
NSDictionary *bufferAttributes = @{ (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA), (__bridge NSString *)kCVPixelBufferWidthKey : @(size.width), (__bridge NSString *)kCVPixelBufferHeightKey : @(size.height), (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ } };
if (pool)
{
error = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, pool, &renderTarget);
}
else
{
error = CVPixelBufferCreate(kCFAllocatorDefault, (NSUInteger)size.width, (NSUInteger)size.height, kCVPixelFormatType_32BGRA, (__bridge CFDictionaryRef)bufferAttributes, …Run Code Online (Sandbox Code Playgroud) 我正在重构基于iOS OpenGL的渲染管道。我的管道包含许多渲染步骤,因此我需要很多中间纹理来渲染和读取。这些纹理具有各种类型(无符号字节和半浮点数),并且可能具有不同数量的通道。
为了节省内存和分配工作,我回收了管道中先前步骤使用的纹理,不再需要这些纹理。在我以前的实现中,我是自己做的。
在我的新实现中,我想使用Core Video框架提供的API。特别是因为它们提供了从CPU对纹理内存的更快访问。我知道CVOpenGLESTextureCache允许我从CVPixelBuffers中创建OpenGL纹理,可以直接创建或使用CVPixelBufferPool。但是,我找不到任何描述它们如何真正发挥作用以及如何共同发挥作用的文档。
这是我想知道的事情:
CVOpenGLESTextureCache我总是需要提供一个像素缓冲区。如果仍然需要提供内存并且无法检索旧的未使用的纹理,为什么将其称为“缓存”?CVOpenGLESTextureCacheFlush功能“目前刷新未使用的资源”。缓存如何知道资源是否“未使用”?发布相应的纹理后,纹理会返回到缓存CVOpenGLESTextureRef吗?相同的问题适用于CVPixelBufferPool。CVPixelBufferPool似乎只能管理相同大小和类型的缓冲区。这意味着我需要为我使用的每种纹理配置创建一个专用池,对吗?如果至少可以澄清其中一些问题,我将非常高兴。
我正在使用 编写一些视频处理代码AVComposition。仅提供必要的背景详细信息,我收到CVPixelBuffer来自我无法控制的苹果 API 的信息。这个 CVPixel 缓冲区包含之前渲染的视频帧,因为它们显然是由我无法控制的 Apple API 回收的。所以我的目标是将 CVPixelBufferRef 中的所有像素设置为 [0, 0, 0, 0] (在 RGBA 颜色空间中)。我可以通过以下函数在 CPU 上执行此操作:
- (void)processPixelBuffer: (CVImageBufferRef)pixelBuffer
{
CVPixelBufferLockBaseAddress( pixelBuffer, 0 );
int bufferWidth = CVPixelBufferGetWidth(pixelBuffer);
int bufferHeight = CVPixelBufferGetHeight(pixelBuffer);
unsigned char *pixel = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBuffer);
for( int row = 0; row < bufferHeight; row++ ) {
for( int column = 0; column < bufferWidth; column++ ) {
pixel[0] = 0;
pixel[1] = 0;
pixel[2] = 0;
pixel[3] = …Run Code Online (Sandbox Code Playgroud) I have a client-server application, where the client sends processed images to the server. I would like the client to send these as CVPixelBufferRef, so the server can combine images easier. The client sends data as NSDictionary.
How do I send a core foundation/core video object over network within a NSDictionary?
CVPixelBufferRef pxbuffer = NULL;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault,
size.width,
size.height,
kCVPixelFormatType_32ARGB,
(__bridge CFDictionaryRef) options,
&pxbuffer);
//If I try this:
NSDictionary* dataToSend = @{@"data":pxbuffer};
//Get Compiler Error: Collection element of …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚所有权如何与功能一起工作CVMetalTextureGetTexture:
CVMetalTextureRef textureRef;
// ... textureRef is created
id<MTLTexture> texture = CVMetalTextureGetTexture(_textureRef);
CVBufferRelease(textureRef); // Releasing the existing texture
// Is texture still valid here?
Run Code Online (Sandbox Code Playgroud)
是texture仍然释放后有效textureRef?如果不是,我可以以某种方式将所有权从转让textureRef给texture(ARC),这样我就不必CVBufferRelease在texture释放时再打电话了吗?
迅速回答同样的问题:
var texture: MTLTexture
do {
var textureRef: CVMetalTexture
// ... textureRef is created
texture = CVMetalTextureGetTexture(textureRef)!
// end of scope, textureRef is released
}
// Is texture still valid here?
Run Code Online (Sandbox Code Playgroud) objective-c core-foundation core-video automatic-ref-counting swift
core-video ×10
ios ×6
avfoundation ×3
core-media ×2
objective-c ×2
opengl ×2
.mov ×1
caching ×1
glreadpixels ×1
iphone ×1
macos ×1
memory-leaks ×1
opengl-es ×1
quicktime ×1
swift ×1
textures ×1