This commit is contained in:
2025-10-03 14:28:55 -04:00
parent 4cbdb00e14
commit 4c847f7753
13 changed files with 121 additions and 57 deletions

View File

@@ -6,6 +6,7 @@ import pickle
from CommonCode.settings import get_logger, LogColorize
import logging
import numpy
import time
pfm = LogColorize.video_meta
if not ('__file__' in vars() or '__file__' in globals()):
@@ -37,9 +38,14 @@ def get_cache_loc(cpath):
class FTPVideo:
def __init__(self, cpath):
def __init__(self, cpath, ignore_filename = False):
self.cpath = cpath
self.file_info = get_info_from_ftp_filename(cpath)
self.ignore_filename = ignore_filename
if self.ignore_filename:
self.file_info = {'name':'None','index':0, 'timestamp': dt.datetime.now(), 'path': os.path.abspath(cpath)}
else:
self.file_info = get_info_from_ftp_filename(cpath)
self._real_path = None
self._frame_info = None
self._embeds = None
@@ -75,11 +81,18 @@ class FTPVideo:
self._embeds = npz_contents
npz_contents = self._embeds
ret_dict = {};
ret_dict['embeds'] = npz_contents['embeds']
ret_dict['frame_numbers'] = [int(x) for x in npz_contents['frame_numbers']]
if max(ret_dict['frame_numbers']) >= len(self.frames_info):
self.invalidate_timestamp_cache()
self.frames_info_rewrite()
ret_dict['frame_offsets'] = [self.frames_info[x]['offset'] for x in ret_dict['frame_numbers']]
ret_dict['frame_time'] = [self.frames_info[x]['time'] for x in ret_dict['frame_numbers']]
e_scores = self.embed_scores
@@ -114,6 +127,16 @@ class FTPVideo:
except Exception as e:
logger.warn(pfm(f'WRITE TO CACHE FAILED: {e} while writing {cache_loc}'))
def invalidate_timestamp_cache():
cache_loc = get_cache_loc(self.real_path)
os.remove(cache_loc)
def frames_info_rewrite(self):
self._frame_info = None
new_info = self.get_frames_info()
self.try_cache_write(self._frame_info)
self._frame_info = self.try_cache_read()
@property
def frames_info(self):
@@ -142,7 +165,7 @@ class FTPVideo:
logger.warn(pfm(f'RUNNING FFPROBE FAILED FOR {e} on {fpath}'))
logger.info(pfm(f'RAN FFPROBE SUCCESSFULLY FOR {fpath}'))
timestamps = list()
for line in out.decode("UTF-8").split("\n"):
if "," not in line: