title: Convert CVImageBufferRef to CVPixelBufferRef
body: <p>I am new to iOS programming and multimedia and I was going through a sample project named RosyWriter provided by apple at <a href="https://developer.apple.com/library/ios/samplecode/RosyWriter/Listings/Classes_RosyWriterVideoProcessor_m.html#//apple_ref/doc/uid/DTS40011110-Classes_RosyWriterVideoProcessor_m-DontLinkElementID_8" rel="noreferrer">this link</a>. Here I saw that in the code there is a function named <code>captureOutput:didOutputSampleBuffer:fromConnection</code> in the code given below:</p>
  <pre><code>- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 
  {   
  CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
  
  if ( connection == videoConnection ) {
      
      // Get framerate
      CMTime timestamp = CMSampleBufferGetPresentationTimeStamp( sampleBuffer );
      [self calculateFramerateAtTimestamp:timestamp];
      
      // Get frame dimensions (for onscreen display)
      if (self.videoDimensions.width == 0 &amp;&amp; self.videoDimensions.height == 0)
          self.videoDimensions = CMVideoFormatDescriptionGetDimensions( formatDescription );
      
      // Get buffer type
      if ( self.videoType == 0 )
          self.videoType = CMFormatDescriptionGetMediaSubType( formatDescription );
  
      CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
      
      // Synchronously process the pixel buffer to de-green it.
      [self processPixelBuffer:pixelBuffer];
      
      // Enqueue it for preview.  This is a shallow queue, so if image processing is taking too long,
      // we'll drop this frame for preview (this keeps preview latency low).
      OSStatus err = CMBufferQueueEnqueue(previewBufferQueue, sampleBuffer);
      if ( !err ) {        
          dispatch_async(dispatch_get_main_queue(), ^{
              CMSampleBufferRef sbuf = (CMSampleBufferRef)CMBufferQueueDequeueAndRetain(previewBufferQueue);
              if (sbuf) {
                  CVImageBufferRef pixBuf = CMSampleBufferGetImageBuffer(sbuf);
                  [self.delegate pixelBufferReadyForDisplay:pixBuf];
                  CFRelease(sbuf);
              }
          });
      }
  }
  
  CFRetain(sampleBuffer);
  CFRetain(formatDescription);
  dispatch_async(movieWritingQueue, ^{
  
      if ( assetWriter ) {
      
          BOOL wasReadyToRecord = (readyToRecordAudio &amp;&amp; readyToRecordVideo);
          
          if (connection == videoConnection) {
              
              // Initialize the video input if this is not done yet
              if (!readyToRecordVideo)
                  readyToRecordVideo = [self setupAssetWriterVideoInput:formatDescription];
              
              // Write video data to file
              if (readyToRecordVideo &amp;&amp; readyToRecordAudio)
                  [self writeSampleBuffer:sampleBuffer ofType:AVMediaTypeVideo];
          }
          else if (connection == audioConnection) {
              
              // Initialize the audio input if this is not done yet
              if (!readyToRecordAudio)
                  readyToRecordAudio = [self setupAssetWriterAudioInput:formatDescription];
              
              // Write audio data to file
              if (readyToRecordAudio &amp;&amp; readyToRecordVideo)
                  [self writeSampleBuffer:sampleBuffer ofType:AVMediaTypeAudio];
          }
          
          BOOL isReadyToRecord = (readyToRecordAudio &amp;&amp; readyToRecordVideo);
          if ( !wasReadyToRecord &amp;&amp; isReadyToRecord ) {
              recordingWillBeStarted = NO;
              self.recording = YES;
              [self.delegate recordingDidStart];
          }
      }
      CFRelease(sampleBuffer);
      CFRelease(formatDescription);
  });
  }
  </code></pre>
  <p>Here a function named <code>pixelBufferReadyForDisplay</code> is called which expects a parameter of type <code>CVPixelBufferRef</code></p>
  <p><strong>Prototype of pixelBufferReadyForDisplay</strong></p>
  <pre><code>- (void)pixelBufferReadyForDisplay:(CVPixelBufferRef)pixelBuffer; 
  </code></pre>
  <p>But in the code above while calling this function it passes the variable <code>pixBuf</code> which is of type <code>CVImageBufferRef</code></p>
  <p>So my question is that isn't it required to use any function or typecasting to convert a CVImageBufferRef to CVPixelBufferRef or is this done implicitly by the compiler?</p>
  <p>Thanks.</p>