import os
from moviepy.editor import *
from pydub import AudioSegment
# video = VideoFileClip("./test.mp4")
1 提取背景音乐
video = VideoFileClip("./test.mp4") # 读取数据
audio = video.audio # 获取视频的音频
audio.write_audiofile('./test.wav') # 将音频以.wav格式保存
2 去掉视频的背景音乐,只保留视频文件
video = VideoFileClip("./small.mp4") # 读取数据
audio = video.without_audio() # 去掉视频的音频
audio.write_videofile('./test1111.mp4') # 保存视频
3 视频剪辑
video = VideoFileClip("./test.mp4") # 读取数据
video = video.subclip(0,20) # 设置截取数据的范围
video.to_videofile("./small.mp4") # 保存数据
4 视频拼接
# # 定义一个数组
# L = []
#
# # 合并少量视频
# video1 = VideoFileClip('./test.mp4')
# L.append(video1)
# video2 = VideoFileClip('./small.mp4')
# L.append(video2)
5 视频倍速播放
# 对视频进行加速
# video= './small.mp4'
# resultFile= './result.mp4'
# video = VideoFileClip(video)
# duration = video.duration
# video = video.fl_time(lambda t: 1.1*t,
# apply_to=['video','audio']
# ).set_end(duration/1.1)
# video.write_videofile(resultFile)
# from moviepy.editor import *
#
# clip = VideoFileClip(r"./small.mp4")
# clipSpeed = clip.speedx(1.1)
# clipSpeed.write_videofile(r"./result.mp4")