ios - 将 CMSampleBufferRef 缓冲到 CFArray 中

标签 ios avfoundation quicktime

我正在尝试将从 iPhone 的摄像机接收到的 150 CMSampleBufferRef 收集到数组中。 相机在 13 个缓冲区后以某种方式停止调用委托(delegate)。 我尝试使用 NSMutableArray、CFArray。没有任何帮助。 我怀疑它与内存有关,但我对内存警告一无所知。

我很乐意为此提供一些帮助。
先谢谢了。

            session = [[AVCaptureSession alloc]init];
            //Quality Preset
            if ([session canSetSessionPreset:AVCaptureSessionPresetLow]) {
                session.sessionPreset = AVCaptureSessionPresetLow;
            }


            [session beginConfiguration];
            AVCaptureDevice *videoDevice = [AVCaptureDevice   defaultDeviceWithMediaType:AVMediaTypeVideo];
            AVCaptureDeviceInput *newVideoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];

            AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];

            output.videoSettings = @{ (NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA) };
            dispatch_queue_t queue = dispatch_queue_create("MyQueue", NULL);
            [output setSampleBufferDelegate:self queue:queue];

            [session addOutput:output];
            [session addInput:newVideoDeviceInput];
            AVCaptureConnection *conn = [output connectionWithMediaType:AVMediaTypeVideo];



            if (conn.supportsVideoMinFrameDuration)
                conn.videoMinFrameDuration = CMTimeMake(1, 10);
            if (conn.supportsVideoMaxFrameDuration)
                conn.videoMaxFrameDuration = CMTimeMake(1, 10);


            [session commitConfiguration];

            arr = CFArrayCreateMutable( NULL, 150, &kCFTypeArrayCallBacks );
            counter=0;
            [session startRunning];

那是我的 StartRecording 方法。

        - (void)captureOutput:(AVCaptureOutput *)captureOutput
        didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
               fromConnection:(AVCaptureConnection *)connection {
            if (counter==150) {
        [self StopRecording:nil];
        return;
    }
            CFArrayInsertValueAtIndex(arr, counter, sampleBuffer);

            counter= (counter+1)%150;

        }
        @end

这就是缓冲区收集方法。

最佳答案

你想做什么? AVFoundation 将 CMSampleBuffer 传递给硬件编码器。我的理论是,当它没有检测到传入的帧时,它就会停止向您传递帧。 相反,请尝试将 CVPixelBufferRef 存储在 CVPixelBufferPool 中。

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

关于ios - 将 CMSampleBufferRef 缓冲到 CFArray 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13531878/

相关文章:

ios - 轻量级迁移后core-data执行 Action

ios - MKAnnotation不显示相应的图标

ios - 将 SCNGeometry 渲染为线框

ios - 如何使用 captureStillImageAsynchronouslyFromConnection 实现多重拍摄(iOS AVFoundation)

ios - 检查应用程序更新时读取 json 错误

ios - 获取视频 IOS 6 的所有帧

avfoundation - 不同 iPad 的录音文件大小不同

iphone - 如何将介绍影片添加到我的应用程序?

macos - 我可以在 QuickTime Player 10 中设置屏幕截图的尺寸吗

cocoa - QTMovie 是否处理 URL 重定向?