0

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.

Zac Jokface
  • 153
  • 2
  • 10
  • Shouldn't it be something like `video_clip = video_clip.set_audio(audio_clip.set_duration(video_clip.duration))`? – Rotem Jan 15 '23 at 21:03
  • @Rotem Yes, I have that line to ensure both audio and video have the same duration. The issue is still there though – Zac Jokface Jan 17 '23 at 18:20
  • Since you didn't post a reproducible code sample, we can't verify the issue, and try to find a solution. Even if you share your input audio and video, and a working code sample, the chances for someone to answer are low because MoviePy is not very popular in SO site. – Rotem Jan 17 '23 at 18:41

1 Answers1

0

Only setting buffersize=400_000 fixed it for me. Default is 200_000.

I tried many permutations, i.e. setting nbytes, fps, codec, nothing worked. My audio was 24_000Hz, 32 bit float, Mono. Coming from Google's TTS

lutian
  • 21
  • 1
  • 4