Skip to content

Add the video reader and the video extra - #12

Draft
C-Achard wants to merge 8 commits into
cy/io-fingerprintsfrom
cy/io-video
Draft

C-Achard wants to merge 8 commits into
cy/io-fingerprintsfrom
cy/io-video

Conversation

@C-Achard

Copy link
Copy Markdown
Member

OpenCV canonical video reader first version, new optional video extra.

  • Only a format's given module imports its library. Video is not re-exported from dlccore.io, so OpenCV loads only with dlccore.io.video.

CI

  • The test, weekly and wheel jobs install .[all].

Note: The comparison with DeepLabCut's VideoReader skips when DeepLabCut is not installed, which is the case in CI.

@C-Achard C-Achard added io: video Video reading consumer: deeplabcut Needed by or affects DeepLabCut CI Related to CI/CD jobs and automated testing labels Nov 24, 2026
@C-Achard C-Achard self-assigned this Nov 24, 2026
@C-Achard
C-Achard added this pull request to stack #18 November 24, 2026 16:24
@C-Achard
C-Achard marked this pull request as draft November 24, 2026 16:25

@deruyter92 deruyter92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful to have the canonical video reader in dlccore.

Should it replace VideoReader in DLC as soon as this package becomes public? Or do you foresee difficulties?

Also, did we follow up on the integration possibilities with the FI team, who were also working on something similar?

Comment thread pyproject.toml Resolved
Comment thread dlccore/io/video.py Resolved
Comment thread dlccore/io/video.py Resolved
Comment thread dlccore/io/video.py
if not self._stream.isOpened():
raise OSError("Video could not be opened.")

self._n_frames = int(self._stream.get(cv2.CAP_PROP_FRAME_COUNT))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently it is risky to trust CAP_PROP_FRAME_COUNT (which is an estimate), because, read_frame can then refuse valid frames, or raise "Could not read frame" near the end.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it a bit clearer, not sure what would be best save for decoding the whole video as fallback

Comment thread dlccore/io/video.py

ind = max(0, min(ind, len(self) - 1))
if ind != self._pos:
ok = self._stream.set(cv2.CAP_PROP_POS_FRAMES, ind)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CAP_PROP_POS_FRAMES could land on the nearest keyframe for some codecs. Only mp4v is tested.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an H264 test

@deruyter92

Copy link
Copy Markdown
Collaborator

One additional comment about rotated videos, maybe you were already aware:

Apparently OpenCV 4.11 and OpenCV 5 can return the same rotated video in different orientations. Probably worth to set cv2.CAP_PROP_ORIENTATION_AUTO explicitly. And let's make sure that the behavior in DLC does not change when we switch the videoreader.

- Rename the package to dlccore.io and add the dlccore license header
- Add the optional `video` extra (opencv-python-headless>=5) and an `all`
  extra listing every extra; dlccore.io does not re-export Video, so
  OpenCV loads only with dlccore.io.video
- test_video skips without OpenCV, and its DeepLabCut comparison skips
  without DeepLabCut
- CI installs .[all] for the test, weekly and wheel jobs; the
  dependency-floor job stays on the core install so numpy's floor stays
  tested
Raise FileNotFoundError for invalid paths and include video paths and frame indices in decoding errors. Clarify reported frame-count limitations and update error tests.
Enable OpenCV's automatic rotation and report unsupported rotation metadata. Expand video tests to cover rotated frames and H.264, and install video dependencies in the lowest-version CI job.
Add Video.frames(start) and iterator support to yield RGB frames until the decoder ends, regardless of reported frame counts. Validate start bounds and cover iteration order, seeking, and inaccurate counts with tests.
Mark stream position unknown after failed reads, grabs, or seeks so subsequent access seeks instead of decoding from stale state. Add a damaged-video regression test.
@C-Achard
C-Achard removed this pull request from stack #18 November 30, 2026 15:16
@C-Achard
C-Achard added this pull request to stack #42 November 30, 2026 15:16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Related to CI/CD jobs and automated testing consumer: deeplabcut Needed by or affects DeepLabCut io: video Video reading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants