Write a Python program to take a .MOV file (60-second long .MOV file) and split it into…
- User
Write a Python program to take a .MOV file (60-second long .MOV file) and split it into twenty 3-second long .MOV files. Then, the code should put these twenty 3-second long .MOV files in the same folder that the 60-second .MOV file is currently in.
- Assistant
To split a .MOV file into multiple shorter files, you can use the
moviepylibrary, which can be installed with the following command:pip install moviepyOnce the
moviepylibrary is installed, you can use the following Python code to split a 60-second long .MOV file into twenty 3-second long .MOV files:import os from moviepy.editor import VideoFileClip def split_video(file_path, duration=3): # Load the input clip clip = VideoFileClip(file_path) # Calculate the number of output clips num_clips = int(clip.duration // duration) # Get the base file name without the extension base_file_name = os.path.splitext(file_path)[0] # Create the output directory output_directory = os.path.join(os.path.dirname(file_path), 'output') os.makedirs(output_directory, exist_ok=True) # Split the video into shorter clips and save them to the output directory for i in range(num_clips): start = i * duration end = (i + 1) * duration sub_clip = clip.subclip(start, end) sub_clip.write_videofile(os.path.join(output_directory, f'{base_file_name}_{i}.MOV')) if __name__ == '__main__': file_path = '/path/to/your/video.MOV' # Replace this with the path to your 60-second .MOV file split_video(file_path)