Image/Text overlay in video swift

前端 未结 5 2036
野趣味
野趣味 2021-01-30 15:09

I am work with image overlay for watermark effect in video using swift.I am using AVFoundation for this but somehow I am not succeed.

Following is my code

5条回答
  •  礼貌的吻别
    2021-01-30 15:43

    The code provided by @El Captain would work. It's only missing:

        assetExport.videoComposition = layercomposition
    

    You can add this right after the instantiation of the AVAssetExportSession

    NOTE: The code originally provided would only export the video track but not the audio track. If you need the audio track you could add something like this after you configure the compositionvideoTrack:

    let compositionAudioTrack:AVMutableCompositionTrack = composition.addMutableTrackWithMediaType(AVMediaTypeAudio, preferredTrackID: CMPersistentTrackID())
        for audioTrack in audioTracks {
            try! compositionAudioTrack.insertTimeRange(audioTrack.timeRange, ofTrack: audioTrack, atTime: kCMTimeZero)
        }
    

提交回复
热议问题