Creating a CMSampleBufferRef from Data

I am trying to create a CMSampleBuffer Ref from data and trying to pass it to AVAssetWriter. But the owner of the resource cannot create a movie from the data. Below is the code to create the CMSampleBufferRef.

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, &timimgInfo); OSStatus result = 0; OSType pixFmt = CVPixelBufferGetPixelFormatType(cvimgRef); CVPixelBufferCreateWithBytes(kCFAllocatorDefault, width, height, pixFmt, buf, bitmapBytesPerRow, NULL, NULL, NULL, &pixelBufRef); CMVideoFormatDescriptionRef videoInfo = NULL; result = CMVideoFormatDescriptionCreateForImageBuffer(NULL, pixelBufRef, &videoInfo); CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBufRef, true, NULL, NULL, videoInfo, &timimgInfo, &newSampleBuffer); 

Making a movie works great when we use the original CMSampleBufferRef obtained from the AVFoundation output callback method.

But the same thing fails when I try to create a movie using a custom CMSampleBufferRef. The script generates the following error:

 The operation couldn't be completed. (AVFoundationErrorDomain error -11800.) 

Please help me in solving this problem.

+7
iphone avfoundation
source share
2 answers

You should study AVAssetWriterInputPixelBufferAdaptor - it accepts CVPixelBuffers, so you don't need to convert CVPixelBuffer to CMSampleBuffer.

here is a link to the thread about it on the apple dev forum β†’ https://devforums.apple.com/thread/70258?tstart=0

In addition, you can publish your project file or sample code of the captured movie - I use the default CMSampleBuffer from the AVFoundation output callback method, but when I save it in the camera frame, everything is black except the last 5 frames that I have to manually hide to: S

any help regarding my problem would be greatly appreciated.

Greetings

Michael

+4
source share
  The operation couldn't be completed. (AVFoundationErrorDomain error -11800.) 

For this error, this always happens when timingInfo not valid. he needs to set it to valid values ​​using PTS and Duration .

 CMSampleTimingInfo timingInfo = kCMTimingInfoInvalid; timingInfo.presentationTimeStamp = pts; timingInfo.duration = duration; 
+1
source share

All Articles