diff --git a/Containerfile b/Containerfile index d68751f..bb7a8b5 100644 --- a/Containerfile +++ b/Containerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/clamsproject/clams-python-opencv4-torch2:1.1.0 +FROM ghcr.io/clamsproject/clams-python-opencv4-torch2:1.1.6 # See https://github.com/orgs/clamsproject/packages?tab=packages&q=clams-python for more base images # IF you want to automatically publish this image to the clamsproject organization, diff --git a/app.py b/app.py index 49fa0f1..98f07ec 100644 --- a/app.py +++ b/app.py @@ -101,16 +101,14 @@ def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif: self.logger.info(f"Processing video {vd.id} at {vd.location_path()}") # opening here will add all basic metadata props to the document vcap = vdh.capture(vd) + fps = vd.get_property('fps') total_frames = vd.get_property(vdh.FRAMECOUNT_DOCPROP_KEY) total_ms = int(vdh.framenum_to_millisecond(vd, total_frames)) - sframe, eframe, srate = [vdh.millisecond_to_framenum(vd, p) for p in - [configs['startAt'], configs['stopAt'], configs['sampleRate']]] - if eframe < sframe or vd.get_property('frameCount') < sframe: - raise ValueError(f"Invalid frame range: {sframe} - {eframe} (total frame count: {vd.get_property('frameCount')})") - if eframe > vd.get_property('frameCount'): - eframe = int(vd.get_property('frameCount')) - sampled = vdh.sample_frames(sframe, eframe, srate) - self.logger.info(f'Sampled {len(sampled)} frames btw {sframe} - {eframe} ms (every{srate} ms)') + start_ms = max(0, configs['startAt']) + final_ms = min(total_ms, configs['stopAt']) + sframe, eframe = [vdh.millisecond_to_framenum(vd, p) for p in [start_ms, final_ms]] + sampled = vdh.sample_frames(sframe, eframe, configs['sampleRate'] / 1000 * fps) + self.logger.info(f'Sampled {len(sampled)} frames btw {start_ms} - {final_ms} ms (every {configs["sampleRate"]} ms)') t = time.perf_counter() positions = [int(vdh.framenum_to_millisecond(vd, sample)) for sample in sampled] extracted = vdh.extract_frames_as_images(vd, sampled, as_PIL=True) diff --git a/requirements.txt b/requirements.txt index 1c38752..f94203a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -clams-python==1.1.3 +clams-python==1.1.6 torch==2.* torchvision torchmetrics