最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Why it's not adding a sound (the path of files are correct, and the audio of file is working but it doesnt outp

programmeradmin3浏览0评论
import moviepy.editor as mpe
my_clip = mpe.VideoFileClip('output.mp4')
audio_background = mpe.AudioFileClip('ayah.mp3')
final_clip = my_clip.set_audio(audio_background)
final_clip.write_videofile('final_output.mp4', codec='libx264', audio_codec='aac')

It outputs the the video without a sound i tried to change the ayah.mp3 to wav but it doesn't work

import moviepy.editor as mpe
my_clip = mpe.VideoFileClip('output.mp4')
audio_background = mpe.AudioFileClip('ayah.mp3')
final_clip = my_clip.set_audio(audio_background)
final_clip.write_videofile('final_output.mp4', codec='libx264', audio_codec='aac')

It outputs the the video without a sound i tried to change the ayah.mp3 to wav but it doesn't work

Share Improve this question asked Feb 15 at 6:50 YahiaYahia 415 bronze badges 1
  • What happens if you use the default audio_codec 'libmp3lame' instead of 'aac'? – dev_light Commented Feb 15 at 8:32
Add a comment  | 

1 Answer 1

Reset to default 0

A common solution people have had online to fix similar issues is explicitly matching the audio clip's length to the videos. Sometimes, they're not exactly the same length and it messes up movie.py.

import moviepy.editor as mpe
my_clip = mpe.VideoFileClip('output.mp4')
audio_background = mpe.AudioFileClip('ayah.mp3').set_duration(my_clip.duration)
final_clip = my_clip.set_audio(audio_background)
final_clip.write_videofile('final_output.mp4', codec='libx264', audio_codec='aac', audio_bitrate='192k')

If that doesn't fix it, you should probably try a different audio codec.

And make sure that the sound file isn't corrupt or silent itself, sometimes the weirdest problems have the simplest solutions.

Hope this helps :)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论