Mac Help Forums


Reply
Thread Tools Display Modes

getting frames by display link

 
New Member
Join Date: Mar 2008
Posts: 2
 
      10th March 2008
Hi all, I am working on an application that involves real time video editing with Core Framework in Cocoa. For testing we basically have a DVI cam hooked up to a Mac Book Pro and need to be able to edit the stream it produces. I successfully got the video into quick time using QTKit, but am having trouble aquiring the frames with a display link. The example in the Core Video guide shows it initializing the video source from file with this method:
  • (id)initWithFilePathNSString*)theFilePath
, but I need to get the frames I can already access into the display link for OpenGL rendering and Core Image effects. If anyone has any ideas or advice I would greatly appreciate it. Thanks in advance!
 
Reply With Quote
 
 
 
 
New Member
Join Date: Mar 2008
Posts: 2
 
      10th March 2008
Right now i have it output via QTCaptureView. But if I want to do openGL rendering/Core Image effects on the frame does it need to be an NSOpenGLView?

Here is what I have for code so far:
Code:
 //
  //  VideoDisplayController.m
  //  Prototype492
  //
  //  Created by Christopher Sanders on 3/7/08.
  //  Copyright 2008 __CIS492__. All rights reserved.
  //
  
  #import "VideoDisplayController.h"
  
  @implementation VideoDisplayController 
  
  /*
      start the video capture session if it's not running
  */
  - (IBAction)startVideoCapture:(id)sender
  {
  
      if(![captureSession isRunning])
      {
          [captureSession startRunning];
      }
  }
  
  /*
      stop the video capture session if it's running
  */
  
  - (IBAction)stopVideoCapture:(id)sender
  {
      if([captureSession isRunning])
      {
          [captureSession stopRunning];
      }
  
  }
  
  
  /*
  initialization of UI elements
  */
  - (void)awakeFromNib
  {
      NSLog(@"initializing video controller");
  
      if(!captureSession) {
  
          //creating capture session
  
          captureSession = [[QTCaptureSession alloc] init];
  
  
          //flags for connecting inputs and outputs
          BOOL successConnect = NO;
          NSError *error = nil;
  
  
          //finding and creating the input device and adding it to the capture session
          //if unsuccessful, send a message to error log
  
  
          //note: using QTMediaTypeMuxed for DV camera... otherwise use QTMediaTypeVideo
          videoCaptureDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeMuxed];
  
          //if the video capture device is found, attempt to open it and add it to the capture session
          if(videoCaptureDevice)
          {
              successConnect = [videoCaptureDevice open:&error];
  
  
            if(!successConnect)
            {
  
                NSLog(@"error opening video capture device");
                  videoCaptureDevice = nil;
  
                //other error handling code goes here
            }
  
              captureVideoDeviceInput = [[QTCaptureDeviceInput alloc] initWithDevice:videoCaptureDevice];
  
  
              //attempt to add capture device input to the capture session
            successConnect = [captureSession addInput:captureVideoDeviceInput error:&error];
  
            if(!successConnect)
            {
                NSLog(@"error adding video capture device input to capture session");
  
                  //other error handling code goes here
              }
  
              //adding decompressed video output to capture session
  
              decompressedVideoOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  
              //assigning delegate to decompressed video output
  
              [decompressedVideoOutput setDelegate: self];
  
              successConnect = [captureSession addOutput:decompressedVideoOutput error:&error];
  
              if(!successConnect)
              {
                  NSLog(@"error adding decompressed video output to capture session");
  
                    //other error handling code goes here
  
              }
  
  
              //linking capture session to the capture view
            [captureView setCaptureSession:captureSession];
  
            //[captureSession startRunning];
          }
          else
          {
              NSLog(@"couldn't find video capture device");
          }
      }
  }
  
  
  /*
  delegate method called when decompressedVideoOutput receives a frame
  it is not called in the main thread, so a synhronized block is used
  delegates of decompressedVideoOutput receive this message 
  and then can used the provided video frame for further image processing
  
  captureOutput - the QTCaptureDecompressedVideoOutput instance that sent the frame (decompressedVideoOutput)
  videoFrame - Core Video image buffer containing the decompressed frame
  sampleBuffer sample buffer containing additional info about the frame
  connection - connnection from which vdieo was received
  */
  
  
  - (void)captureOutput:(QTCaptureOutput *)captureOutput 
          didOutputVideoFrame:(CVImageBufferRef)videoFrame
          withSampleBuffer:(QTSampleBuffer *)sampleBuffer 
          fromConnection:(QTCaptureConnection *)connection
  {
      CVImageBufferRef releasedImageBuffer;
  
  
      CVBufferRetain(videoFrame);
  
  
      @synchronized(self)
      {
          //basically, have frame to be released refer to the current frame
        //then update the reference to the current frame with the next frame in the "video stream"
          releasedImageBuffer = currentImageBuffer;
          currentImageBuffer = videoFrame;
      }
  
      CVBufferRelease(releasedImageBuffer);
  
  }
  
  
  
  
  
  /*
  event that's fired when window is closed
  stop the session and close any opened devices
  */
  - (void)windowWillClose:(NSNotification *)notification
  {
      if([captureSession isRunning])
      {
          [captureSession stopRunning];
      }
  
      if([videoCaptureDevice isOpen])
      {
          [videoCaptureDevice close];
      }
  
  }
  
  /*
  event that fires when memory is to be deallocated when object is killed
  */
  - (void)dealloc
  {
  
      [captureSession release];
      [captureVideoDeviceInput release];
      [decompressedVideoOutput release];
  
      [super dealloc];
  }
  
  
  @end
  
  
  //
  //  VideoDisplayController.h
  //  Prototype492v1.1
  //
  //  Updated by Christopher Sanders on 3/8/08.
  //  Copyright 2008 CIS492. All rights reserved.
  //
  
  #import <Cocoa/Cocoa.h>
  #import <QTKit/QTkit.h>
  #import "VideoView.h"
  
  @interface VideoDisplayController : NSOpenGLView 
  {
      QTCaptureSession *captureSession;
      QTCaptureDevice *videoCaptureDevice;
      QTCaptureDeviceInput *captureVideoDeviceInput;
      QTCaptureDecompressedVideoOutput *decompressedVideoOutput;
  
      //stores most recent frame grabbed from a CVImageBufferRef
      CVImageBufferRef currentImageBuffer;
  
  
      //this is the panel on which the video from the DV camera will be displayed
      IBOutlet QTCaptureView *captureView;
  
  
      //IBOutlet VideoView *openGLVideoView;
  
  }
  
  
  
  - (IBAction)startVideoCapture:(id)sender;
  - (IBAction)stopVideoCapture:(id)sender;
  
  
  @end
 
