# First, find the path to the ffmpeg executable file installed on your system # You can do this by running one of the following commands in you system's terminal where ffmpeg # for windows type -a ffmpeg # for macOS import os # enables terminal commands through python Executable = '/Folder/Subfolder/ffmpeg.exe' # Add the path to the ffmpeg executable file obtained on line 3 or 4. For Mac OSX do not include the .exe # The code is set up for processing single video files # The processing is done in two steps. First it creates multiple short video files, one for each segment of interest. Then it concatenates them into one longer file # For each video file, one has to adjust the input path for the file of interest (line13), the lists of the starting points and durations for the video segments one is interested in (line 14 and 15 respectively) an also set a suitable output folder (line 18 and 21) vid_file = "Folder/Subfolder/video.mp4" # Add the path to the video you want to process start_points = 5, 25, 45, 65, 86, 105 # Here, paste a list of the start points for all video segments you are interested in, in seconds from the video start durations = 10,10,10,10,10,10 # Here, paste a list of durations for the video segments of interst, corresponding to the list on line 11 current_segment = 0 f = open("Folder/Subfolder/Output_folder/video_segments.txt","w+") # This creates a text file which lists the individual video segments that are extracted in the first step of the editing process # This loop will use the lists of starting points and corresponding durations (line 14,15) to create new video files of the segments of interest in the output folder # It will also create a text file that lists each video file, which is needed for concatenating the files afterwards for x in start_points: out_path = "Folder/Subfolder/Output_folder" # Set the path for the output folder file_name = str(x) file_format = ".mp4" # This would have to be changes if one is working with a different video file format output = out_path + "/" + file_name + file_format print(output) to_write = "file " + "'" + str(x) + file_format + "'" + "\n" f.write(to_write) myCommand = Executable + " -ss " + str(x) + " -i " + vid_file + " -t " + str(durations[current_segment]) + " " + output os.system(myCommand) current_segment = current_segment + 1 f.close() # The following code concatenates the video segments created by the for loop # note that the text file that lists the video segments should be placed in the same folder as the video segments segment_file = "Folder/Subfolder/Output_folder/video_segments.txt" # Add the path to the text file myCommand_2 = Executable + " -f concat -safe 0 -i " + str(segment_file) + " -c copy Folder/Subfolder/Output_folder/combo.mp4" # the final path written here gives the name and path to the concatenated video file os.system(myCommand_2)