Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with sv.VideoInfo FPS Handling for Precise Video Metadata Retrieval #1687

Open
2 tasks done
joesu-angible opened this issue Nov 25, 2024 · 1 comment
Open
2 tasks done
Labels
enhancement New feature or request

Comments

@joesu-angible
Copy link

joesu-angible commented Nov 25, 2024

Search before asking

  • I have searched the Supervision issues and found no similar feature requests.

Description

Hello,

I'm using sv.VideoInfo.from_video_path to retrieve video metadata and perform video manipulations. However, I've noticed an issue with how fps is calculated. Specifically, sv.VideoInfo.from_video_path uses the following method:
fps = int(video.get(cv2.CAP_PROP_FPS))

This approach can lead to inaccuracies in certain scenarios. For example, if the actual FPS of a video is 24.999, the method will round this down to 24. Over a long video, this discrepancy can cause significant shifts and synchronization problems.

Would it be possible to modify the implementation to return the FPS as a float rather than truncating it to an integer? This would improve accuracy for edge cases like this.

Thank you for your attention!

Use case

Change the method of fps from fps = int(video.get(cv2.CAP_PROP_FPS)) to fps = float(video.get(cv2.CAP_PROP_FPS))

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@joesu-angible joesu-angible added the enhancement New feature or request label Nov 25, 2024
@LinasKo
Copy link
Contributor

LinasKo commented Nov 25, 2024

Hi @joesu-angible 👋

Thank you for reporting the issue! Indeed, half of our own asset videos don't have a round number for the fps.

Test code
import supervision as sv
from supervision.assets import VideoAssets, download_assets
import cv2

# int fps:   People walking, Market square, Skiing, Milk bottling plant, Vehicles
# float fps: Subway, Basketball, Grocery Store, Beach, Vehicles 2

asset = VideoAssets.VEHICLES_2
download_assets(asset)

video = cv2.VideoCapture(asset.value)

fps = video.get(cv2.CAP_PROP_FPS)
print(fps, type(fps))

video_info = sv.VideoInfo.from_video_path(asset.value)
print(video_info)

This would be a superb PR submission! However, since we've had the int(fps) code for a while, this issue requires looking at the wider impacts. There's multiple things to check, but I believe each of these is pretty simple:

  • Can we still use VideoSink to store a video?
  • Does ByteTrack still work if a non-int FPS is passed in? Does setting track_seconds * fps for the lost track buffer work?
  • Does speed estimation in inference_example.py work?
  • It's also used in coordinate calculation in {ultralytics,inference,yolo_nas}_example.py
  • timers.py for time in zone calculation. Used in ultralytics{_naive}_stream_example.py
  • Is FPS monitor anyhow affected? I don't think so, but it'd be worth checking.

Does that sound interesting, @joesu-angible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants