4

我正在尝试将我从 iPhone 的摄像机收到的 150 个 CMSampleBufferRef 收集到一个数组中。不知何故,相机在 13 个缓冲区后停止调用委托。我尝试使用 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

这就是缓冲区收集方法。

4

1 回答 1

2

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

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
于 2014-02-26T10:05:24.217 回答