Wednesday, 14 February 2024

converter

 

from moviepy.editor import VideoFileClip def convert_to_short_clips(video_path, clip_duration, output_directory): """ Converts a podcast video into shorter clips of specified duration. Args: - video_path: The path to the input video file. - clip_duration: The duration (in seconds) of each output clip. - output_directory: The directory where the output clips will be saved. """ # Load the video video = VideoFileClip(video_path) # Calculate total duration of the video total_duration = video.duration # Calculate number of clips needed num_clips = int(total_duration / clip_duration) # Iterate over each clip and extract it for i in range(num_clips): start_time = i * clip_duration end_time = min((i + 1) * clip_duration, total_duration) clip = video.subclip(start_time, end_time) # Save the clip output_file = f"{output_directory}/clip_{i+1}.mp4" clip.write_videofile(output_file) # Close the original video video.close() # Example usage if __name__ == "__main__": input_video_path = "path/to/your/podcast_video.mp4" output_directory = "path/to/your/output/directory" clip_duration = 60 # Duration of each clip in seconds convert_to_short_clips(input_video_path, clip_duration, output_directory)

No comments:

Post a Comment

converter

  from moviepy.editor import VideoFileClip def convert_to_short_clips(video_path, clip_duration, output_directory): """...