Hello - I just setup Faceswap for the first time in years so I can get back into it, but both the CLI and the GUI seems to be ignoring my "extract-every-n" setting. Instead of checking every 12th frame, it seems to be checking every frame, producing far too many images.
ignores "extract every" setting
Read the FAQs and search the forum before posting a new topic.
This forum is for reporting errors with the Extraction process. If you want to get tips, or better understand the Extract process, then you should look in the Extract Discussion forum.
Please mark any answers that fixed your problems so others can find the solutions.
Re: ignores "extract every" setting
I tried digging into the code, and it seems the -N option only servers to filter an input file list, not to skip frames when extracting faces from a video.
I recall the -een
flag used to skip video frames back when I first started using Faceswap a few years ago, and it seems to now be deprecated in favor of -N
, but the new flag doesn't do what the old one did.
Re: ignores "extract every" setting
I finally found the place in the code to hack to skip frames before they're processed for faces:
Code: Select all
# faceswap/lib/image.py
class ImagesLoader(ImageIO):
...
def _from_video(self):
...
for idx, frame in enumerate(reader):
# HACK GOES HERE
...
Now I just need to figure out how to drive that hack using the -N
arg.
Is it worth submitting a patch? Is the project still active? (Last commit on 'fs3' branch was seven months ago.)
Re: ignores "extract every" setting
Here's the full diff I ended up with:
Code: Select all
diff --git a/lib/image.py b/lib/image.py
index 897d8e2..e3a8298 100644
--- a/lib/image.py
+++ b/lib/image.py
@@ -1073,6 +1073,7 @@ class ImagesLoader(ImageIO):
def __init__(self,
path,
+ een,
queue_size=8,
fast_count=True,
skip_list=None,
@@ -1087,6 +1088,7 @@ class ImagesLoader(ImageIO):
self._fps = self._get_fps()
self._count = None
+ self._een = een if een > 1 else None
self._file_list = None
self._get_count_and_filelist(fast_count, count)
@@ -1242,6 +1244,9 @@ class ImagesLoader(ImageIO):
logger.debug("Loading frames from video: '%s'", self.location)
reader = imageio.get_reader(self.location, "ffmpeg")
for idx, frame in enumerate(reader):
+ if self._een and idx % self._een != 0:
+ logger.trace("Skipping frame %s due to een", idx)
+ continue
if idx in self._skip_list:
logger.trace("Skipping frame %s due to skip list", idx)
continue
diff --git a/scripts/extract.py b/scripts/extract.py
index a4912d5..fc0bffa 100644
--- a/scripts/extract.py
+++ b/scripts/extract.py
@@ -496,10 +496,11 @@ class PipelineLoader():
def __init__(self,
path: str | list[str],
extractor: Extractor,
+ een: int,
aligned_filenames: list[str] | None = None) -> None:
logger.debug("Initializing %s: (path: %s, extractor: %s, aligned_filenames: %s)",
self.__class__.__name__, path, extractor, aligned_filenames)
- self._images = ImagesLoader(path, fast_count=True)
+ self._images = ImagesLoader(path, fast_count=True, een=een)
self._extractor = extractor
self._threads: list[MultiThread] = []
self._aligned_filenames = [] if aligned_filenames is None else aligned_filenames
@@ -639,7 +640,7 @@ class _Extract():
self._args.output_dir)
logger.info("Output Directory: %s", self._output_dir)
- self._loader = PipelineLoader(self._args.input_dir, extractor)
+ self._loader = PipelineLoader(self._args.input_dir, extractor, een=self._args.extract_every_n)
self._alignments = Alignments(self._args, True, self._loader.is_video)
self._extractor = extractor