Skip to content

Commit

Permalink
fixes possible disparity in passed sampling rate and actual frame sam…
Browse files Browse the repository at this point in the history
…pling
  • Loading branch information
keighrim committed Apr 2, 2024
1 parent 68059f8 commit 59a76ff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Containerfile
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
14 changes: 6 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
clams-python==1.1.3
clams-python==1.1.6
torch==2.*
torchvision
torchmetrics
Expand Down

0 comments on commit 59a76ff

Please sign in to comment.