'custom resolution for video AV Fondation
I use AVCaptureMovieFileOutput to recording video, but output video resolution depends on the AVCaptureSession.sessionPreset = xxxx. How i can set custom resolution for a video?
I find solution: set session preset on :
guard let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back) else {
print("Could not create capture device.")
return
}
// 1) Set session preset on .inputPriority
captureSession.sessionPreset = .inputPriority
guard let deviceInput = try? AVCaptureDeviceInput(device: captureDevice) else {
print("Could not create device input.")
return
}
if captureSession.canAddInput(deviceInput) {
captureSession.addInput(deviceInput)
}
var activFormat = captureDevice.formats.last
//2) find specific formats
for format in captureDevice.formats
{
let dimensions = CMVideoFormatDescriptionGetDimensions(format)
if dimensions.width == 1920 && dimensions.height == 1440
{
activFormat = item
}
}
//3) set specific format
do {
try captureDevice.lockForConfiguration()
captureDevice.activeFormat = activFormat!
captureDevice.unlockForConfiguration()
} catch {
print("Could not set active format error: \(error)")
return
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
