title: Creating CMSampleBufferRef from the data
body: <p>I am trying to create a CMSampleBuffer Ref from the data and trying to feed it to AVAssetWriter. 
  But asset writer is failing to create the movie from the data. Following is the code to create the CMSampleBufferRef.</p>
  
  <pre><code>CVImageBufferRef cvimgRef = CMSampleBufferGetImageBuffer(sampleBuffer);
  CVPixelBufferLockBaseAddress(cvimgRef,0);
  
  uint8_t *buf=(uint8_t *)CVPixelBufferGetBaseAddress(cvimgRef);
  
  int width = 480;
  int height = 360;
  int bitmapBytesPerRow   = width*4;
  int bitmapByteCount     = bitmapBytesPerRow*height;
  
  
  CVPixelBufferRef pixelBufRef = NULL;
  CMSampleBufferRef newSampleBuffer = NULL;
  CMSampleTimingInfo timimgInfo = kCMTimingInfoInvalid;
  CMSampleBufferGetSampleTimingInfo(sampleBuffer, 0, &amp;timimgInfo);
  
  OSStatus result = 0;
  
  OSType pixFmt = CVPixelBufferGetPixelFormatType(cvimgRef);
  
  CVPixelBufferCreateWithBytes(kCFAllocatorDefault, width, height, pixFmt, buf, bitmapBytesPerRow, NULL, NULL, NULL, &amp;pixelBufRef);
  
  CMVideoFormatDescriptionRef videoInfo = NULL;
  
  result = CMVideoFormatDescriptionCreateForImageBuffer(NULL, pixelBufRef, &amp;videoInfo);
  
  CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBufRef, true, NULL, NULL, videoInfo, &amp;timimgInfo, &amp;newSampleBuffer);
  </code></pre>
  
  <p>Movie creation works fine when we use the original CMSampleBufferRef obtained from the AVFoundation data output callback method.</p>
  
  <p>But the same fails when I try to create the movie using the custom CMSampleBufferRef. Asset writer throws the following error:</p>
  
  <pre><code>The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)
  </code></pre>
  
  <p>Please help me out in resolving this issue.</p>