Skip to content

Commit

Permalink
Add hardware accelerated profiles
Browse files Browse the repository at this point in the history
Fixes #27 and #45
  • Loading branch information
JuniorIsAJitterbug committed Apr 24, 2024
1 parent f340fea commit 162f2e7
Show file tree
Hide file tree
Showing 26 changed files with 812 additions and 490 deletions.
259 changes: 61 additions & 198 deletions flake.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
ruff
mediainfo
inputs.jitterbug.packages.${pkgs.system}.vhs-decode
inputs.jitterbug.packages.${pkgs.system}.ab-av1
];

languages.python = {
Expand All @@ -55,10 +56,11 @@
pre-commit.hooks = {
ruff.enable = true;
pyright.enable = true;
};

pre-commit.settings = {
yamllint.relaxed = true;
yamllint = {
enable = true;
settings.preset = "relaxed";
};
};
};

Expand All @@ -67,7 +69,7 @@

packages = with pkgs;[
ruff
fuse
mediainfo
];

languages.python = {
Expand Down
12 changes: 8 additions & 4 deletions src/tbc_video_export/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,14 @@ class VideoBitDepthType(Enum):
BIT16 = "16bit"


class ProfileVideoType(Enum):
"""Video types for profiles."""

LOSSLESS = "lossless"
class HardwareAccelType(Enum):
"""Hardware accel types for profiles."""

VAAPI = "vaapi"
NVENC = "nvenc"
QUICKSYNC = "quicksync"
AMF = "amf"
VIDEOTOOLBOX = "videotoolbox"


class VideoFormatType(Enum):
Expand Down
1 change: 0 additions & 1 deletion src/tbc_video_export/common/file_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def __init__(self, opts: Opts, config: Config) -> None:
self._config = config

self._profile = self._config.get_profile(GetProfileFilter(self._opts.profile))
self._video_subtype = self._opts.video_profile

# initially set both input and output files to the input file
# file without file extension
Expand Down
36 changes: 16 additions & 20 deletions src/tbc_video_export/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
)

if TYPE_CHECKING:
from tbc_video_export.common.enums import ProfileVideoType, VideoSystem
from tbc_video_export.common.enums import (
HardwareAccelType,
VideoSystem,
)
from tbc_video_export.config.json import JsonConfig


Expand Down Expand Up @@ -57,16 +60,6 @@ def __init__(self) -> None:
"Configuration file missing required fields.", self.get_config_file()
) from e

@cached_property
def video_profiles(self) -> list[ProfileVideo]:
"""Return list of available video profiles."""
try:
return [ProfileVideo(p) for p in self._data["video_profiles"]]
except KeyError as e:
raise exceptions.InvalidProfileError(
"Could not read video profiles.", self.get_config_file()
) from e

@cached_property
def audio_profiles(self) -> list[ProfileAudio]:
"""Return list of available audio profiles."""
Expand Down Expand Up @@ -105,9 +98,12 @@ def get_profile(self, profile_filter: GetProfileFilter) -> Profile:
)

if profile is None:
raise exceptions.InvalidProfileError(
f"Could not find profile {profile_filter.name}."
)
err_msg = f"Could not find profile {profile_filter.name}."

if profile_filter.hwaccel_type is not None:
err_msg += f" ({profile_filter.hwaccel_type.value})"

raise exceptions.InvalidProfileError(err_msg)

return profile
except KeyError as e:
Expand Down Expand Up @@ -254,15 +250,15 @@ def _generate_profile(self, profile_name: str) -> list[Profile]:
# get video profile(s) for profile
if isinstance(profile_data["video_profile"], list):
video_profiles = [
ProfileVideo(json_video_profile)
ProfileVideo(profile_data, json_video_profile)
for json_video_profile in self._data["video_profiles"]
for video_profile_name in profile_data["video_profile"]
if json_video_profile["name"] == video_profile_name
]
else:
video_profiles = [
next(
ProfileVideo(json_video_profile)
ProfileVideo(profile_data, json_video_profile)
for json_video_profile in self._data["video_profiles"]
if json_video_profile["name"] == profile_data["video_profile"]
)
Expand Down Expand Up @@ -295,7 +291,7 @@ def _generate_profile(self, profile_name: str) -> list[Profile]:
)

# set profile overrides
if (override := video_profile.filter_profiles_override) is not None:
if override := video_profile.filter_profiles:
profile.filter_profiles = [
ProfileFilter(json_filter_profile)
for json_filter_profile in self._data["filter_profiles"]
Expand All @@ -317,7 +313,7 @@ class GetProfileFilter:
"""Container class for get profile filter params."""

name: str
video_type: ProfileVideoType | None = None
hwaccel_type: HardwareAccelType | None = None
video_system: VideoSystem | None = None

def match(self, profile: Profile) -> bool:
Expand All @@ -328,8 +324,8 @@ def match(self, profile: Profile) -> bool:
return False

if (
self.video_type is not None
and video_profile.profile_type is not self.video_type
self.hwaccel_type is not None
and video_profile.hardware_accel is not self.hwaccel_type
):
return False

Expand Down
Loading

0 comments on commit 162f2e7

Please sign in to comment.