Skip to content

y5gfunc.encode.audio.audio_config

audio_config

Classes:

Name Description
ProcessMode

Defines how an audio track should be processed.

TrackConfig
AudioConfig

Functions:

Name Description
create_main_lossless_2ch
create_main_lossless_multi
create_main_lossy
create_main_special
create_comment_lossless_2ch
create_comment_lossless_multi
create_comment_lossy_low
create_comment_lossy_2ch
create_comment_lossy_multi

ProcessMode

Bases: StrEnum

Defines how an audio track should be processed.

Attributes:

Name Type Description
COPY

Keep original track, stream copy if possible

COMPRESS

Re-encode losslessly (e.g., to FLAC)

LOSSY

Re-encode lossily (e.g., to AAC, Opus)

DROP

Do not include this track in the output

COPY class-attribute instance-attribute

COPY = 'copy'

COMPRESS class-attribute instance-attribute

COMPRESS = 'compress'

LOSSY class-attribute instance-attribute

LOSSY = 'lossy'

DROP class-attribute instance-attribute

DROP = 'drop'

TrackConfig dataclass

TrackConfig(mode: ProcessMode = COPY, format: str = 'flac', bitrate: Optional[str] = None)

Attributes:

Name Type Description
mode ProcessMode
format str
bitrate Optional[str]

mode class-attribute instance-attribute

mode: ProcessMode = COPY

format class-attribute instance-attribute

format: str = 'flac'

bitrate class-attribute instance-attribute

bitrate: Optional[str] = None

AudioConfig dataclass

AudioConfig(main_lossless_2ch: TrackConfig = create_main_lossless_2ch(), main_lossless_multi: TrackConfig = create_main_lossless_multi(), main_lossy: TrackConfig = create_main_lossy(), main_special: TrackConfig = create_main_special(), comment_lossless_2ch: TrackConfig = create_comment_lossless_2ch(), comment_lossless_multi: TrackConfig = create_comment_lossless_multi(), comment_lossy_low: TrackConfig = create_comment_lossy_low(), comment_lossy_2ch: TrackConfig = create_comment_lossy_2ch(), comment_lossy_multi: TrackConfig = create_comment_lossy_multi(), lossy_threshold: int = 512)

Methods:

Name Description
get_track_config

Determines the appropriate TrackConfig based on audio track properties.

Attributes:

Name Type Description
main_lossless_2ch TrackConfig
main_lossless_multi TrackConfig
main_lossy TrackConfig
main_special TrackConfig
comment_lossless_2ch TrackConfig
comment_lossless_multi TrackConfig
comment_lossy_low TrackConfig
comment_lossy_2ch TrackConfig
comment_lossy_multi TrackConfig
lossy_threshold int

main_lossless_2ch class-attribute instance-attribute

main_lossless_2ch: TrackConfig = field(default_factory=create_main_lossless_2ch)

main_lossless_multi class-attribute instance-attribute

main_lossless_multi: TrackConfig = field(default_factory=create_main_lossless_multi)

main_lossy class-attribute instance-attribute

main_lossy: TrackConfig = field(default_factory=create_main_lossy)

main_special class-attribute instance-attribute

main_special: TrackConfig = field(default_factory=create_main_special)

comment_lossless_2ch class-attribute instance-attribute

comment_lossless_2ch: TrackConfig = field(default_factory=create_comment_lossless_2ch)

comment_lossless_multi class-attribute instance-attribute

comment_lossless_multi: TrackConfig = field(default_factory=create_comment_lossless_multi)

comment_lossy_low class-attribute instance-attribute

comment_lossy_low: TrackConfig = field(default_factory=create_comment_lossy_low)

comment_lossy_2ch class-attribute instance-attribute

comment_lossy_2ch: TrackConfig = field(default_factory=create_comment_lossy_2ch)

comment_lossy_multi class-attribute instance-attribute

comment_lossy_multi: TrackConfig = field(default_factory=create_comment_lossy_multi)

lossy_threshold class-attribute instance-attribute

lossy_threshold: int = 512

get_track_config

get_track_config(is_comment: bool, is_lossless: bool, channels: int, bitrate: Optional[int] = None, is_special: bool = False) -> TrackConfig

