Skip to content

Commit

Permalink
alignments tool - Don't re-analyze video if metadata in alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
torzdf committed Mar 30, 2022
1 parent 635a24d commit 30872ef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
19 changes: 18 additions & 1 deletion tools/alignments/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,30 @@ def __init__(self, alignments, arguments):
self._is_legacy = self._alignments.version == 1.0 # pylint:disable=protected-access
self._mask_pipeline = None
self._faces_dir = arguments.faces_dir
self._frames = Frames(arguments.frames_dir)

self._frames = Frames(arguments.frames_dir, self._get_count())
self._extracted_faces = ExtractedFaces(self._frames,
self._alignments,
size=arguments.size)
self._saver = None
logger.debug("Initialized %s", self.__class__.__name__)

def _get_count(self):
""" If the alignments file has been run through the manual tool, then it will hold video
meta information, meaning that the count of frames in the alignment file can be relied
on to be accurate.
Returns
-------
int or ``None``
For video input which contain video meta-data in the alignments file then the count of
frames is returned. In all other cases ``None`` is returned
"""
has_meta = all(val is not None for val in self._alignments.video_meta_data.values())
retval = len(self._alignments.video_meta_data["pts_time"]) if has_meta else None
logger.debug("Frame count from alignments file: (has_meta: %s, %s", has_meta, retval)
return retval

def process(self):
""" Run the re-extraction from Alignments file process"""
logger.info("[EXTRACT FACES]") # Tidy up cli output
Expand Down
9 changes: 6 additions & 3 deletions tools/alignments/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ class MediaLoader():
----------
folder: str
The folder of images or video file to load images from
count: int or ``None``, optional
If the total frame count is known it can be passed in here which will skip
analyzing a video file. If the count is not passed in, it will be calculated.
"""
def __init__(self, folder):
def __init__(self, folder, count=None):
logger.debug("Initializing %s: (folder: '%s')", self.__class__.__name__, folder)
logger.info("[%s DATA]", self.__class__.__name__.upper())
self._count = None
self._count = count
self.folder = folder
self.vid_reader = self.check_input_folder()
self.file_list_sorted = self.sorted_items()
Expand Down Expand Up @@ -188,7 +191,7 @@ def stream(self, skip_list=None):
numpy.ndarray
The image that has been loaded from disk
"""
loader = ImagesLoader(self.folder, queue_size=32)
loader = ImagesLoader(self.folder, queue_size=32, count=self._count)
if skip_list is not None:
loader.add_skip_list(skip_list)
for filename, image in loader.load():
Expand Down

0 comments on commit 30872ef

Please sign in to comment.