I am using AVFoundation and getting the sample buffer from AVCaptureVideoDataOutput, I can write it directly to videoWriter by using:
- (void)writeBufferFrame:(CMSampleBufferRef)sampleBuffer {
CMTime lastSampleTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
if(self.videoWriter.status != AVAssetWriterStatusWriting)
{
[self.videoWriter startWriting];
[self.videoWriter startSessionAtSourceTime:lastSampleTime];
}
[self.videoWriterInput appendSampleBuffer:sampleBuffer];
}
What I want to do now is to crop and scale the image inside the CMSampleBufferRef without converting it into UIImage or CGImageRef because that slows down the performance.
If you use vimage you can work directly on the buffer data without converting it to any image format.
outImgcontains the cropped and scaled image data. The relation betweenoutWidthandcropWidthsets the scaling.So setting
cropX0 = 0andcropY0 = 0andcropWidthandcropHeightto the original size means no cropping (using the whole original image). SettingoutWidth = cropWidthandoutHeight = cropHeightresults in no scaling. Note thatinBuff.rowBytesshould always be the length of the full source buffer, not the cropped length.