fix(camera): modernize mp4 export
This commit is contained in:
@@ -199,13 +199,22 @@ actor CameraController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private nonisolated static func exportToMP4(inputURL: URL, outputURL: URL) async throws {
|
private nonisolated static func exportToMP4(inputURL: URL, outputURL: URL) async throws {
|
||||||
let asset = AVAsset(url: inputURL)
|
let asset = AVURLAsset(url: inputURL)
|
||||||
guard let exporter = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality) else {
|
guard let exporter = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality) else {
|
||||||
throw CameraError.exportFailed("Failed to create export session")
|
throw CameraError.exportFailed("Failed to create export session")
|
||||||
}
|
}
|
||||||
|
exporter.shouldOptimizeForNetworkUse = true
|
||||||
|
|
||||||
|
if #available(iOS 18.0, tvOS 18.0, visionOS 2.0, *) {
|
||||||
|
do {
|
||||||
|
try await exporter.export(to: outputURL, as: .mp4)
|
||||||
|
return
|
||||||
|
} catch {
|
||||||
|
throw CameraError.exportFailed(error.localizedDescription)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
exporter.outputURL = outputURL
|
exporter.outputURL = outputURL
|
||||||
exporter.outputFileType = .mp4
|
exporter.outputFileType = .mp4
|
||||||
exporter.shouldOptimizeForNetworkUse = true
|
|
||||||
|
|
||||||
try await withCheckedThrowingContinuation(isolation: nil) { cont in
|
try await withCheckedThrowingContinuation(isolation: nil) { cont in
|
||||||
exporter.exportAsynchronously {
|
exporter.exportAsynchronously {
|
||||||
@@ -223,6 +232,7 @@ actor CameraController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
|
private final class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
|
||||||
private let continuation: CheckedContinuation<Data, Error>
|
private let continuation: CheckedContinuation<Data, Error>
|
||||||
|
|||||||
@@ -200,13 +200,22 @@ actor CameraCaptureService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private nonisolated static func exportToMP4(inputURL: URL, outputURL: URL) async throws {
|
private nonisolated static func exportToMP4(inputURL: URL, outputURL: URL) async throws {
|
||||||
let asset = AVAsset(url: inputURL)
|
let asset = AVURLAsset(url: inputURL)
|
||||||
guard let export = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetMediumQuality) else {
|
guard let export = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetMediumQuality) else {
|
||||||
throw CameraError.exportFailed("Failed to create export session")
|
throw CameraError.exportFailed("Failed to create export session")
|
||||||
}
|
}
|
||||||
|
export.shouldOptimizeForNetworkUse = true
|
||||||
|
|
||||||
|
if #available(macOS 15.0, *) {
|
||||||
|
do {
|
||||||
|
try await export.export(to: outputURL, as: .mp4)
|
||||||
|
return
|
||||||
|
} catch {
|
||||||
|
throw CameraError.exportFailed(error.localizedDescription)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
export.outputURL = outputURL
|
export.outputURL = outputURL
|
||||||
export.outputFileType = .mp4
|
export.outputFileType = .mp4
|
||||||
export.shouldOptimizeForNetworkUse = true
|
|
||||||
|
|
||||||
await withCheckedContinuation { cont in
|
await withCheckedContinuation { cont in
|
||||||
export.exportAsynchronously {
|
export.exportAsynchronously {
|
||||||
@@ -226,6 +235,7 @@ actor CameraCaptureService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
|
private final class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
|
||||||
private var cont: CheckedContinuation<Data, Error>?
|
private var cont: CheckedContinuation<Data, Error>?
|
||||||
|
|||||||
Reference in New Issue
Block a user