1.
- (void)dealWithSampleBuffer:(CMSampleBufferRef)buffer { CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(buffer); CIImage *ciimage = [CIImage imageWithCVPixelBuffer:pixelBuffer]; size_t width = CVPixelBufferGetWidth(pixelBuffer); size_t height = CVPixelBufferGetHeight(pixelBuffer); // 旋转的方法 CIImage *wImage = [ciimage imageByApplyingCGOrientation:kCGImagePropertyOrientationLeft]; CIImage *newImage = [wImage imageByApplyingTransform:CGAffineTransformMakeScale(0.5, 0.5)]; CVPixelBufferLockBaseAddress(pixelBuffer, 0); CVPixelBufferRef newPixcelBuffer = nil; CVPixelBufferCreate(kCFAllocatorDefault, height * 0.5, width * 0.5, kCVPixelFormatType_32BGRA, nil, &newPixcelBuffer); [_ciContext render:newImage toCVPixelBuffer:newPixcelBuffer]; // CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); CMVideoFormatDescriptionRef videoInfo = nil; CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, newPixcelBuffer, &videoInfo); CMTime duration = CMSampleBufferGetDuration(buffer); CMTime presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(buffer); CMTime decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(buffer); CMSampleTimingInfo sampleTimingInfo; sampleTimingInfo.duration = duration; sampleTimingInfo.presentationTimeStamp = presentationTimeStamp; sampleTimingInfo.decodeTimeStamp = decodeTimeStamp; // CMSampleBufferRef newSampleBuffer = nil; CMSampleBufferCreateForImageBuffer(kCFAllocatorMalloc, newPixcelBuffer, true, nil, nil, videoInfo, &sampleTimingInfo, &newSampleBuffer); // 对新buffer做处理 // release CVPixelBufferRelease(newPixcelBuffer); CFRelease(newSampleBuffer); }
https://www.jianshu.com/p/205083b93c1c