Skip to content

Exported video appears to be darker (colour shifting) #84

Description

@m-at-drigmo

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:
IMG_0876

Exported:
IMG_0877

The code:

        let timeline = Timeline()
        
        var videoChannels = [TrackItem]()
        var audioChannels = [TrackItem]()
        
        var currentTime = CMTime.zero
        for asset in self.assets {
            let resource = AVAssetTrackResource(asset: asset)

            let trackItem = TrackItem(resource: resource)
            trackItem.videoConfiguration.contentMode = .aspectFit
            trackItem.startTime = currentTime
            currentTime = CMTimeAdd(currentTime, asset.duration)
            
            videoChannels.append(trackItem)
            audioChannels.append(trackItem)
        }
        
        timeline.videoChannel = videoChannels
        timeline.audioChannel = audioChannels
        timeline.renderSize = CGSize(width: 1080, height: 1920)

        let compositionGenerator = CompositionGenerator(timeline: timeline)
        let exportSession = compositionGenerator.buildExportSession(presetName: AVAssetExportPresetHighestQuality)
        exportSession?.outputFileType = .mov

        let outputURL = URL(fileURLWithPath: NSTemporaryDirectory().appending("test.mov"))
        exportSession?.outputURL = outputURL
        exportSession?.exportAsynchronously {
            if let error = exportSession?.error {
                print("Failed to export: \(error)")
            } else {
                print("Movie file generated: \(outputURL)")
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions