मैं CGImage
से CMSampleBufferRef
में कनवर्ट करना चाहता हूं और इसे appendSampleBuffer:
विधि का उपयोग करके AVAssetWriterInput
पर जोड़ना चाहता हूं। मैंने निम्नलिखित कोड का उपयोग करके CMSampleBufferRef
प्राप्त करने में कामयाब रहा है, लेकिन appendSampleBuffer:
जब मैं परिणामी CMSampleBufferRef
की आपूर्ति करता हूं तो बस NO
देता है। मैं क्या गलत कर रहा हूं?मैं CGImage को CMSampleBufferRef में कैसे परिवर्तित करूं?
- (void) appendCGImage: (CGImageRef) frame
{
const int width = CGImageGetWidth(frame);
const int height = CGImageGetHeight(frame);
// Create a dummy pixel buffer to try the encoding
// on something simple.
CVPixelBufferRef pixelBuffer = NULL;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, width, height,
kCVPixelFormatType_32BGRA, NULL, &pixelBuffer);
NSParameterAssert(status == kCVReturnSuccess && pixelBuffer != NULL);
// Sample timing info.
CMTime frameTime = CMTimeMake(1, 30);
CMTime currentTime = CMTimeAdd(lastSampleTime, frameTime);
CMSampleTimingInfo timing = {frameTime, currentTime, kCMTimeInvalid};
OSStatus result = 0;
// Sample format.
CMVideoFormatDescriptionRef videoInfo = NULL;
result = CMVideoFormatDescriptionCreateForImageBuffer(NULL,
pixelBuffer, &videoInfo);
NSParameterAssert(result == 0 && videoInfo != NULL);
// Create sample buffer.
CMSampleBufferRef sampleBuffer = NULL;
result = CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault,
pixelBuffer, true, NULL, NULL, videoInfo, &timing, &sampleBuffer);
NSParameterAssert(result == 0 && sampleBuffer != NULL);
// Ship out the frame.
NSParameterAssert(CMSampleBufferDataIsReady(sampleBuffer));
NSParameterAssert([writerInput isReadyForMoreMediaData]);
BOOL success = [writerInput appendSampleBuffer:frame];
NSParameterAssert(success); // no go :(
}
पीएस मुझे पता है कि इस कोड में मेमोरी लीक हैं, मैंने सादगी के लिए कुछ कोड छोड़े हैं।
हाय क्या आप कोड को पोस्ट कर सकते हैं जो इसे काम करता है? – Ondrej
कोई भी कभी भी समाधान ढूंढता है :-) – DogCoffee
HI! क्या आप कृपया हमारे साथ कोड साझा कर सकते हैं? –