supervision
supervision copied to clipboard
Change how frames are skipped in the generator
❗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:
- Videos in
supervision.assets - ~~Videos in #1345~~ Already tested.
- 5 videos from different online sources, ideally with different video formats.
- 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:
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:
- Install the library
pip install git+https://github.com/roboflow/supervision.git@fix/no-frames-generated-for-some-videos
- 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:
- What video format did you use?
- Did it play successfully?
- Did the playback start from the beginning, or did it skip some frames?
- Did you have to wait before it started?
- Did it reach the end?
- Google Drive link to video (Optional, but useful)
Test on videos of #1345:
- What video format did you use? mp4
- Did it play successfully? Yes
- Did the playback start from the beginning, or did it skip some frames? Started frrom the beginning
- Did you have to wait before it started? No
- Did it reach the end? Yes
- Google Drive link to video: See videos in https://github.com/roboflow/supervision/issues/1345
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...
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 Just one comment, this will make skipping large amounts of frames really slow.
@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