Reply With Quote
 
Senior Member
Kaveman's Avatar
Join Date: Nov 2010
Location: Westland, NZ
Posts: 1,360
 
      12th June 2011
Again a very old post:
But for anyone coming to here looking for help, Apple has a great range of very specialised Mail Groups who have gurus in this field.

http://lists.apple.com/mailman/listinfo
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jumbo frames Henry UK Macs 4 4th April 2008 03:13 PM
Getting frames with display link echosummet@gmail.com Programmer Help 3 18th March 2008 05:31 AM
Safari link display Paul Sperry Apps 3 7th December 2007 10:25 PM
program for frames on iphotos hurlebaus Apps 0 5th September 2007 06:19 PM
Frames per second in Flash Thom White UK Macs 3 16th April 2004 01:50 PM


All times are GMT +1. The time now is 09:43 PM.
Mac-Help.com is an independent website and is not affiliated with Apple Inc.


Welcome!
Welcome to the Mac Help Forums
 


Latest Threads
Yikes! Teacher needs help!
Mollyc4627 (46 Minutes Ago, 08:57 PM)

Unable to log in to websites
AMonty20 (3 Hours Ago, 05:52 PM)

Add Different Speech Commands
bae_22 (5 Hours Ago, 04:40 PM)

Login (2 macs) passwords spontaniously changed?
Roger Vaught (6 Hours Ago, 03:31 PM)

Best car charger or inverter for Macbook Pro?
imeme87 (6 Hours Ago, 03:22 PM)

 


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51