python ffmpeg 合并后的视频加音频

923 阅读1分钟

最近有业务需要合并视频和音频,一顿搜索猛如虎,发现了moviepy,发现这个还真好用,但是也有弊端,就是合并了好几段视频后,再加音频,发现加不上,所以查看ffmpeg,发现了如下的方法

    def video_add_mp3(times, file_name, mp3_file):  # 给视频添加声音
        outfile_name = file_name.split('.')[0] + '-end.mp4'
        subprocess.call("ffmpeg -i %s -i %s -t %s -y %s" % (mp3_file, file_name, times, outfile_name))
        return outfile_name
#首先times是视频长度,file_name是视频地址,mp3_file是音频地址
ok  那么运行吧