def main(): while True: start_time = datetime.now() folder_location = input("Enter Folder Location: ") output_location = input("Enter Output Location: ") trim_start = input("Enter Seconds to Trim From Start: ") trim_end = input("Enter Seconds to Trim From End: ") folder = os.listdir(folder_location) print(f'{start_time}: Processing {len(folder)} files...') for file in folder: if file.endswith('.mp4'): file_name = f"{folder_location}\\{file}" video_file = VideoFileClip(file_name).cutout( 0, float(trim_start)) new_file_duration = float( video_file.duration) - float(trim_end) video_file.duration = new_file_duration name_array = file.split('-') new_file_name = f"{name_array[0].strip()} - {name_array[1].strip()}.mp4" video_file.write_videofile( f"{output_location}\\{new_file_name}") video_file.close() end_time = datetime.now() print(f'Ended in {end_time - start_time} seconds') continue_input = input("Should I update another folder? (y or n): ") if continue_input.lower() == "n": return False
def draw_text_in_box_on_video(video: med.VideoFileClip, video_text: str, length: float, width: int, height: int, box_height: int, move: bool, top: bool, on_box: bool = True, center: bool = False, vpos: Optional[float] = None, interval: Optional[Tuple[float, float]] = None, fontsize=30) -> med.CompositeVideoClip: """Draws a semi-transparent box either at the top or bottom and writes text in it, optionally scrolling by""" clips = [] y_location = 0 if top else height - box_height y_location = height // 2 if center else y_location if vpos is not None: y_location = int(height * vpos) video_w, _ = video.size if on_box: color_clip = med.ColorClip(size=(video_w, box_height), color=(0, 0, 0)) color_clip = color_clip.set_fps(Moviepy.DEFAULT_FPS) # pylint: disable=assignment-from-no-return color_clip = color_clip.set_opacity(0.5) # pylint: disable=assignment-from-no-return color_clip = color_clip.set_position(pos=(0, y_location)) clips.append(color_clip) stroke_color = 'black' if not on_box else None txt = med.TextClip(video_text, font='Bauhaus-93', color='white', stroke_color=stroke_color, fontsize=fontsize) txt_y_location = (box_height - txt.h) // 2 + y_location if center: txt_left_margin = (width - txt.w) // 2 else: txt_left_margin = 20 # pylint: disable=assignment-from-no-return if move: txt_mov = txt.set_position(lambda t: (max(txt_left_margin, round(video_w - video_w * t / float(length))), txt_y_location)) else: txt_mov = txt.set_position((txt_left_margin, txt_y_location)) # pylint: enable=assignment-from-no-return txt_mov = txt_mov.set_fps(Moviepy.DEFAULT_FPS) # pylint: disable=assignment-from-no-return if interval: # Fade text in and out fade_duration = 1 # second txt_mov = txt_mov.set_duration(interval[1] - interval[0] + fade_duration * 2) txt_mov = txt_mov.set_start(max(0, interval[0] - fade_duration)) txt_mov = txt_mov.fx(vfx.fadein, fade_duration).\ fx(vfx.fadeout, fade_duration) clips.append(txt_mov) duration = video.duration # Add the input video as the first in the list clips = [video] + clips # Build a new composition out of the original clip and the text overlay. # video = med.CompositeVideoClip(clips, use_bgclip=interval is not None) video = med.CompositeVideoClip(clips) video.duration = duration return video