Open m-at-drigmo opened 2 years ago
Upon further digging, this appears to be HDR related issue.
The original is an HDR video, and it looks like the exported video did not preserve the HDR format. Per Apple's WWDC sessions for exporting HDR, AVAssetExportSession will preserve HDR without extra code if default compositor is used (and the chosen preset is set to one of the AVAssetExportPresetHEVC* options).
When using custom compositor though (which is the case for Cabbage), it must be updated to be HDR aware.
I have tried rewriting the code above to use AVFoundation APIs directly, the video is exported correctly when HEVC preset is used.
I add a demo to show how to support HDR video, you can pull the latest code.
HDR could be supported by subclass VideoCompositor
预览正常,导出存在偏色,我这边测试的视频是偏红😭
@m-at-drigmo we have fixed this issue in our local code. Steps that you should do.
extension AVAsset {
@inlinable
public var containsHDRVideo: Bool {
tracks.contains { $0.hasMediaCharacteristic(.containsHDRVideo) }
}
}
extension AVAssetTrackResource { public var containsHDRVideo: Bool { asset?.containsHDRVideo ?? false } }
extension Timeline { public var containsHDRVideo: Bool { return videoChannel.contains { channel in guard let item = channel as? TrackItem else { return false } guard let assetTrackResource = item.resource as? AVAssetTrackResource else { return false } return assetTrackResource.containsHDRVideo } } }
2. Set `HDRVideoCompositor` for `AVVideoComposition` when `timeline.containsHDRVideo == true`
3. Use `AVAssetExportPresetHEVC1920x1080` for `AVVideoComposition` when `timeline.containsHDRVideo == true`
I noticed that while exporting video using AVAssetExportSession, the result appears to be darker. Attached below are the original and exported screenshot of the videos.
Is this expected? Any suggestions/workarounds to preserve as much of the visual quality of the original videos in the exported?
Original:
Exported:
The code: