Hãy thử mã hoạt động này. Cung cấp CMSampleBufferRef được mã hóa cho sampleBuffer.
if(!decompressionSession)
{
CMFormatDescriptionRef formatDescription=CMSampleBufferGetFormatDescription(sampleBuffer);
decompressionSession = NULL;
VTDecompressionOutputCallbackRecord callBackRecord;
callBackRecord.decompressionOutputCallback=didDecompress;
callBackRecord.decompressionOutputRefCon = (__bridge void *)self;
OSStatus status1= VTDecompressionSessionCreate(kCFAllocatorDefault, formatDescription, NULL, NULL, &callBackRecord, &decompressionSession);
}
else
{
VTDecodeFrameFlags flags = kVTDecodeFrame_EnableAsynchronousDecompression;
VTDecodeInfoFlags flagOut;
VTDecompressionSessionDecodeFrame(decompressionSession, sampleBuffer, flags, NULL, &flagOut);
VTDecompressionSessionWaitForAsynchronousFrames(decompressionSession);
}
Decompression all back
static void didDecompress(void *decompressionOutputRefCon, void *sourceFrameRefCon, OSStatus status, VTDecodeInfoFlags infoFlags, CVImageBufferRef imageBuffer, CMTime presentationTimeStamp, CMTime presentationDuration){
if(status==noErr)
{
NSLog(@"SUCCESS PROCEED FROM HERE !!!!");
}
}
// Hãy nhớ, bạn cung cấp thời gian trình bày đúng khi encoding.Here tôi đang cung cấp cho bạn các chi tiết mã hóa ..
//ENCODING-------------------ENCODING---------------ENCODING
if(!_compression_session)
{
NSDictionary* pixelBufferOptions = @{
(NSString*) kCVPixelBufferWidthKey : @(widthOFCaptureImage),
(NSString*) kCVPixelBufferHeightKey : @(heightOFCaptureImage),
(NSString*) kCVPixelBufferOpenGLESCompatibilityKey : @YES,
(NSString*) kCVPixelBufferIOSurfacePropertiesKey : @{}};
_compression_session=NULL;
CFMutableDictionaryRef encoderSpecifications = NULL;
err = VTCompressionSessionCreate(
kCFAllocatorDefault,
widthOFCaptureImage,
heightOFCaptureImage,
kCMVideoCodecType_H264,
encoderSpecifications,
(__bridge CFDictionaryRef)pixelBufferOptions,
NULL,
compressionCallback,
(__bridge void *)self,
&_compression_session);
}
else
{
CMTime presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(sampleBufferIs);
CVPixelBufferRef pixelbufferPassing= CMSampleBufferGetImageBuffer(sampleBufferIs);
OSStatus status1= VTCompressionSessionEncodeFrame(_compression_session, pixelbufferPassing, presentationTimeStamp, kCMTimeInvalid, NULL, NULL, NULL);
VTCompressionSessionEndPass(_compression_session, NO, NULL);
}
// Mã hóa GỌI LẠI ------ -----------------------------------
static void compressionCallback(void *outputCallbackRefCon,
void *sourceFrameRefCon,
OSStatus status,
VTEncodeInfoFlags infoFlags,
CMSampleBufferRef sampleBuffer){
}
// Lời chúc tốt đẹp nhất :) chúc mừng mã hóa :)
Bạn đã đọc tài liệu chưa? Bạn đã xem video WWDC về chủ đề chưa? Tại sao bạn thử? – szatmary
Tôi biết đến thế giới phát trực tuyến video & video. Có, tôi đã xem video từ WWDC 2014, nhưng hiện tại nó không đủ khiến tôi nhớ một số chi tiết, điều này có thể hiển nhiên đối với bạn :) – sivan
Ồ, rất rõ ràng đối với tôi bạn đang thiếu chi tiết. Trong thực tế, bạn không có đủ chi tiết trong câu hỏi của bạn để thậm chí trả lời nó. Định dạng luồng h264 của bạn là gì? Là phụ lục B? Bạn có con trỏ đến SPS/PPS không? – szatmary