处理的内容

  1. 获取一个抖音美女舞蹈视频分别提取其视频、音频。
  2. 加载音频文件并自动找到速度
  3. 加载视频并自动找到循环良好的片段
  4. 提取此片段,放慢速度使其与音频速度匹配,并使其永远循环。
  5. 对称化这一部分,美女加倍
  6. 添加标题屏幕,写入文件。

Moviepy视频处理示例:抖音美女的舞蹈

代码及视频可访问:

https://blog.csdn.net/pythonhuan/article/details/115408699

from moviepy.editor import *from moviepy.video.tools.cuts import find_video_periodfrom moviepy.audio.tools.cuts import find_audio_periodfile_path = r"./素材/给你点赞 #戏曲漫步大赏.mp4"audio = (AudioFileClip(file_path).subclip(3,12) .audio_fadein(1) .audio_fadeout(1))audio_period = find_audio_period(audio)print ('Analyzed the audio, found a period of %.02f seconds'%audio_period)clip = (VideoFileClip(file_path, audio=False) .subclip(4,12))# .crop(x1=332, x2=910, y2=686))video_period = find_video_period(clip, tmin=6)print ('Analyzed the video, found a period of %.02f seconds'%video_period)edited_right = (clip.subclip(0,video_period) .speedx(final_duration=2*audio_period) .fx(vfx.loop, duration=audio.duration))edited_left = edited_right.fx(vfx.mirror_x)dancing_knights = (clips_array([[edited_left, edited_right]]) .fadein(1).fadeout(1).set_audio(audio))txt_title = (TextClip("戏曲漫步大赏", fontsize=70, font="STXINGKA.TTF", color="white") .margin(top=15, opacity=0) .set_position(("center","top")))#片头图片定格+标题title = (CompositeVideoClip([dancing_knights.to_ImageClip(), txt_title]) .fadein(.5) .set_duration(.5))# 结尾字幕txt_credits = """CREDITS戏曲漫步大赏Video editing © 老纳老纳"""credits = (TextClip(txt_credits, color='white', font="STXINGKA.TTF", fontsize=35, kerning=-2, interline=-1, bg_color='black', size=title.size) .set_duration(2.5) .fadein(.5) .fadeout(.5))# 视频合成final = concatenate_videoclips([title, dancing_knights, credits])final.write_videofile("xqmb2.mp4", fps=clip.fps, audio_bitrate="1000k", bitrate="4000k")