这是python脚本。
from moviepy.editor import *
videoclip = VideoFileClip("1_0_1522314608.m4v")
audioclip = AudioFileClip("jam_1_Mix.mp3")
new_audioclip = CompositeAudioClip([videoclip.audio, audioclip])
videoclip.audio = new_audioclip
videoclip.write_videofile("new_filename.mp4")
然后返回
[MoviePy]>>>>构建视频new_filename.mp4 [MoviePy]编写音频 在new_filenameTEMP_MPY_wvf_snd.mp3中 100%|████████████████████████████████████████| 795/795 [00:01< 00:00, 466.23it / s] [MoviePy]完成。 [MoviePy]写视频new_filename.mp4 100%|███████████████████████████████████████ | 1072/1072 [01:26< 00:00, 10.31it / s] [MoviePy]完成。 [MoviePy]>>>>视频就绪:new_filename.mp4
1_0_1522314608.m4v和jam_1_Mix.mp3他们都有声音。
但是新文件new_filename.mp4没有声音。
我做错了吗?请帮忙。谢谢。
答案 0 :(得分:0)
I had similar issues. I found that sometimes the audio is in fact present, but will not be played by all players. (Quicktime does not work, but VLC does). I finally use something like :
video_clip.set_audio(composite_audio).write_videofile(
composite_file_path,
fps=None,
codec="libx264",
audio_codec="aac",
bitrate=None,
audio=True,
audio_fps=44100,
preset='medium',
audio_nbytes=4,
audio_bitrate=None,
audio_bufsize=2000,
# temp_audiofile="/tmp/temp.m4a",
# remove_temp=False,
# write_logfile=True,
rewrite_audio=True,
verbose=True,
threads=None,
ffmpeg_params=None,
progress_bar=True)
A few remarks :
set_audio()
returns a new clip and leave the object on which it is called unchangedSetting the audio clip duration to match the video helps :
composite_audio = composite_audio.subclip(0, video_clip.duration)
composite_audio.set_duration(video_clip.duration)