title: Decoding H264 VideoToolkit API fails with Error -12911 in VTDecompressionSessionDecodeFrame
body: <p>I'm trying to decode a raw stream of .H264 video data but I can't find a way to create a proper </p>
  
  <pre><code>    - (void)decodeFrameWithNSData:(NSData*)data presentationTime:
  
  (CMTime)presentationTime
  {
  
      @autoreleasepool {
  
      CMSampleBufferRef sampleBuffer = NULL;
      CMBlockBufferRef blockBuffer = NULL;
      VTDecodeInfoFlags infoFlags;
      int sourceFrame;
  
      if( dSessionRef == NULL )
          [self createDecompressionSession];
  
  
      CMSampleTimingInfo timingInfo ;
      timingInfo.presentationTimeStamp = presentationTime;
      timingInfo.duration =  CMTimeMake(1,100000000);
      timingInfo.decodeTimeStamp = kCMTimeInvalid;
  
      //Creates block buffer from NSData
      OSStatus status  = CMBlockBufferCreateWithMemoryBlock(CFAllocatorGetDefault(), (void*)data.bytes,data.length*sizeof(char), CFAllocatorGetDefault(), NULL, 0, data.length*sizeof(char), 0, &amp;blockBuffer);
  
      //Creates CMSampleBuffer to feed decompression session    
      status = CMSampleBufferCreateReady(CFAllocatorGetDefault(), blockBuffer,self.encoderVideoFormat,1,1,&amp;timingInfo, 0, 0, &amp;sampleBuffer);
  
      status = VTDecompressionSessionDecodeFrame(dSessionRef,sampleBuffer, kVTDecodeFrame_1xRealTimePlayback, &amp;sourceFrame,&amp;infoFlags);
  
  
      if(status != noErr) {
          NSLog(@"Decode with data error %d",status);
      }
  
  
      }
  }
  </code></pre>
  
  <p>At the end of the call I'm getting -12911 error in VTDecompressionSessionDecodeFrame that translates to kVTVideoDecoderMalfunctionErr which after reading this [post] pointed me that I should make a VideoFormatDescriptor using CMVideoFormatDescriptionCreateFromH264ParameterSets. But how can I create a new VideoFormatDescription if I don't have information of the currentSps or currentPps? How can I get that information from my raw .H264 streaming?</p>
  
  <pre><code>CMFormatDescriptionRef decoderFormatDescription;
  const uint8_t* const parameterSetPointers[2] = 
      { (const uint8_t*)[currentSps bytes], (const uint8_t*)[currentPps bytes] };
  const size_t parameterSetSizes[2] = 
      { [currentSps length], [currentPps length] };
  status = CMVideoFormatDescriptionCreateFromH264ParameterSets(NULL,
         2,
         parameterSetPointers,
         parameterSetSizes,
         4,
         &amp;decoderFormatDescription);
  </code></pre>
  
  <p>Thanks in advance,</p>
  
  <p>Marcos</p>
  
  <p>[post] : <a href="https://stackoverflow.com/questions/24039345/decoding-h264-videotoolkit-api-fails-with-error-8971-in-vtdecompressionsessionc">Decoding H264 VideoToolkit API fails with Error -8971 in VTDecompressionSessionCreate</a> </p>