如何在python中合并mp3和mp4 /将mp4文件静音并在其上添加mp3文件

时间:2020-09-14 08:52:46

标签: python ffmpeg moviepy

如果可能的话,我想用moviepy库将mp3和mp4合并到python中。

但是我的mp4视频中有声音,所以我想先删除此声音。

1 个答案:

答案 0 :(得分:0)

我很难找到合适的东西,所以我认为很多人也可能遇到这种困难,所以这是对我有用的代码:

def combine_audio(vidname, audname, outname, fps=60): 
    import moviepy.editor as mpe
    my_clip = mpe.VideoFileClip(vidname)
    audio_background = mpe.AudioFileClip(audname)
    final_clip = my_clip.set_audio(audio_background)
    final_clip.write_videofile(outname,fps=fps)

combine_audio("test.mp4", "test.mp3", "test_over.mp4") # i create a new file
combine_audio("test.mp4", "test.mp3", "test.mp4") # i rewrite on the same file```