I used moviepy to add audio to a given video. I started by checking the duration of the video. If it's shorter than the audio, I slow the video down using:
video_clip = video_clip.fx( vfx.speedx, (video_clip.duration/audio_clip.duration))
Then, I added the audio using:
video_clip = video_clip.set_audio(audio_clip)
I saved the result with
video_clip.write_videofile(save_path, codec="libx264", audio_codec="aac", fps=24, audio_bitrate="64K", threads=32, ffmpeg_params=['-safe', '0'])
Everything seems to be OK, except for the last half second of the resulting video, where the audio is replayed right before the end of the video. I tried
new_audio_clip = afx.audio_loop(audio_clip, duration=video_clip.duration)
And added the new audio instead. But nothing changed.