视频剪辑-python moviepy

from moviepy.editor import *

提取声音

from moviepy.editor import *
mp4_file_name = r"源.mp4"
mp3_fime_name = r"提取出来的声音.mp3"

# 应用1、提取视频文件中的音频

# 如果提示句柄无效,请关闭重新打开
with VideoFileClip(mp4_file_name) as video:
    video.audio.write_audiofile(mp3_fime_name)

删除声音

from moviepy.editor import *
mp4_file_name = r"源.mp4"
mp3_fime_name = r"提取出来的声音.mp3"
mp4_fime_name_silence = r"源_silence.mp4"
# 应用2、删除视频文件中的音频

# 如果提示句柄无效,请关闭重新打开
with VideoFileClip(mp4_file_name) as video:
    video = video.without_audio()
    video.write_videofile(mp4_fime_name_silence)

剪切和拼接

from moviepy.editor import *
flv_1 = r"剪切.flv"
flv_2 = r"拼接_2.flv"
flv_3 = r"剪切.flv"

# 应用3、视频剪辑 拼接 添加字幕

# 1 剪切
video1 = VideoFileClip(flv_1).subclip(t_start=1, t_end=(1,51)) # 从第2秒 剪切到3分51
video1.write_videofile(r"剪切_1.mp4")
print("剪切1完成")
video2 = VideoFileClip(flv_2).cutout(0,5)  # 减掉0-5秒的内容
video2.write_videofile(r"剪切_2.mp4")
print("剪切2完成")
video3 = concatenate_videoclips([video1, video2])  # 合并两个视频

# text_clip = TextClip(    "花开彼岸天,鱼跃此时海",
#                         fontsize=50,
#                         font=f"C:\Windows\Fonts\STXINGKA.TTF",
#                         color="red",
#                         bg_color = "transparent",).set_position(("right","top")).set_duration(1200).set_start(0)

# # video = CompositeVideoClip([video3, TextClip])  # 给视频添加字幕

video3.write_videofile(r"剪切合并加字幕.mp4")

你可能感兴趣的:(Python)