use*_*111 5 python audio video moviepy
这是Python脚本。
\n\nfrom moviepy.editor import *\nvideoclip = VideoFileClip("1_0_1522314608.m4v")\naudioclip = AudioFileClip("jam_1_Mix.mp3")\n\nnew_audioclip = CompositeAudioClip([videoclip.audio, audioclip])\nvideoclip.audio = new_audioclip\nvideoclip.write_videofile("new_filename.mp4")\n
Run Code Online (Sandbox Code Playgroud)\n\n然后返回
\n\n\n\n\n[MoviePy] >>>> 构建视频 new_filename.mp4 [MoviePy] 在 new_filenameTEMP_MPY_wvf_snd.mp3\n 中写入音频\n 100%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96 \x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2 \x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96 \x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88 \xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 795/795 [00:01<00:00,\n 466.23it/s] [MoviePy] 完成。[MoviePy] 写入视频 new_filename.mp4 100%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\ x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\ x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\ xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\ x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 1072/1072 [01:26<00:00,\n 10.31it/s] [MoviePy] 完成。[MoviePy] >>>> 视频准备好:new_filename.mp4
\n
1_0_1522314608.m4v 和 jam_1_Mix.mp3 它们都有声音。
\n\n但新文件new_filename.mp4没有声音。
\n\n我做错什么了吗?请帮忙。谢谢。
\n我有类似的问题。我发现有时音频确实存在,但并非所有玩家都能播放。(Quicktime 不起作用,但 VLC 可以)。我最终使用类似的东西:
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)
Run Code Online (Sandbox Code Playgroud)
几点说明:
set_audio()
返回一个新剪辑并保持调用它的对象不变设置音频剪辑持续时间以匹配视频有助于:
composite_audio = composite_audio.subclip(0, video_clip.duration)
composite_audio.set_duration(video_clip.duration)
Run Code Online (Sandbox Code Playgroud)