from moviepy.editor import VideoFileClip, vfx, afx
def compress_video(video_path, output_path, target_duration, volume_scale=1.0):
clip = VideoFileClip(video_path)
if clip.duration > target_duration:
# Calculate speedup factor needed
speedup = clip.duration / target_duration
# Create a new clip that plays at `speedup` speed and adjust volume
new_clip = clip.fx(vfx.speedx, speedup).fx(afx.volumex, volume_scale)
# Write the result to a file
new_clip.write_videofile(output_path)
else:
print(f"Video is shorter than target duration of {target_duration} seconds")
path_to_your_video = r"D:\Desktop\1.mp4"
output_patch = r"D:\Desktop\2.mp4"
times = 55 # 压缩时间
volume_scale = 0.5 # 缩放因子,它将音量乘以该因子。例如,0.8将会降低20%的音量,而1.2将会增加20%的音量。
compress_video(path_to_your_video, output_patch, times, volume_scale)
利用python加速视屏
猜你喜欢
转载自blog.csdn.net/qq_45100200/article/details/134324847
今日推荐
周排行