现在我正在制作一个应用程序来拍摄像 Instagram 这样的方形电影。我正在尝试在 GPUImage 中使用cropFilter 来裁剪视频。视频真的很方形,但看起来拉伸和破碎的比例。
我是这样写的。
videoView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.width)
videoView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill
self.view.addSubview(videoView)
videoCamera.outputImageOrientation = .Portrait
videoCamera.addTarget(videoView)
let documentDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let fileName = "video.mp4"
pathToMovie = (documentDirectory as NSString).stringByAppendingPathComponent(fileName)
let movieURL = NSURL(fileURLWithPath: pathToMovie)
unlink((pathToMovie as NSString).UTF8String)
movieWriter = GPUImageMovieWriter(movieURL: movieURL, size: CGSize(width: 480, height: 480))
movieWriter.encodingLiveVideo = true
movieWriter.shouldPassthroughAudio = true
movieWriter.assetWriter.movieFragmentInterval = kCMTimeInvalid
videoCamera.addTarget(movieWriter)
videoCamera.audioEncodingTarget = movieWriter
let cropFilter = GPUImageCropFilter(cropRegion: CGRect(x: 0, y: 0.125, width: 1.0, height: 0.75))
videoCamera.addTarget(cropFilter)
cropFilter.addTarget(movieWriter)
videoCamera.startCameraCapture()
movieWriter.startRecording()
任何人,请帮助。