moviepy的常见用法
作者:互联网
看了,还是自己弄这些方便。
#字幕 >>> from moviepy.video.tools.subtitles import SubtitlesClip >>> from moviepy.video.io.VideoFileClip import VideoFileClip >>> generator = lambda txt: TextClip(txt, font='Georgia-Regular', fontsize=24, color='white') >>> sub = SubtitlesClip("subtitles.srt", generator) >>> myvideo = VideoFileClip("myvideo.avi") >>> final = CompositeVideoClip([clip, subtitles]) >>> final.to_videofile("final.mp4", fps=myvideo.fps) #前后播放 from moviepy.editor import VideoFileClip, concatenate_videoclips clip1 = VideoFileClip("myvideo.mp4") clip2 = VideoFileClip("myvideo2.mp4").subclip(50,60) clip3 = VideoFileClip("myvideo3.mp4") final_clip = concatenate_videoclips([clip1,clip2,clip3]) final_clip.write_videofile("my_concatenation.mp4") #同屏播放 from moviepy.editor import VideoFileClip, clips_array, vfx clip1 = VideoFileClip("myvideo.mp4").margin(10) # add 10px contour clip2 = clip1.fx( vfx.mirror_x) clip3 = clip1.fx( vfx.mirror_y) clip4 = clip1.resize(0.60) # downsize 60% final_clip = clips_array([[clip1, clip2], [clip3, clip4]]) final_clip.resize(width=480).write_videofile("my_stack.mp4") #淡入淡出 video = CompositeVideoClip([clip1, # starts at t=0 clip2.set_start(5).crossfadein(1), clip3.set_start(9).crossfadein(1.5)]) # 水印位置,大小屏 video = CompositeVideoClip([clip1, clip2.set_pos((45,150)), clip3.set_pos((90,100))]) clip2.set_pos((45,150)) # x=45, y=150 , in pixels clip2.set_pos("center") # automatically centered # clip2 is horizontally centered, and at the top of the picture clip2.set_pos(("center","top")) # clip2 is vertically centered, at the left of the picture clip2.set_pos(("left","center")) # clip2 is at 40% of the width, 70% of the height of the screen: clip2.set_pos((0.4,0.7), relative=True) # clip2's position is horizontally centered, and moving down ! clip2.set_pos(lambda t: ('center', 50+t) ) # 视频导入处理 from moviepy.editor import * clip = (VideoFileClip("myvideo.avi") .fx( vfx.resize, width=460) # resize (keep aspect ratio) .fx( vfx.speedx, 2) # double the speed .fx( vfx.colorx, 0.5)) # darken the picture #文字嵌入 # Generate a text clip. You can customize the font, color, etc. txt_clip = TextClip("My Holidays 2013",fontsize=70,color='white') # Say that you want it to appear 10s at the center of the screen txt_clip = txt_clip.set_pos('center').set_duration(10) # Overlay the text clip on the first video clip video = CompositeVideoClip([clip, txt_clip]) #预览 my_clip.show() # shows the first frame of the clip my_clip.show(10.5) # shows the frame of the clip at t=10.5s my_clip.show(10.5, interactive = True) my_clip.preview() # preview with default fps=15 my_clip.preview(fps=25) my_clip.preview(fps=15, audio=False) # don't generate/play the audio. my_audio_clip.preview(fps=22000) ipython_display(my_video_clip) # embeds a video ipython_display(my_imageclip) # embeds an image ipython_display(my_audio_clip) # embeds a sound ipython_display("my_picture.jpeg") # embeds an image ipython_display("my_video.mp4") # embeds a video ipython_display("my_sound.mp3") # embeds a sound #多加音轨 videoclip2 = videoclip.set_audio(my_audioclip) #登陆视频clip剪辑方法总结 # VIDEO CLIPS clip = VideoClip(make_frame, duration=4) # for custom animations (see below) clip = VideoFileClip("my_video_file.mp4") # or .avi, .webm, .gif ... clip = ImageSequenceClip(['image_file1.jpeg', ...], fps=24) clip = ImageClip("my_picture.png") # or .jpeg, .tiff, ... clip = TextClip("Hello !", font="Amiri-Bold", fontsize=70, color="black") clip = ColorClip(size=(460,380), color=[R,G,B]) #有用的url https://zulko.github.io/moviepy/getting_started/videoclips.html
标签:moviepy,set,clip,常见,VideoFileClip,用法,clip2,video,my 来源: https://www.cnblogs.com/aguncn/p/11018075.html