使用python进行视频编辑:为带声音的视频添加背景音乐 [英] Video editing with python : adding a background music to a video with sound

查看:98
本文介绍了使用python进行视频编辑:为带声音的视频添加背景音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 python 中为视频文件 (.mp4) 添加背景音乐.

I would like to add a background music to a video file (.mp4) in python.

我查看了网络并使用用于 python 的 moviepy 做了一些技巧,但我没有找到一种将背景音乐添加到已经包含音乐的视频文件的方法.任何想法如何做到这一点?

I have looked the web and did some tricks with moviepy for python, but I did not found a single way to add background music to a video file that already contains music. Any ideas how to do that ?

按照 Anil_M 的评论进行谢谢,不,我没有看过这个特定的线程,虽然我知道 ffmpeg 但它看起来又像是一种将没有音频的视频与音轨合并的方法.

Edit following Anil_M's comment : Thanks, no I didn't look at this particular thread, althought I knew about ffmpeg but it looks like again, it is a way to merge a video without audio with an audio track.

所以现在我要尝试从视频中提取音频,与另一个音频文件合并,然后与视频合并.也许这不是最好的方法,但至少它是可能的,因为有关合并 2 个音轨的问题得到了解答.

So now I am going to try to extract audio from the video, merge with another audio file, then merge back with video. Maybe that's not the best way, but at least it is possile as questions about merging 2 audio tracks are answered.

推荐答案

您可以使用 moviepy 的 CompositeAudioClip:

You can do this with moviepy's CompositeAudioClip:

import moviepy.editor as mpe
my_clip = mpe.VideoFileClip('some_clip.mp4')
audio_background = mpe.AudioFileClip('some_background.mp3')
final_audio = mpe.CompositeAudioClip([my_clip.audio, audio_background])
final_clip = my_clip.set_audio(final_audio)

这篇关于使用python进行视频编辑:为带声音的视频添加背景音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