dvt icon indicating copy to clipboard operation
dvt copied to clipboard

`freq` does not work consistently across the whole video file

Open Cutuchiqueno opened this issue 4 years ago • 0 comments

Describe the bug utils._which_frames does not filter frames as one would expect with respect to the freq-Attribute. It applies freq only within a present batch but not across batches for the entire movie. This leads to inconsistent steps in the output data.

To Reproduce

dextra = DataExtraction(FrameInput(input_path="./VID-20191006-WA0014.mp4"))  # default bsize=256
dextra.run_annotators([LchAnnotatorRay(freq=10)], max_batch=2)  #my custom annotator, using utils._which_frames function

which gives me data for the frames: [0, 10, 20, ..., 240, 250, 256, 266, 276, ..., 500, 510]

you see wrong frame step after switching from batch 1 to batch 2. This makes sense when looking at the implementation of utils._which_frames:

https://github.com/distant-viewing/dvt/blob/f4e5f895a9515f36368f73db6b53e12e837cd7fe/dvt/utils.py#L218

Regardless of the starting point of the current batch, the selection of frames always starts with 0 and the first frame in the second batch is frame 256.

Expected behavior The correct frame sequence in the above example should be [0, 10, 20, ..., 240, 250, 260, 270, ..., 500, 510]. The first frame of the second batch should be 260 which equates to the index 4 (not 0).

Desktop (please complete the following information):

  • Arch Linux
  • Python 3.7.1
  • dvt 0.3.3

Additional context I developed a fix which for which I would make a pull request if you agree upon my expected behaviour. It works like this:

The freq minus the rest of bnum times the bsize divided by the freq for bnum greater than 0 otherwise 0.

if frames is None:
        # return list(range(0, batch.bsize, freq))
        first_frame = 0
        _, rest = divmod(batch.bnum * batch.bsize, freq)
        if rest != 0:
            first_frame = freq - rest
        return list(range(first_frame, batch.bsize, freq))

This works well for me so far.

Cutuchiqueno avatar May 12 '20 11:05 Cutuchiqueno