first 先安装需要的版本
pip install moviepy==1.0.0
然后代码如下
import os
from moviepy.editor import VideoFileClip, concatenate_videoclips
def batch_volumex(path):
# 函数功能:在指定路径下,将该文件夹的视频声音调为x倍
origin_path = os.getcwd()
os.chdir(path)
for fname in os.listdir():
genNewFile(fname)
os.chdir(origin_path)
def genNewFile(fname):
clip = VideoFileClip(fname)
#放大三倍音量
newclip = clip.volumex(5)
newclip.write_videofile("new_" + fname)
def eachFile(filepath):
global datas
fileNames = os.listdir(filepath) # 获取当前路径下的文件名,返回List
for file in fileNames:
newDir = filepath + '/' + file # 将文件命加入到当前文件路径后面
# print(newDir)
# if os.path.isdir(newDir): # 如果是文件夹
if os.path.isfile(newDir): # 如果是文件
if os.path.splitext(newDir)[1] == ".mp4" and not file.__contains__("new_"): # 判断是否是txt
print(newDir)
os.chdir(filepath)
genNewFile(file)
os.chdir(filepath)
else:
eachFile(newDir) #如果不是文件,递归这个文件夹的路径
datas = []
def main():
# 文件夹目录
path = r'C:\Users\liuan\Desktop\android开发从入门到项目'
eachFile(path)
print(datas)
pass
if __name__ == '__main__':
main()
最后贴个小广告
这个是我本人录制的教学视频。正在准备提升音量