A utility class for making test encodes.
This can automatically parse strings like
--preset veryfast --crf [14/15/0.5]
and will then run encodes with CRF 14, 14.5 and 15.
The same works with non stepping options like
--preset [fast,veryfast,slow,slower]
or
--sao [true,false]
(can also use yes/no and y/n for these)
Keep in mind that this will create an encode for EVERY combination and not some order.
--preset [fast,veryfast,ultrafast] --crf [14/15/0.5]
For example will end up with 9 encodes.
Source code in vsmuxtools/video/testing.py
| class SettingsTester:
"""
A utility class for making test encodes.
This can automatically parse strings like
`--preset veryfast --crf [14/15/0.5]`
and will then run encodes with CRF 14, 14.5 and 15.
The same works with non stepping options like
`--preset [fast,veryfast,slow,slower]`
or
`--sao [true,false]` (can also use yes/no and y/n for these)
Keep in mind that this will create an encode for EVERY combination and not some order.
`--preset [fast,veryfast,ultrafast] --crf [14/15/0.5]`
For example will end up with 9 encodes.
"""
encoder: VideoEncoder
encodes = list[tuple[str | None, str]]()
qp_file: str | None = None
def __init__(self, settings: str | list[str], encoder: VideoEncoder | None = None, qp_clip: SRC_FILE | vs.VideoNode | None = None) -> None:
if not encoder:
self.encoder = x265("--kek")
else:
self.encoder = encoder
if isinstance(self.encoder, SupportsQP) and qp_clip:
self.encoder.qp_clip = qp_clip
self.qp_file = self.encoder._get_qpfile()
if isinstance(settings, str):
self.encodes = generate_settings(settings)
else:
self.encodes = [(None, s) for s in settings]
def run(self, clip: vs.VideoNode, output_clips: bool = True) -> None:
"""
Runs all encodes with the settings specified/generated.
:param output_clips: Will index and output clips with proper naming if vspreview is installed.
This might obviously end up using quite a lot of ram.
"""
for encode in self.encodes:
encoder = self.encoder.__class__(settings=encode[1])
encoder.resumable = False
if isinstance(self.encoder, SupportsQP) and self.qp_file:
encoder.qp_file = self.qp_file
out = make_output("encode", "test", suffix="" if not encode[0] else f"[{encode[0]}]")
f = encoder.encode(clip, out)
if output_clips:
done = src(f.file, True)
try:
from vspreview import set_output
set_output(done, name=encode[0], cache=False)
except:
done.set_output(len(vs.get_outputs()))
|
Runs all encodes with the settings specified/generated.
Parameters:
Name |
Type |
Description |
Default |
output_clips
|
bool
|
Will index and output clips with proper naming if vspreview is installed. This might obviously end up using quite a lot of ram.
|
True
|
Source code in vsmuxtools/video/testing.py
| def run(self, clip: vs.VideoNode, output_clips: bool = True) -> None:
"""
Runs all encodes with the settings specified/generated.
:param output_clips: Will index and output clips with proper naming if vspreview is installed.
This might obviously end up using quite a lot of ram.
"""
for encode in self.encodes:
encoder = self.encoder.__class__(settings=encode[1])
encoder.resumable = False
if isinstance(self.encoder, SupportsQP) and self.qp_file:
encoder.qp_file = self.qp_file
out = make_output("encode", "test", suffix="" if not encode[0] else f"[{encode[0]}]")
f = encoder.encode(clip, out)
if output_clips:
done = src(f.file, True)
try:
from vspreview import set_output
set_output(done, name=encode[0], cache=False)
except:
done.set_output(len(vs.get_outputs()))
|