5.2.9. ytpb.merge

Merge and cut media segments.

Note

The current implementation of segment merging is not optimal in terms of disk space, as it requires triple the amount of the total size of segments if cutting is requested (by default). Should be changed to use different techniques, without the need for intermediate files.

ytpb.merge.merge_segments(audio_segment_paths: list[Path] | None = None, video_segment_paths: list[Path] | None = None, output_directory: str | Path | None = None, output_stem: str | Path | None = None, temp_directory: str | Path | None = None, cut_at_start: float = 0, cut_at_end: float = 0, metadata_tags: dict[str, str] = None, cleanup: bool = True) Path

Merges and cuts media segments.

The cut_at_start and cut_at_end arguments define the values to be passed to FFmpeg: -ss <cut_at_start>s and -to <cut_at_end>s, respectively.

Parameters:
  • audio_segment_paths – Paths to audio segments.

  • video_segment_paths – Paths to video segments.

  • output_directory – Where to output the merged file.

  • output_stem – An output stem of the merged file.

  • temp_directory – Where to store intermediate files.

  • cut_at_start – An offset (in seconds) to cut at start.

  • cut_at_end – An offset (in seconds) to cut at end.

  • metadata_tags – Metadata tags to write to the merged file.

  • cleanup – Whether to cleanup intermediate files.

Returns:

A path of the merged file.

ytpb.merge.mux_and_cut_boundary_segment(audio_segment_path: Path, video_segment_path: Path, output_path: Path, video_codec: str | None = None, **cut_kwargs) None

Muxes and cuts a boundary segment.

Parameters:
  • audio_segment_path – A path to an audio segment.

  • video_segment_path – A path to a video segment.

  • output_path – An output path of the muxed segment.

  • video_codec – A video codec name.

  • cut_kwargs – Cut keyword arguments: cut_at_start and cut_at_end.