title: Create CVPixelBufferRef from CIImage for Writing to File
body: <p>I'm writing a custom Movie Recording app and have implemented AVAssetWriter and AVAssetWriterInputPixelBufferAdaptor for writing frames to a file. In the DataOutputDelegate callback I am trying to apply a CIFilter to the sampleBuffer. First I get a CVPixelBufferRef and then create a CIImage. I then apply the CIIFilter and grab the resulting CIImage:</p>
  
  <pre><code>    CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
  
      CIImage *image = [CIImage imageWithCVPixelBuffer:pixelBuffer];
      CIFilter *hueAdjust = [CIFilter filterWithName:@"CIHueAdjust"];
      [hueAdjust setDefaults];
      [hueAdjust setValue: image forKey: @"inputImage"];
      [hueAdjust setValue: [NSNumber numberWithFloat: 2.094]
                   forKey: @"inputAngle"];
  
      CIImage *result = [hueAdjust valueForKey: @"outputImage"];
  
      CVPixelBufferRef newBuffer = //Convert CIImage...
  </code></pre>
  
  <p>How would I go about converting that CIImage so I can:</p>
  
  <pre><code>    [self.filteredImageWriter appendPixelBuffer:newBuffer withPresentationTime:lastSampleTime];
  </code></pre>