[英]Moviepy - video will not export with the audio I add to it
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.
我还没有找到有这个问题的人。
You are doing clip.write_videofile
when you need to do videoclip.write_videofile
.当您需要执行
videoclip.write_videofile
时,您正在执行clip.write_videofile
。 You are saving the unmodified original.您正在保存未修改的原件。
You can add encoding as argument in videoclip.write_videofile
like this:您可以像这样在
videoclip.write_videofile
中添加编码作为参数:
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').
“libx264”(文件扩展名.mp4 的默认编解码器)制作压缩良好的视频(使用“比特率”可调整质量)。
'mpeg4' (other codec for extension.mp4) can be an alternative to 'libx264', and produces higher quality videos by default.
“mpeg4”(extension.mp4 的其他编解码器)可以替代“libx264”,并默认生成更高质量的视频。
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 .
例如 'libmp3lame' 代表 '.mp3','libvorbis' 代表 'ogg','libfdk_aac':'m4a', 'pcm_s16le' 代表 16 位 wav 和 'pcm_s32le' 代表 32 位 wav 。 Default is 'libmp3lame', unless the video extension is 'ogv' or 'webm', at which case the default is 'libvorbis'.
默认为“libmp3lame”,除非视频扩展名是“ogv”或“webm”,在这种情况下默认为“libvorbis”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.