我正在尝试裁剪视频帧。我已经使用AVFoundation
框架录制了视频。我需要将拍摄的图像和录制的视频裁剪成方形。我已经完成了它的UIImage
工作,现在我正在尝试裁剪视频。
- (UIImage *)squareImageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { // Cropping UIImage is working fine. CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], CGRectMake(0,0, image.size.width, image.size.width)); UIImage *result = [UIImage imageWithCGImage:imageRef scale:image.scale orientation:image.imageOrientation]; CGImageRelease(imageRef); return result; }
我试图裁剪视频,但结果是在没有裁剪的情况下更改了整个视频帧,并且看起来被拉伸了。
_writer = [AVAssetWriter assetWriterWithURL:url fileType:AVFileTypeQuickTimeMovie error:nil]; NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys: AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithInt: 320], AVVideoWidthKey, [NSNumber numberWithInt: 320], AVVideoHeightKey, nil]; _videoInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:settings]; [_writer addInput:_videoInput];
有人可以帮我解决这个视频裁剪问题吗?提前致谢。