Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge audio with video perfectly

I've been trying to merge audio with video using AVMutableComposition and AVExportSession. Everything works perfectly except that the audio and video sources don't have the same duration.

So the exported movie is a bit laggy. Is there anyway to resize or redefine the rate of the video so that its duration becomes exactly equal to the audio's duration? For example, if the audio lasts 10 seconds and the video lasts 9 seconds, I'd like to play the video back at 9/10 speed, so they both end at the same time. b

like image 212
Jad Avatar asked Dec 06 '25 10:12

Jad


1 Answers

Solved

Use something like that:

[compositionVideoTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero,videoAsset.duration) toDuration:audioAsset.duration];
like image 190
Jad Avatar answered Dec 08 '25 00:12

Jad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!