Skip to content

Commit

Permalink
cli: add option to output both PES and SUP. Push version to hotfix v0…
Browse files Browse the repository at this point in the history
….1.9
  • Loading branch information
cubicibo committed Aug 5, 2023
1 parent 0876499 commit 4d632e0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion SUPer/__metadata__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

__MAJOR = 0
__MINOR = 1
__REVISION = 8
__REVISION = 9

__name__ = "SUPer"
__version__ = '.'.join(map(str, [__MAJOR, __MINOR, __REVISION]))
Expand Down
32 changes: 24 additions & 8 deletions SUPer/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def optimise(self) -> None:
if self.kwargs.get('adjust_dropframe', False):
if isinstance(bdn.fps, float):
bdn.fps = round(bdn.fps)
logger.info(f"NTSC timing flag: using {round(bdn.fps)} for timestamps rather than BDNXML {clip_framerate:.03f}.")
logger.info(f"NTSC timing flag: scaling all timestamps by 1.001.")
else:
self.kwargs['adjust_dropframe'] = False
logger.warning("Ignored NDF flag with integer framerate.")
Expand Down Expand Up @@ -118,7 +118,7 @@ def scale_pcsfps(self) -> bool:
ds.pcs.fps = new_pcs_fps
scaled_fps = True
else:
logger.error(f"Expexcted 25 or 30 fps for 2x scaling. Got '{BDVideo.LUT_FPS_PCSFPS[pcs_fps]}'.")
logger.error(f"Expected 25 or 30 fps for 2x scaling. Got '{BDVideo.LUT_FPS_PCSFPS[pcs_fps]}'.")
return scaled_fps

def merge(self, input_sup) -> None:
Expand All @@ -137,8 +137,24 @@ def merge(self, input_sup) -> None:

def write_output(self, fp: str) -> None:
if self._epochs:
if fp.lower().endswith('pes'):
writer = EsMuiStream.segment_writer(fp)
is_pes = fp.lower().endswith('pes')
is_sup = fp.lower().endswith('sup')
if not (is_pes or is_sup):
logger.warning("Unknown extension, assuming a .SUP file...")
is_sup = True
if self.kwargs.get('output_all_formats', False):
is_pes = is_sup = True
if len(filepath := fp.split('.')) > 1:
fp_pes = ''.join(filepath[:-1]) + '.pes'
fp_sup = ''.join(filepath[:-1]) + '.sup'
else:
fp_pes = filepath[0] + '.pes'
fp_sup = filepath[0] + '.sup'

if is_pes:
logger.info(f"Writing output file {fp_pes}")

writer = EsMuiStream.segment_writer(fp_pes)
next(writer) #init writer
for epoch in self._epochs:
for ds in epoch:
Expand All @@ -147,10 +163,10 @@ def write_output(self, fp: str) -> None:
# Close ESMUI writer
writer.send(None)
writer.close()
else:
if not fp.lower().endswith('sup'):
logger.warning("Unknown extension, assuming a .SUP file...")
with open(fp, 'wb') as f:
if is_sup:
logger.info(f"Writing output file {fp_sup}")

with open(fp_sup, 'wb') as f:
for epoch in self._epochs:
f.write(bytes(epoch))
else:
Expand Down
6 changes: 6 additions & 0 deletions supercli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def check_ext(fp: Union[Path, str]) -> None:
parser.add_argument('-a', '--aheadoftime', help="Allow ahead of time decoding.", action='store_true', default=False, required=False)
parser.add_argument('-p', '--palette', help="Always write the full palette.", action='store_true', default=False, required=False)
parser.add_argument('-y', '--yes', help="Overwrite output file", action='store_true', default=False, required=False)
parser.add_argument('-w', '--withsup', help="Write SUP aside of PES file", action='store_true', default=False, required=False)


parser.add_argument('-v', '--version', action='version', version=f"(c) {__author__}, v{LIB_VERSION}")
parser.add_argument("output", type=str)
Expand All @@ -92,6 +94,9 @@ def check_ext(fp: Union[Path, str]) -> None:
if ext == 'pes' and not args.palette:
logger.warning("PES output: generating with full palette flag.")
args.palette = True
if ext != 'pes' and args.withsup:
args.withsup = False
logger.warning("Ignoring withsup flag, output is not PES.")

print("\n @@@@@@@ &@@@ @@@@ @@@@@@@\n"\
"@@@B &@@@ @@@@ @@@@ @@@@ @@@\n"\
Expand Down Expand Up @@ -119,6 +124,7 @@ def check_ext(fp: Union[Path, str]) -> None:
'enforce_dts': not args.nodts,
'no_overlap': not args.aheadoftime,
'full_palette': args.palette,
'output_all_formats': args.withsup,
}

bdnr = BDNRender(args.input, parameters)
Expand Down
17 changes: 13 additions & 4 deletions supergui.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def get_kwargs() -> dict[str, int]:
'enforce_dts': set_dts.value,
'no_overlap': scenarist_checks.value,
'full_palette': scenarist_fullpal.value,
'output_all_formats': all_formats.value,
}

def wrapper_mp() -> None:
Expand Down Expand Up @@ -107,6 +108,13 @@ def monitor_mp() -> None:
do_super.enabled = True
do_super.text = SUPER_STRING

def hide_chkbox() -> None:
if all_formats.value:
set_dts.value = scenarist_checks.value = scenarist_fullpal.value = True
set_dts.enabled = scenarist_checks.enabled = scenarist_fullpal.enabled = False
elif not supout.value.lower().endswith('pes'):
set_dts.enabled = scenarist_checks.enabled = scenarist_fullpal.enabled = True

def get_sup() -> None:
pg_sup_types = ('*.sup', '*.SUP')
supname.value = app.select_file(filetypes=[["SUP", pg_sup_types], ["All files", "*"]])
Expand Down Expand Up @@ -136,9 +144,10 @@ def set_outputsup() -> None:
scenarist_fullpal.value = True
scenarist_fullpal.enabled = False
else:
set_dts.enabled = True
scenarist_checks.enabled = True
scenarist_fullpal.enabled = True
if not all_formats.value:
set_dts.enabled = True
scenarist_checks.enabled = True
scenarist_fullpal.enabled = True

if bdnname.value != '':
do_super.enabled = True
Expand Down Expand Up @@ -179,7 +188,6 @@ def from_bdnxml(queue: ...) -> None:
logger.info(f"Merging output with {supi}")
sup_obj.merge(supi)

logger.info(f"Writing output file {supo}")
sup_obj.write_output(supo)

logger.info("Finished, exiting...")
Expand Down Expand Up @@ -272,6 +280,7 @@ def from_bdnxml(queue: ...) -> None:
Hovertip(scenarist_fullpal.tk, "Scenarist BD mendles with the imported files and may mess up the palette assignments.\n"\
"Writing the full palette everytime ensures palette data consistency throughout the stream.")

all_formats = CheckBox(app, text="Generate both SUP and PES+MUI files.", grid=[0,pos_v:=pos_v+1,2,1], align='left', command=hide_chkbox)

bspace = Box(app, layout="grid", grid=[0,pos_v:=pos_v+1,2,1])
Text(bspace, "Color space: ", grid=[0,0], align='right')
Expand Down

0 comments on commit 4d632e0

Please sign in to comment.