Determines the appropriate TrackConfig based on audio track properties.

Parameters:

Name Type Description Default

is_comment

bool

True if the track is commentary.

required

is_lossless

bool

True if the original track is lossless.

required

channels

int

Number of audio channels in the track.

required

bitrate

Optional[int]

Original bitrate of the track in Kbps (used for lossy threshold).

None

is_special

bool

True if the track should use the 'main_special' config.

False

Returns:

Type Description
TrackConfig

The selected TrackConfig instance defining how to process the track.

Source code in y5gfunc/encode/audio/audio_config.py
def get_track_config(
    self,
    is_comment: bool,
    is_lossless: bool,
    channels: int,
    bitrate: Optional[int] = None,
    is_special: bool = False,
) -> TrackConfig:
    """
    Determines the appropriate TrackConfig based on audio track properties.

    Args:
        is_comment: True if the track is commentary.
        is_lossless: True if the original track is lossless.
        channels: Number of audio channels in the track.
        bitrate: Original bitrate of the track in Kbps (used for lossy threshold).
        is_special: True if the track should use the 'main_special' config.

    Returns:
        The selected TrackConfig instance defining how to process the track.
    """

    if is_special:
        return self.main_special

    if is_comment:
        if is_lossless:
            return (
                self.comment_lossless_2ch
                if channels <= 2
                else self.comment_lossless_multi
            )
        else:  # lossy
            if bitrate and bitrate < self.lossy_threshold:
                return self.comment_lossy_low
            return (
                self.comment_lossy_2ch
                if channels <= 2
                else self.comment_lossy_multi
            )
    else:  # main track
        if is_lossless:
            return (
                self.main_lossless_2ch
                if channels <= 2
                else self.main_lossless_multi
            )
        return self.main_lossy

create_main_lossless_2ch

create_main_lossless_2ch() -> TrackConfig
Source code in y5gfunc/encode/audio/audio_config.py
def create_main_lossless_2ch() -> TrackConfig:
    return TrackConfig(mode=ProcessMode.COMPRESS, format="flac")

create_main_lossless_multi

create_main_lossless_multi() -> TrackConfig
Source code in y5gfunc/encode/audio/audio_config.py
def create_main_lossless_multi() -> TrackConfig:
    return TrackConfig(mode=ProcessMode.COMPRESS, format="flac")

create_main_lossy

create_main_lossy() -> TrackConfig
Source code in y5gfunc/encode/audio/audio_config.py
def create_main_lossy() -> TrackConfig:
    return TrackConfig(mode=ProcessMode.COPY)

create_main_special

create_main_special() -> TrackConfig
Source code in y5gfunc/encode/audio/audio_config.py
def create_main_special() -> TrackConfig:
    return TrackConfig(mode=ProcessMode.COMPRESS, format="flac")

create_comment_lossless_2ch

create_comment_lossless_2ch() -> TrackConfig
Source code in y5gfunc/encode/audio/audio_config.py
def create_comment_lossless_2ch() -> TrackConfig:
    return TrackConfig(mode=ProcessMode.LOSSY, format="aac", bitrate="192k")

create_comment_lossless_multi

create_comment_lossless_multi() -> TrackConfig
Source code in y5gfunc/encode/audio/audio_config.py
def create_comment_lossless_multi() -> TrackConfig:
    return TrackConfig(mode=ProcessMode.LOSSY, format="aac", bitrate="320k")

create_comment_lossy_low

create_comment_lossy_low() -> TrackConfig
Source code in y5gfunc/encode/audio/audio_config.py
def create_comment_lossy_low() -> TrackConfig:
    return TrackConfig(mode=ProcessMode.COPY)

create_comment_lossy_2ch

create_comment_lossy_2ch() -> TrackConfig
Source code in y5gfunc/encode/audio/audio_config.py
def create_comment_lossy_2ch() -> TrackConfig:
    return TrackConfig(mode=ProcessMode.LOSSY, format="aac", bitrate="192k")

create_comment_lossy_multi

create_comment_lossy_multi() -> TrackConfig
Source code in y5gfunc/encode/audio/audio_config.py
def create_comment_lossy_multi() -> TrackConfig:
    return TrackConfig(mode=ProcessMode.LOSSY, format="aac", bitrate="320k")