2020 Developer ToolsAudio & Video
WWDC20 · 23 min · Developer Tools / Audio & Video
Export HDR media in your app with AVFoundation
Discover how to author and export high dynamic range (HDR) content in your app using AVFoundation. Learn about high dynamic range and how you can take advantage of it in your app. We’ll show you how to implement feature sets that allow people to export HDR content, go over supported HDR formats, review current restrictions, and explore the Apple platforms that support HDR export.
Watch at developer.apple.com ↗Code shown on screen · 3 snippets
AVAssetExportSession Intro
// AVAssetExportSession code snippet
guard let exportSession = AVAssetExportSession(asset: sourceAsset,
presetName: AVAssetExportPresetHEVCHighestQuality) else {
// Handle error
}
exportSession.outputURL = outputURL
exportSession.outputFileType = AVFileTypeQuickTimeMovie
exportSession.exportAsynchronouslyWithCompletionHandler {
// Handle completion
} AVAssetWriter with sourceFormatHint
// AVAssetWriter with sourceFormatHint
let assetWriter = try AVAssetWriter(url: outputURL, fileType: AVFileTypeQuickTimeMovie)
let outputSettings: [String: AnyObject] = [
AVVideoCodecKey: AVVideoCodecTypeHEVC
]
let assetWriterInput = AVAssetWriterInput(mediaType: AVMediaTypeVideo,
outputSettings: outputSettings
sourceFormatHint: videoFormatDescription)
assetWriter.add(assetWriterInput)
guard assetWriter.startWriting() else {
throw assetWriter.error!
} AVAssetWriter with AVOutputSettingsAssistant
// AVAssetWriter with AVOutputSettingsAssistant
let assetWriter = try AVAssetWriter(url: outputURL, fileType: AVFileTypeQuickTimeMovie)
let settingsAssistant = AVOutputSettingsAssistant(
preset: AVOutputSettingsPreset.hevc1920x1080)
settingsAssistant.sourceVideoFormat = videoFormatDescription
let newVideoSettings = settingsAssistant.videoSettings
// Modify a few fields in newVideoSettings here
let assetWriterInput = AVAssetWriterInput(mediaType: AVMediaTypeVideo,
outputSettings: newVideoSettings)
assetWriter.add(assetWriterInput)
guard assetWriter.startWriting() else {
throw assetWriter.error!
} Resources
Related sessions
-
34 min