Skip to content

Commit

Permalink
bugfix: Patch writer. Correctly split frame number from the end of fi…
Browse files Browse the repository at this point in the history
…lenames
  • Loading branch information
torzdf committed May 10, 2024
1 parent 13dd5b3 commit 8c3bc39
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions plugins/convert/writer/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import json
import logging
import re

import os
import cv2
Expand Down Expand Up @@ -34,6 +35,7 @@ def __init__(self, output_folder: str, patch_size: int, **kwargs) -> None:
super().__init__(output_folder, **kwargs)
self._extension = {"png": ".png", "tiff": ".tif"}[self.config["format"]]
self._separate_mask = self.config["separate_mask"]
self._fname_split = re.compile("[^0-9a-zA-Z]")

if self._extension == ".png" and self.config["bit_depth"] not in ("8", "16"):
logger.warning("Patch Writer: Bit Depth '%s' is unsupported for format '%s'. "
Expand Down Expand Up @@ -97,18 +99,20 @@ def _get_new_filename(self, filename: str, face_index: int) -> str:
fname, ext = os.path.splitext(filename)
fname = os.path.basename(fname)

split_fname = fname.rsplit("_", 1)
if split_fname[-1].isdigit():
split_fname = self._fname_split.split(fname)
if split_fname and split_fname[-1].isdigit():
i_frame_no = (int(split_fname[-1]) +
(int(self.config["start_index"]) - 1) +
self.config["index_offset"])
frame_no = f".{str(i_frame_no).rjust(self.config['number_padding'], '0')}"
base_fname = fname[:-len(split_fname[-1]) - 1]
else:
frame_no = ""
base_fname = fname

retval = ""
if self.config["include_filename"]:
retval += f"{split_fname[0]}"
retval += base_fname
if self.config["face_index_location"] == "before":
retval = f"{retval}_{face_idx}"
retval += frame_no
Expand Down

0 comments on commit 8c3bc39

Please sign in to comment.