Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions soothe/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def encode(
output_file: str,
timeout: int,
verbose: bool,
keep_files: bool,
):
"""Encodes input_file in output_file"""
raise NotImplementedError
Expand Down
1 change: 1 addition & 0 deletions soothe/encoders/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def encode(
output_file: str,
timeout: int,
verbose: bool,
keep_files: bool,
):
"""Copies input_file to output_file"""

Expand Down
1 change: 1 addition & 0 deletions soothe/encoders/gstreamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def encode(
output_file: str,
timeout: int,
verbose: bool,
keep_files: bool,
):
"""Encodes input_file in output_file"""

Expand Down
40 changes: 32 additions & 8 deletions soothe/encoders/vk_video_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

"""Module for Vulkan Video Samples based encoders"""

import os
import shlex
import subprocess

Expand All @@ -30,13 +31,15 @@
from ..encoder import Encoder, register_encoder
from ..utils import normalize_binary_cmd, run_command

VKVS_TPL = "{} -c {} -i {} -o {} --profile {}"
VKVS_ENC_TPL = "{} -c {} -i {} -o {} --profile {}"
VKVS_DEC_TPL = "{} -i {} -o {} --y4m --noPresent --enablePostProcessFilter 0"


class VKVS(Encoder):
"""Base class for Vulkan Video Samples encoders"""

cmd: str
enc_cmd: str
dec_cmd: str
provider = 'VKVS'
variant: str

Expand All @@ -46,7 +49,8 @@ def __init__(self) -> None:
f'{self.variant}'
self.description = f'{self.provider} {self.codec.value}'\
f' {self.variant} encoder'
self.cmd = normalize_binary_cmd('vk-video-enc-test')
self.enc_cmd = normalize_binary_cmd('vk-video-enc-test')
self.dec_cmd = normalize_binary_cmd('vk-video-dec-test')

def codec_name(self, codec: Codec) -> str:
"""Generate the codec name"""
Expand All @@ -58,25 +62,37 @@ def codec_name(self, codec: Codec) -> str:
return 'av1'
return 'unknown'

def _construct_cmd(
def _construct_enc_cmd(
self,
input_file: str,
output_file: str,
) -> str:
"""Generate the VKVS command used to encode the asset"""
return VKVS_TPL.format(
self.cmd,
return VKVS_ENC_TPL.format(
self.enc_cmd,
self.codec_name(self.codec),
input_file,
output_file,
self.variant
)

def _construct_dec_cmd(
self,
input_file: str,
output_file: str,
) -> str:
"""Generate the VKVS command used to decode the asset"""
return VKVS_DEC_TPL.format(
self.dec_cmd,
input_file,
output_file
)

@lru_cache(maxsize=128)
def check(self, verbose: bool) -> bool:
"""Check if VKVS decoder is valid"""
try:
enc_cmd = f"{self.cmd} --help"
enc_cmd = f"{self.enc_cmd} --help"
run_command(shlex.split(enc_cmd), verbose=verbose)
except FileNotFoundError as e:
print("Executable not found:", e)
Expand All @@ -92,10 +108,18 @@ def encode(
output_file: str,
timeout: int,
verbose: bool,
keep_files: bool,
):
"""Encodes input_file in output_file"""
enc_cmd = self._construct_cmd(input_file, output_file)
encoded_file = f"{output_file}.enc"
enc_cmd = self._construct_enc_cmd(input_file, encoded_file)
run_command(shlex.split(enc_cmd), timeout=timeout, verbose=verbose)
dec_cmd = self._construct_dec_cmd(encoded_file, output_file)
run_command(shlex.split(dec_cmd), timeout=timeout, verbose=verbose)
if not keep_files \
and os.path.exists(encoded_file) \
and os.path.isfile(encoded_file):
os.remove(encoded_file)


@register_encoder
Expand Down
1 change: 1 addition & 0 deletions soothe/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def run(self, result: Result) -> None:
output_filepath,
self.params.timeout,
self.params.verbose,
self.params.keep_files
)
result.encode_time = perf_counter() - start
except TimeoutExpired:
Expand Down