Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

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 ↗

Transcript all transcripts

Code shown on screen · 3 snippets

AVAssetExportSession Intro swift · at 9:02 ↗
// 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 swift · at 13:24 ↗
// 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 swift · at 14:13 ↗
// 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