Skip to content

[Enhance] Calculate and adjust FPS for video output to maintain origi… #2907

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

haysho2260
Copy link

Match output video duration to original duration

Motivation

The current spatial-temporal action detection demo script in MMAction2 outputs a video with a fixed frame rate (default 6 FPS) without ensuring that the output video duration matches the original input video. This often leads to shorter (or longer) output videos that are temporally misaligned with the input, which is especially problematic when trying to:

  • Visually compare annotated results side-by-side with the original video.
  • Ensure alignment for downstream evaluations or presentations.

This PR ensures the output video duration remains consistent with the original video by adapting either the frame sampling or the FPS accordingly.


Modification

  • Added logic to:

    • Extract the original video’s frame rate and duration using OpenCV.
    • Calculate the desired number of frames based on the requested output FPS.
    • If there are too many frames, downsample them to preserve the original duration.
    • If too few frames, adjust the FPS proportionally to match the duration.
  • Inserted this logic before video saving with moviepy.

  • The change is minimally invasive and does not affect any core inference functionality.


BC-breaking (Optional)

No, this PR is not backward compatibility breaking.
It only affects the video output format of the demo script, and improves its correctness.


Use cases (Optional)

  • Users visualizing detection results will now get a video that matches the duration of the original input.
  • Supports more accurate comparisons and synchronizations between input and output.
  • Optional future improvement: this behavior could be made toggleable via a CLI flag.

Checklist

  • Pre-commit or other linting tools used.
  • Unit tests not applicable to demo scripts, but manual verification was performed.
  • This PR has no downstream breakage.
  • Docstring comments included where relevant.

@CLAassistant
Copy link

CLAassistant commented May 30, 2025

CLA assistant check
All committers have signed the CLA.

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

Successfully merging this pull request may close these issues.

3 participants