Question

I'm trying to create a custom patch for Quartz Composer that captures from a FireWire input. I can open the device and add the input successfully. I even disable the audio inputs as per the QTKit documentation. I suspect my problem is either adding the output (although it adds without error). Every time the frame runs it crashes when it appears the imageBuffer is empty. It has no dimensions or anything. I'm using the standard captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection from the documentation.

   [mCaptureDecompressedVideoOutput release];
    mCaptureDecompressedVideoOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
    NSLog(@"allocated mCaptureDecompressedVideoOutput");
    [mCaptureDecompressedVideoOutput setPixelBufferAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [NSNumber numberWithBool:YES], kCVPixelBufferOpenGLCompatibilityKey,
      [NSNumber numberWithLong:k32ARGBPixelFormat], kCVPixelBufferPixelFormatTypeKey, nil]];


    [mCaptureDecompressedVideoOutput setDelegate:self];
    success = [mCaptureSession addOutput:mCaptureDecompressedVideoOutput error:&error];

    if (!success) {
        NSLog(@"Failed to add output");
            self.outputImage = nil; 
        if (mCaptureSession) {
            [mCaptureSession release];
            mCaptureSession= nil;
        }
        if (mCaptureDeviceInput) {
            [mCaptureDeviceInput release];
            mCaptureDeviceInput= nil;
        }
        if (mCaptureDecompressedVideoOutput) {
            [mCaptureDecompressedVideoOutput release];
            mCaptureDecompressedVideoOutput= nil;
        }
        return YES;
    }

    [mCaptureSession startRunning]; 
        _currentDevice= self.inputDevice;
    }

    CVImageBufferRef imageBuffer = CVBufferRetain(mCurrentImageBuffer);

if (imageBuffer) {
    CVPixelBufferLockBaseAddress(imageBuffer, 0);
    NSLog(@"ColorSpace: %@", CVImageBufferGetColorSpace(imageBuffer));

    id provider= [context outputImageProviderFromBufferWithPixelFormat:QCPlugInPixelFormatARGB8           
                                                            pixelsWide:CVPixelBufferGetWidth(imageBuffer)
                                                            pixelsHigh:CVPixelBufferGetHeight(imageBuffer)
                                                           baseAddress:CVPixelBufferGetBaseAddress(imageBuffer)
                                                           bytesPerRow:CVPixelBufferGetBytesPerRow(imageBuffer)
                                                       releaseCallback:_BufferReleaseCallback
                                                        releaseContext:imageBuffer
                                                            colorSpace:CVImageBufferGetColorSpace(imageBuffer)
                                                      shouldColorMatch:YES];

What could I be doing wrong? This code works great for video only inputs, but not for FireWire (muxed) inputs.

Was it helpful?

Solution

I managed to get this patch to work with both Video and Muxed inputs by removing the kCVPixelBufferOpenGLCompatibilityKey from mCaptureDecompressedVideoOutput. While that allows the patch to work perfectly inside Quartz Composer, my intent is to run this patch in a composition that is used inside CamTwist, which appears not to need OpenGL support. Right now, it just displays a black screen with wither Video or Muxed inputs, where it was working with Video inputs before. So, I'm going to convert my CVImageBufferRef to an OpenGL texture and see if I can get that to work with

outputImageProviderFromTextureWithPixelFormat:pixelsWide:pixelsHigh:name:flipped:releaseCallback:releaseContext:colorSpace:shouldColorMatch
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top