def test_speedx(): clip = VideoFileClip("media/big_buck_bunny_432_433.webm") clip1 = speedx(clip, factor=0.5) # 1/2 speed assert clip1.duration == 2 clip1.write_videofile(os.path.join(TMP_DIR, "speedx1.webm")) clip2 = speedx(clip, final_duration=2) # 1/2 speed assert clip2.duration == 2 clip2.write_videofile(os.path.join(TMP_DIR, "speedx2.webm")) clip2 = speedx(clip, final_duration=3) # 1/2 speed assert clip2.duration == 3 clip2.write_videofile(os.path.join(TMP_DIR, "speedx3.webm"))
def test_speedx(): clip = VideoFileClip("media/big_buck_bunny_432_433.webm") clip1=speedx(clip, factor=0.5) # 1/2 speed assert clip1.duration == 2 clip1.write_videofile(os.path.join(TMP_DIR, "speedx1.webm")) clip2=speedx(clip, final_duration=2) # 1/2 speed assert clip2.duration == 2 clip2.write_videofile(os.path.join(TMP_DIR, "speedx2.webm")) clip2=speedx(clip, final_duration=3) # 1/2 speed assert clip2.duration == 3 clip2.write_videofile(os.path.join(TMP_DIR, "speedx3.webm"))
def test_speedx(): clip = get_test_video() clip1 = speedx(clip, factor=0.5) # 1/2 speed assert clip1.duration == 2 clip1.write_videofile(os.path.join(TMP_DIR, "speedx1.webm")) clip2 = speedx(clip, final_duration=2) # 1/2 speed assert clip2.duration == 2 clip2.write_videofile(os.path.join(TMP_DIR, "speedx2.webm")) clip2 = speedx(clip, final_duration=3) # 1/2 speed assert clip2.duration == 3 clip2.write_videofile(os.path.join(TMP_DIR, "speedx3.webm")) close_all_clips(locals())
def test_subfx(): clip = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0, 5) transform = lambda c: speedx(c, 0.5) new_clip = clip.subfx(transform, 2, 4) location = os.path.join(TMP_DIR, "subfx.mp4") new_clip.write_videofile(location) assert os.path.isfile(location)
def run(self, outputVideoName): # 对加速点迭代加速 BgmName = 'BGM/model2-BGM.wav' for breakPoint in self.breakPoints: print(' *' * 12, '正在处理:', breakPoint, ' *' * 12) END = self.clip.end clipFirst = self.clip.subclip(self.START, breakPoint - self.M / self.speedRate) clipMiddle = speedx(self.clip.subclip( breakPoint - self.M / self.speedRate, breakPoint - self.M / self.speedRate + self.M), factor=self.speedRate) clipLast = self.clip.subclip( breakPoint - self.M / self.speedRate + self.M, END) self.clip = concatenate_videoclips( [clipFirst, clipMiddle, clipLast]) length = 0 sound = AudioFileClip(BgmName) if self.clip.end < sound.end: length = self.clip.end sound = sound.subclip(0, length) else: length = sound.end self.clip = self.clip.subclip(0, length) self.clip = self.clip.set_audio(sound) self.clip.fps = 30 self.writeClip(outputVideoName)
def test_subfx(): clip = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0, 1) transform = lambda c: speedx(c, 0.5) new_clip = clip.subfx(transform, 0.5, 0.8) location = os.path.join(TMP_DIR, "subfx.mp4") new_clip.write_videofile(location) assert os.path.isfile(location) close_all_clips(locals())
def change_speed(clip, factor): """ INPUT: Filename with path. String INPUT: Speed factor. Float OUTPUT: New video. MOV """ video_clip = VideoFileClip(clip) print("...") print("...") new_clip = speedx(video_clip, factor) new_clip.to_gif("new_video.mov") return new_clip
def with_fps(self, fps, change_duration=False): """Returns a copy of the clip with a new default fps for functions like write_videofile, iterframe, etc. If ``change_duration=True``, then the video speed will change to match the new fps (conserving all frames 1:1). For example, if the fps is halved in this mode, the duration will be doubled.""" if change_duration: from moviepy.video.fx.speedx import speedx newclip = speedx(self, fps / self.fps) else: newclip = self.copy() newclip.fps = fps return newclip
def test_speedx(): clip = BitmapClip([["A"], ["B"], ["C"], ["D"]], fps=1) clip1 = speedx(clip, 0.5) # 1/2x speed target1 = BitmapClip( [["A"], ["A"], ["B"], ["B"], ["C"], ["C"], ["D"], ["D"]], fps=1 ) assert clip1 == target1 clip2 = speedx(clip, final_duration=8) # 1/2x speed target2 = BitmapClip( [["A"], ["A"], ["B"], ["B"], ["C"], ["C"], ["D"], ["D"]], fps=1 ) assert clip2 == target2 clip3 = speedx(clip, final_duration=12) # 1/2x speed target3 = BitmapClip( [ ["A"], ["A"], ["A"], ["B"], ["B"], ["B"], ["C"], ["C"], ["C"], ["D"], ["D"], ["D"], ], fps=1, ) assert clip3 == target3 clip4 = speedx(clip, 2) # 2x speed target4 = BitmapClip([["A"], ["C"]], fps=1) assert clip4 == target4 clip5 = speedx(clip, final_duration=2) # 2x speed target5 = BitmapClip([["A"], ["C"]], fps=1) assert clip5 == target5 clip6 = speedx(clip, 4) # 4x speed target6 = BitmapClip([["A"]], fps=1) assert ( clip6 == target6 ), f"{clip6.duration} {target6.duration} {clip6.fps} {target6.fps}"
clip = VideoFileClip(clipName).subclip(1803, 1814) #clip_1 = VideoFileClip(clipName).subclip(1506, 1538) logo = ImageClip("tactification_logo.png").set_duration( clip.duration).resize(height=75).margin(right=40, top=10, opacity=0).set_pos( ("right", "top")) #logo_1=ImageClip("tactification_logo.png").set_duration(clip_1.duration).resize(height=75).margin(right=40, top=10, opacity=0).set_pos(("right","top")) clip = CompositeVideoClip([ clip, #clip_1, logo ]) #logo_1]) # Reduce the audio volume (volume x 0.8) #clip = clip.volumex(0.1) clip = clip.without_audio() clip = speedx.speedx(clip, factor=.65) # Say that you want it to appear 10s at the center of the screen _txt = TextClip("www.tactification.com", fontsize=70, color='white') _txt = _txt.set_position('center').set_duration(2) txt = CompositeVideoClip([_txt], size=clip.size) final = concatenate_videoclips([txt, clip]) # Overlay the text clip on the first video clip # Write the result to a file (many options available !) final.write_gif("FCBvsMANUTD.gif")
def cut_video(folder, filename, count): # Get clip duration file_path = base_path + '/' + folder + '/' + filename clip = VideoFileClip(file_path) duration = clip.duration # Cut video clip = clip.cutout(duration - 5, duration) temp_clip = clip temp_count = count # Save processed clip # Define directory if not os.path.exists(save_base_path + '/Cut'): os.mkdir(save_base_path + '/Cut') print("Made Cut directory!") if not os.path.exists(save_base_path + '/Cut/' + folder): os.mkdir(save_base_path + '/Cut/' + folder) print("Made " + folder + " directory!") save_path = save_base_path + '/Cut/' + folder # Write video temp_clip.write_videofile(save_path + '/' + folder + str(temp_count) + '.mp4') temp_count += 1 # Flip video temp_clip = temp_clip.fx(vfx.mirror_x) # Write flipped video temp_clip.write_videofile(save_path + '/' + folder + str(temp_count) + '.mp4') temp_count += 1 # Save optimized clip # Speedup clip fin = 1 if folder == 'push-up': fin = 1 elif folder == 'plank': fin = 1 elif folder == 'dumbell-curl': fin = 1 else: fin = 2 clip = speedx(clip=clip, final_duration=fin) # Define directory if not os.path.exists(save_base_path + '/Optimized'): os.mkdir(save_base_path + '/Optimized') print("Made Optimized directory!") if not os.path.exists(save_base_path + '/Optimized/' + folder): os.mkdir(save_base_path + '/Optimized/' + folder) print("Made " + folder + " directory!") save_path = save_base_path + '/Optimized/' + folder # Write video clip.write_videofile(save_path + '/' + folder + str(count) + '.mp4', fps=24) count += 1 # Flip video clip = clip.fx(vfx.mirror_x) # Write flipped video clip.write_videofile(save_path + '/' + folder + str(count) + '.mp4', fps=24) count += 1 return count
): #Checking to differentiate between labels like 'perfect square' (number **2) and 'square' (The shape) i = k + 1 k = 0 for name in glob.glob( './signLanguageDataset/*'): #Looping to find the relevant label relevantVideoFileName = (((name.split("/")[2]).split(".")[0]).split()) if (len(relevantVideoFileName) == 1 ): #Checking for videos which have 1 as length of word label. if (wordsSpoken[i] == relevantVideoFileName[0]): clip = VideoFileClip(name) clips.append(clip) del clip elif (len(relevantVideoFileName) == 2 ): #Checking for videos which have 2 as length of word label. if (wordsSpoken[i] == relevantVideoFileName[0] and wordsSpoken[i + 1] == relevantVideoFileName[1]): clip = VideoFileClip(name) clips.append(clip) k = i + 1 del clip #Concatenating the relevant videos final_clip = concatenate_videoclips(clips) #Increasing the play speed of the new translated video file. translatedClip = speedx(final_clip, factor=2) #Playing the required video file translatedClip.preview()
def speed(self): self.clip = speedx.speedx(self.clip, 2)