supervision icon indicating copy to clipboard operation
supervision copied to clipboard

Change how frames are skipped in the generator

Open LinasKo opened this issue 1 year ago • 5 comments

❗We're looking for help in testing this feature. If you have the time, please run it on your video and report any errors encountered! See this comment for instructions.

Description

For some videos, e.g. the one in #1345, the frame generator generates no frames. This happens when video.get(cv2.CAP_PROP_FRAME_COUNT, x) is called, even when x = video.get(cv2.CAP_PROP_FRAME_COUNT).

Since we use this to skip the first N frames, we can do it manually instead by retrieving and dropping them.

This has the potential to affect many codebases, so thorough tests are needed.

At the very least. this should work on:

  1. Videos in supervision.assets
  2. ~~Videos in #1345~~ Already tested.
  3. 5 videos from different online sources, ideally with different video formats.
  4. Bonus: I had some GoPro videos that had invalid frames at the start. I should test with those.

Please delete options that are not relevant.

  • [x] Bug fix (non-breaking change which fixes an issue)

How has this change been tested, please provide a testcase or example of how you tested the change?

Tested locally on Videos of #1345

Any specific deployment considerations

Docs

  • [ ] Docs updated? What were the changes:

LinasKo avatar Jul 12 '24 09:07 LinasKo

We'd like some help testing this! If you have the time, please run it on videos you have (any video will do!) and tell us if there are any issues. This will help us merge faster.

It's pretty simple:

  1. Install the library
pip install git+https://github.com/roboflow/supervision.git@fix/no-frames-generated-for-some-videos
  1. Run it
import supervision as sv
import cv2

path_to_video = "test2.mp4"

cv2.namedWindow("Frame", cv2.WINDOW_NORMAL)
for frame in sv.get_video_frames_generator(path_to_video):
    cv2.imshow("Frame", frame)
    
    # Press Q to stop
    if cv2.waitKey(1) == ord("q"):
        break

I'd like to know:

  1. What video format did you use?
  2. Did it play successfully?
  3. Did the playback start from the beginning, or did it skip some frames?
  4. Did you have to wait before it started?
  5. Did it reach the end?
  6. Google Drive link to video (Optional, but useful)

LinasKo avatar Jul 12 '24 09:07 LinasKo

Test on videos of #1345:

  1. What video format did you use? mp4
  2. Did it play successfully? Yes
  3. Did the playback start from the beginning, or did it skip some frames? Started frrom the beginning
  4. Did you have to wait before it started? No
  5. Did it reach the end? Yes
  6. Google Drive link to video: See videos in https://github.com/roboflow/supervision/issues/1345

LinasKo avatar Jul 12 '24 09:07 LinasKo

Hi @LinasKo, one question off the topic. How do you generate this pip of the branch(Step 1) that you are currently working on to install it on the Colab notebook? I am working on some other project and I wanted to test it on Colab soo...

Bhavay-2001 avatar Jul 15 '24 10:07 Bhavay-2001

Here's how we do it: !pip install git+https://github.com/roboflow/supervision.git@fix/no-frames-generated-for-some-videos

You may also find it at the very bottom of the cheatsheet

Does that answer your question?

LinasKo avatar Jul 15 '24 10:07 LinasKo

@LinasKo Just one comment, this will make skipping large amounts of frames really slow.

SkalskiP avatar Aug 07 '24 11:08 SkalskiP

@Piotr, requesting your review. Confirming that it was terribly slow. Seeking through 1 hour of a movie took 18 sec. This PR now avoids calling video.set(cv2.CAP_PROP_POS_FRAMES, ...) when not necessary and adds a param to enable manual seeking mode. I couldn't get the video mentioned in the Colab to work otherwise.

Colab: https://colab.research.google.com/drive/1MGoj7Imgen9zYnMqzGDcP20hRmK76DNr?usp=sharing

LinasKo avatar Aug 13 '24 13:08 LinasKo