-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KNOWN ISSUES: - It is highly recommended that the rotation lock be set, as there is currently a problem with camera rotation. The bug will be fixed in upcoming updates feat: - Added ability to apply filters to photos and videos (#11) - Format of captured image was changed to UIImage (#10)
- Loading branch information
1 parent
5e08682
commit 15f83d5
Showing
15 changed files
with
364 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// AVVideoComposition++.swift of MijickCameraView | ||
// | ||
// Created by Tomasz Kurylik | ||
// - Twitter: https://twitter.com/tkurylik | ||
// - Mail: tomasz.kurylik@mijick.com | ||
// - GitHub: https://github.com/FulcrumOne | ||
// | ||
// Copyright ©2024 Mijick. Licensed under MIT License. | ||
|
||
|
||
import AVKit | ||
|
||
// MARK: - Applying Filters | ||
extension AVVideoComposition { | ||
static func applyFilters(to asset: AVAsset, applyFiltersAction: @escaping (AVAsynchronousCIImageFilteringRequest) -> (), completionHandler: @escaping (AVVideoComposition?, (any Error)?) -> ()) { | ||
if #available(iOS 16.0, *) { applyFiltersNewWay(asset, applyFiltersAction, completionHandler) } | ||
else { applyFiltersOldWay(asset, applyFiltersAction, completionHandler) } | ||
} | ||
} | ||
private extension AVVideoComposition { | ||
@available(iOS 16.0, *) | ||
static func applyFiltersNewWay(_ asset: AVAsset, _ applyFiltersAction: @escaping (AVAsynchronousCIImageFilteringRequest) -> (), _ completionHandler: @escaping (AVVideoComposition?, (any Error)?) -> ()) { | ||
AVVideoComposition.videoComposition(with: asset, applyingCIFiltersWithHandler: applyFiltersAction, completionHandler: completionHandler) | ||
} | ||
static func applyFiltersOldWay(_ asset: AVAsset, _ applyFiltersAction: @escaping (AVAsynchronousCIImageFilteringRequest) -> (), _ completionHandler: @escaping (AVVideoComposition?, (any Error)?) -> ()) { | ||
let composition = AVVideoComposition(asset: asset, applyingCIFiltersWithHandler: applyFiltersAction) | ||
completionHandler(composition, nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// CIImage++.swift of MijickCameraView | ||
// | ||
// Created by Tomasz Kurylik | ||
// - Twitter: https://twitter.com/tkurylik | ||
// - Mail: tomasz.kurylik@mijick.com | ||
// - GitHub: https://github.com/FulcrumOne | ||
// | ||
// Copyright ©2024 Mijick. Licensed under MIT License. | ||
|
||
|
||
import SwiftUI | ||
|
||
extension CIImage { | ||
func applyingFilters(_ filters: [CIFilter]) -> CIImage { | ||
var ciImage = self | ||
filters.forEach { | ||
$0.setValue(ciImage, forKey: kCIInputImageKey) | ||
ciImage = $0.outputImage ?? ciImage | ||
} | ||
return ciImage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// FileManager++.swift of MijickCameraView | ||
// | ||
// Created by Tomasz Kurylik | ||
// - Twitter: https://twitter.com/tkurylik | ||
// - Mail: tomasz.kurylik@mijick.com | ||
// - GitHub: https://github.com/FulcrumOne | ||
// | ||
// Copyright ©2024 Mijick. Licensed under MIT License. | ||
|
||
|
||
import SwiftUI | ||
|
||
// MARK: - Preparing place for video output | ||
extension FileManager { | ||
static func prepareURLForVideoOutput() -> URL? { | ||
guard let fileUrl = createFileUrl() else { return nil } | ||
|
||
clearPlaceIfTaken(fileUrl) | ||
return fileUrl | ||
} | ||
} | ||
private extension FileManager { | ||
static func createFileUrl() -> URL? { | ||
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) | ||
.first? | ||
.appendingPathComponent(videoPath) | ||
} | ||
static func clearPlaceIfTaken(_ url: URL) { | ||
try? FileManager.default.removeItem(at: url) | ||
} | ||
} | ||
private extension FileManager { | ||
static var videoPath: String { "mijick-camera-view-video-output.mp4" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// UIImage.Orientation++.swift of MijickCameraView | ||
// | ||
// Created by Tomasz Kurylik | ||
// - Twitter: https://twitter.com/tkurylik | ||
// - Mail: tomasz.kurylik@mijick.com | ||
// - GitHub: https://github.com/FulcrumOne | ||
// | ||
// Copyright ©2024 Mijick. Licensed under MIT License. | ||
|
||
|
||
import SwiftUI | ||
|
||
extension UIImage.Orientation { | ||
init(_ orientation: CGImagePropertyOrientation) { switch orientation { | ||
case .down: self = .down | ||
case .downMirrored: self = .downMirrored | ||
case .left: self = .left | ||
case .leftMirrored: self = .leftMirrored | ||
case .right: self = .right | ||
case .rightMirrored: self = .rightMirrored | ||
case .up: self = .up | ||
case .upMirrored: self = .upMirrored | ||
}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.