From 1bbeb0da5e418056785bdab0b31846f88600c264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lui=CC=81s=20Silva?= Date: Thu, 14 Feb 2019 21:36:42 +0000 Subject: [PATCH] Adds support to set AVVideoCodecType, fixes uninitialized property --- Source/SwiftyCamViewController.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Source/SwiftyCamViewController.swift b/Source/SwiftyCamViewController.swift index 9ad4503..61da7b8 100644 --- a/Source/SwiftyCamViewController.swift +++ b/Source/SwiftyCamViewController.swift @@ -125,7 +125,7 @@ open class SwiftyCamViewController: UIViewController { /// Sets whether flash is enabled for photo and video capture @available(*, deprecated, message: "use flashMode .on or .off") //use flashMode - public var flashEnabled: Bool { + public var flashEnabled: Bool = false { didSet{ self.flashMode = self.flashEnabled ? .on : .off } @@ -293,6 +293,10 @@ open class SwiftyCamViewController: UIViewController { return allowAutoRotate } + /// Sets output video codec + + public var videoCodecType: AVVideoCodecType? = nil + // MARK: ViewDidLoad /// ViewDidLoad Implementation @@ -781,6 +785,15 @@ open class SwiftyCamViewController: UIViewController { if connection.isVideoStabilizationSupported { connection.preferredVideoStabilizationMode = .auto } + + if #available(iOS 11.0, *) { + if let videoCodecType = videoCodecType { + if movieFileOutput.availableVideoCodecTypes.contains(videoCodecType) == true { + // Use the H.264 codec to encode the video. + movieFileOutput.setOutputSettings([AVVideoCodecKey: videoCodecType], for: connection) + } + } + } } self.movieFileOutput = movieFileOutput }