這個要比前一個厚實點。django
更改視頻亮度,增長字幕,去除音軌,淡入特效,轉換,截取時間,控制位置,組合圖框,合成多段,ide
嗯,不少都有了。spa
from django.test import TestCase # Create your tests here. # coding=utf-8 from moviepy.editor import * from moviepy.video.tools.subtitles import SubtitlesClip from moviepy.video.fx import volumex, resize, mirrorx, lum_contrast from moviepy.video.tools.segmenting import findObjects # 導入字幕 generator = lambda txt: TextClip(txt, font='SimHei', fontsize=24, color='black') sub = SubtitlesClip("welcome.srt", generator) # 片頭 start_clip = VideoFileClip("start_clip.mp4").subclip(0, 9.0).resize((500, 1000)).fx(lum_contrast, (lum=0, contrast=0, contrast_thr=127)).crossfadein(0.5).crossfadeout(0.5) # 合成字幕 start_clip = CompositeVideoClip([start_clip, sub]) # 片尾 end_clip = ImageClip("wzj_cover.png").subclip(0, 9.0).resize((500, 1000)).fx(resize, (1000, 500)) # 內容 main_clip = VideoFileClip("main_clip.mp4", audio=False).without_audio().subclip(0, 9.0).on_color(color=(255, 255, 255)).resize((700, 500)).crossfadein(0.5).crossfadeout(0.5) left_clip1 = VideoFileClip("left_clip.mp4", audio=False).without_audio().subclip(0, 9.0).rotate(90).on_color(color=(255, 255, 255)) left_clip2 = VideoFileClip("left_clip.mp4", audio=False).without_audio().subclip(0, 9.0).rotate(90).on_color(color=(255, 255, 255)) left_clip3 = VideoFileClip("left_clip.mp4", audio=False).without_audio().subclip(0, 9.0).rotate(90).on_color(color=(255, 255, 255)) # 一種實現,經過巧妙堆疊 left_clip = clips_array([[left_clip, main_clip]]) mid_clip = clips_array([[left_clip, main_clip]]) """ # 另外一種實現,經過畫好的線框來安置視頻 # Load the image specifying the regions. im = ImageClip("motif.png") # Loacate the regions, return a list of ImageClips regions = findObjects(im) clips = [left_clip1, left_clip2, left_clip3, main_clip] comp_clips = [c.resize(r.size) .set_mask(r.mask) .set_position(r.screenpos) for c,r in zip(clips,regions)] mid_clip = CompositeVideoClip(comp_clips, im.size) """ mid_clip = mid_clip.resize(width=1000, height=500).rotate(90) # 剪輯合成 final_clip = concatenate_videoclips([start_clip, mid_clip, end_clip]) # 輸出視頻 final_clip.write_videofile("my_stack.mp4")