Reputation: 31
from moviepy.editor import *
clip = VideoFileClip('add_audio.mp4')
audio = AudioFileClip('liver_1.wav')
videoclip = clip.set_audio(audio)
clip.write_videofile('does this work.mp4')
Please help, when I run this code the video exports but with no audio. I've tried many different formations of this with slightly different functions and still nothing works. I have yet to find someone with this issue.
Upvotes: 1
Views: 2041
Reputation: 90
You can add encoding as argument in videoclip.write_videofile
like this:
videoclip.write_videofile('sample.mp4', codec='libx264', audio_codec='pcm_s32le')
As it's explained in the documentation, you can change video and audio codec when you writing video:
codec
'libx264' (default codec for file extension .mp4) makes well-compressed videos (quality tunable using ‘bitrate’).
'mpeg4' (other codec for extension .mp4) can be an alternative to 'libx264', and produces higher quality videos by default.
audio_codec
Which audio codec should be used? Examples are ‘libmp3lame’ for ‘.mp3’, ‘libvorbis’ for ‘ogg’, ‘libfdk_aac’:’m4a’, ‘pcm_s16le’ for 16-bit wav and ‘pcm_s32le’ for 32-bit wav. Default is ‘libmp3lame’, unless the video extension is ‘ogv’ or ‘webm’, at which case the default is ‘libvorbis’.
Upvotes: 2
Reputation: 54897
You are doing clip.write_videofile
when you need to do videoclip.write_videofile
. You are saving the unmodified original.
Upvotes: 0