Video Splitting

scenedetect.video_splitter Module

The scenedetect.video_splitter module contains functions to split videos with a scene list using external tools (e.g. mkvmerge, ffmpeg), as well as functions to check if the tools are available.

These functions are mainly intended for use by the PySceneDetect command line interface (the scenedetect command).

Certain distributions of PySceneDetect may include the above software. If using a source distribution, these programs can be obtained from following URLs (note that mkvmerge is a part of the MKVToolNix package):

If you are a Linux user, you can likely obtain the above programs from your package manager (e.g. sudo apt-get install ffmpeg).

Once installed, ensure the program can be accessed system-wide by calling the mkvmerge or ffmpeg command from a terminal/command prompt. PySceneDetect will automatically use whichever program is available on the computer, depending on the specified command-line options.

scenedetect.video_splitter.is_ffmpeg_available()

Is ffmpeg Available: Gracefully checks if ffmpeg command is available.

Returns:(bool) True if the ffmpeg command is available, False otherwise.
scenedetect.video_splitter.is_mkvmerge_available()

Is mkvmerge Available: Gracefully checks if mkvmerge command is available.

Returns:(bool) True if the mkvmerge command is available, False otherwise.
scenedetect.video_splitter.split_video_ffmpeg(input_video_paths, scene_list, output_file_template, video_name, arg_override='-c:v libx264 -preset fast -crf 21 -c:a aac', hide_progress=False, suppress_output=False)

Calls the ffmpeg command on the input video(s), generating a new video for each scene based on the start/end timecodes.

Parameters:
  • input_video_paths (List[str]) – List of strings to the input video path(s). Is a list to allow for concatenation of multiple input videos together.
  • scene_list (List[Tuple[FrameTimecode, FrameTimecode]]) – List of scenes (pairs of FrameTimecodes) denoting the start/end frames of each scene.
  • output_file_template (str) – Template to use for generating the output filenames. Can use $VIDEO_NAME and $SCENE_NUMBER in this format, for example: $VIDEO_NAME - Scene $SCENE_NUMBER
  • video_name (str) – Name of the video to be substituted in output_file_template.
  • arg_override (str) – Allows overriding the arguments passed to ffmpeg for encoding.
  • hide_progress (bool) – If True, will hide progress bar provided by tqdm (if installed).
  • suppress_output (bool) – If True, will set verbosity to quiet for the first scene.
scenedetect.video_splitter.split_video_mkvmerge(input_video_paths, scene_list, output_file_template, video_name, suppress_output=False)

Calls the mkvmerge command on the input video(s), splitting it at the passed timecodes, where each scene is written in sequence from 001.

Parameters:
  • input_video_paths (List[str]) – List of strings to the input video path(s). Is a list to allow for concatenation of multiple input videos together.
  • scene_list (List[Tuple[FrameTimecode, FrameTimecode]]) – List of scenes (pairs of FrameTimecodes) denoting the start/end frames of each scene.
  • output_file_template (str) – Template to use for output files. Note that the scene number is automatically appended to the prefix by mkvmerge. Can use $VIDEO_NAME as a parameter in the template.
  • video_name (str) – Name of the video to be substituted in output_file_template.
  • suppress_output (bool) – If True, adds the –quiet flag when invoking mkvmerge.