3

I'm trying to set audio clip on image clip in moviepy. I read this page, then I wrote code like this.

from moviepy.editor import *
clip = ImageClip('img/output_1.png')
audio_clip = AudioFileClip('audio/output_1.mp3')
clip = clip.set_duration(audio_clip.duration)
clip = clip.set_audio(audio_clip)

Audio and duration are returns value.

>>> clip.audio
<moviepy.audio.io.AudioFileClip.AudioFileClip object at 0x1241dbd30>
>>> clip.duration
4.18

However when I write as file.

clip.write_videofile('mov/sample.mp4',fps=4)

I can't hear the sound. Are there any mistake on my code? I don't know how should I change my code... If you have any idea please help me!

My environment is

MacOS 11.3.1
python 3.9.5
moviepy 1.0.3

I had run same code on google colab, I got same problem. The video has 4.18 seconds, however it's no sound...

I downloaded audio file from ondoku3 and youtube as mp3

Nori
  • 2,340
  • 1
  • 18
  • 41
  • do you have this problem when you save only audio? How long is video (duration) when you display in any video player? maybe it display it with duration 0 (zero) and then it can't play audio. – furas May 13 '21 at 04:03
  • When I ran your code, the resulting video wouldn't even play - very strange. – knosmos May 13 '21 at 04:08
  • code works for me on Linux Mint 20, Python 3.8.5, MoviePy 1.0.3. I would check if `mp3` is correct and if video player is not mute – furas May 13 '21 at 04:09
  • @knosmos what system, python, moviepy's version did you use? maybe problem is only on some systems? It works for me on Linux. – furas May 13 '21 at 04:11
  • Windows 10, Python 3.7.4, moviepy 1.0.3 - I've used moviepy in the past without incident so it probably has something to do with the test files I used – knosmos May 13 '21 at 04:15
  • @furas Hello furas. The video has duration 4 seconds. I got same problem on google colab. – Nori May 13 '21 at 08:38

1 Answers1

2

I found QuickTime can't play sound. When I play VLC, I can hear the sound.

And also when I merge audio and video with ffmpeg. I got same problem. So I think this problem from ffmpge convert problem or QuickTime problem.

Nori
  • 2,340
  • 1
  • 18
  • 41