ビデオを正方形のUIViewに録画していますが、ビデオをエクスポートすると1080x1920のフルスクリーンになりました。ビデオをフルスクリーンから1:1の正方形に縮小する方法が不思議です...クロップビデオスウィフト
session = AVCaptureSession()
for device in AVCaptureDevice.devices() {
if let device = device as? AVCaptureDevice , device.position == AVCaptureDevicePosition.back {
self.device = device
}
}
for device in AVCaptureDevice.devices(withMediaType: AVMediaTypeAudio) {
let device = device as? AVCaptureDevice
let audioInput = try! AVCaptureDeviceInput(device: device)
session?.addInput(audioInput)
}
do {
if let session = session {
videoInput = try AVCaptureDeviceInput(device: device)
session.addInput(videoInput)
videoOutput = AVCaptureMovieFileOutput()
let totalSeconds = 60.0 //Total Seconds of capture time
let timeScale: Int32 = 30 //FPS
let maxDuration = CMTimeMakeWithSeconds(totalSeconds, timeScale)
videoOutput?.maxRecordedDuration = maxDuration
videoOutput?.minFreeDiskSpaceLimit = 1024 * 1024//SET MIN FREE SPACE IN BYTES FOR RECORDING TO CONTINUE ON A VOLUME
if session.canAddOutput(videoOutput) {
session.addOutput(videoOutput)
}
let videoLayer = AVCaptureVideoPreviewLayer(session: session)
videoLayer?.frame = self.videoPreview.bounds
videoLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
self.videoPreview.layer.addSublayer(videoLayer!)
session.startRunning()
が、私は彼らは非常に有用見つけ、そしてそれらのほとんどがobj Cにあるいくつかの他の記事を見てなくて...
の場合:私は、私のビデオカメラを設定していますどのようにここで
です誰でも私を助けたり、正しい方向に私を置くことができます。それは非常に感謝しています!
FileManager.getOutputPath(String.random()が何であるか質問してもいいですか?) –
Hey Jack、FileManagerはファイル関連のものを処理するカスタムクラスです。FileManager.getOutputPath (String.random())は、ランダムなStringファイル名をとり、そのファイルへのurlパスを出力します。それに応じて私の答えを更新しました。 – AndreasLukas
それは良いと思われます。 +1を今すぐ受け入れます。ありがとうたくさんあります。 –