Page 1 of 1

ignores "extract every" setting

Posted: Sun Mar 09, 2025 12:51 am
by korrupt78

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.


Re: ignores "extract every" setting

Posted: Sun Mar 09, 2025 5:10 am
by korrupt78

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

Posted: Sun Mar 09, 2025 7:13 pm
by korrupt78

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

Posted: Sun Mar 09, 2025 9:00 pm
by korrupt78

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

Re: ignores "extract every" setting

Posted: Tue May 20, 2025 5:52 pm
by torzdf

I have not tested this, but I believe this issue is a regression because imageio-ffmpeg updated to a new version (as EEN definitely worked in the past, as I used it extensively)

I have now pinned to an older version of imageio-ffmpeg, so you may need to re-install faceswap. Hopefully this will fix the issue, but I would be keen to know either way.