Skip to main content

Concatenate Videos by List

Description

The concatenate_videos_by_list function concatenates multiple videos listed in a text file into a single output video. The list file must contain the paths of the video files to be concatenated. The function uses ffmpeg to perform the concatenation operation.

Function Signature:

def concatenate_videos_by_list(list_file_path: str, output_file_path: str):

Parameters

  • list_file_path (str): The file path to the text file that contains the list of video paths to concatenate.
  • output_file_path (str): The file path where the concatenated video will be saved.

Returns

  • None

Example Usage

concatenate_videos_by_list('video_list.txt', 'output_video.mp4')

Notes

  • The list file (list_file_path) should be formatted such that each line contains a path to a video file in the format file 'path_to_video'.
  • The function uses ffmpeg with the -f concat and -safe 0 options to concatenate the videos listed in the provided text file.
  • The -c copy option is used to copy the video streams without re-encoding them, preserving the original video quality.
  • The -y option automatically overwrites the output file if it already exists.

Error Handling

  • If an error occurs during the execution of the ffmpeg command, a subprocess.CalledProcessError is caught, and an error message is printed to the console.