Skip to content

muxtools.muxing.muxfiles

VideoFile

VideoFile(file: PathLike | Sequence[PathLike] | GlobSearch, container_delay: int = 0, source: PathLike | None = None, tags: dict[str, str] | None = None)

Bases: MuxingFile

Source code in muxtools/muxing/muxfiles.py
def __init__(
    self,
    file: PathLike | Sequence[PathLike] | GlobSearch,
    container_delay: int = 0,
    source: PathLike | None = None,
    tags: dict[str, str] | None = None,
):
    super().__init__(ensure_path(file, self), container_delay, source, tags)

to_track

to_track(name: str = '', lang: str = 'ja', default: bool = True, forced: bool = False, timecode_file: PathLike | GlobSearch | None = None, crop: int | tuple[int, int] | tuple[int, int, int, int] | None = None, args: list[str] = [], tags: dict[str, str] | None = None, **kwargs: Any) -> VideoTrack

Parameters:

Name Type Description Default
timecode_file PathLike | GlobSearch | None

Pass a path for proper vfr playback if needed.

None
crop int | tuple[int, int] | tuple[int, int, int, int] | None

Container based cropping with (horizontal, vertical) or (left, top, right, bottom). Will crop the same on all sides if passed a single integer.

None
Source code in muxtools/muxing/muxfiles.py
def to_track(
    self,
    name: str = "",
    lang: str = "ja",
    default: bool = True,
    forced: bool = False,
    timecode_file: PathLike | GlobSearch | None = None,
    crop: int | tuple[int, int] | tuple[int, int, int, int] | None = None,
    args: list[str] = [],
    tags: dict[str, str] | None = None,
    **kwargs: Any,
) -> VideoTrack:
    """
    :param timecode_file:       Pass a path for proper vfr playback if needed.
    :param crop:                Container based cropping with (horizontal, vertical) or (left, top, right, bottom).
                                Will crop the same on all sides if passed a single integer.
    """
    return VideoTrack(self.file, name, lang, default, forced, self.container_delay, timecode_file, crop, args, tags or self.tags, **kwargs)

AudioFile

AudioFile(file: PathLike | Sequence[PathLike] | GlobSearch, container_delay: int = 0, source: PathLike | None = None, tags: dict[str, str] | None = None, duration: timedelta | None = None)

Bases: MuxingFile

Source code in muxtools/muxing/muxfiles.py
def __init__(
    self,
    file: PathLike | Sequence[PathLike] | GlobSearch,
    container_delay: int = 0,
    source: PathLike | None = None,
    tags: dict[str, str] | None = None,
    duration: timedelta | None = None,
):
    super().__init__(ensure_path(file, self), container_delay, source, tags)
    self.duration = duration

to_mka

to_mka(delete: bool = True, quiet: bool = True) -> Path

Muxes the AudioFile to an MKA file with specified container delay applied.

Parameters:

Name Type Description Default
delete bool

Deletes the current file after muxing

True

Returns:

Type Description
Path

Path object of the resulting mka file

Source code in muxtools/muxing/muxfiles.py
def to_mka(self, delete: bool = True, quiet: bool = True) -> Path:
    """
    Muxes the AudioFile to an MKA file with specified container delay applied.

    :param delete:      Deletes the current file after muxing
    :return:            Path object of the resulting mka file
    """
    mkv = get_executable("mkvmerge")
    self.file = ensure_path_exists(self.file, self)
    out = self.file.with_suffix(".mka")
    args = [mkv, "-o", str(out.resolve()), "--audio-tracks", "0"]
    if self.container_delay:
        args.extend(["--sync", f"0:{self.container_delay}"])
    args.append(str(self.file))
    if run_commandline(args, quiet) in [0, 1]:
        if delete:
            self.file.unlink()
        return out
    else:
        raise error("Failed to mux AudioFile to mka.", self)