VideoFlint / Cabbage

A video composition framework build on top of AVFoundation. It's simple to use and easy to extend.
MIT License
1.55k stars 227 forks source link

black screen when the audio overlay goes to finish #76

Open ahmedsafadii opened 3 years ago

ahmedsafadii commented 3 years ago
            let voiceResource = AVAssetTrackResource(asset: asset)

            if videoTimelineView.duration <= ((voiceOvers[currentVoiceOver]?.startTime ?? 0.0) + asset.duration.seconds) {
                voiceResource.selectedTimeRange = CMTimeRange(start: .zero, duration: CMTime(seconds: asset.duration.seconds, preferredTimeScale: 10))
            }
            item.identifier = voiceOvers[currentVoiceOver]?.name ?? ""
            item.startTime = CMTime(seconds: voiceOvers[currentVoiceOver]?.startTime ?? 0.0, preferredTimescale: 10)
vitoziv commented 3 years ago

your issue maybe because the audio time is bigger than the video time, you can try to cut the audio time or extend the video time

ahmedsafadii commented 3 years ago

@vitoziv thank you for answering, as you can see here I already do the selected time range

            if videoTimelineView.duration <= ((voiceOvers[currentVoiceOver]?.startTime ?? 0.0) + asset.duration.seconds) {
                voiceResource.selectedTimeRange = CMTimeRange(start: .zero, duration: CMTime(seconds: asset.duration.seconds, preferredTimeScale: 10))
            }

in case the audio is bigger than video, but I would say that's it's not because sometimes it's works and sometime I get black,

you need to know that i had more than one audio recorded and all have startime, but the only voice which reach the end can make the black issue