Skip to content

Implement Video Reader#356

Merged
edgarriba merged 21 commits intokornia:mainfrom
as1100k-forks:issue-257
May 18, 2025
Merged

Implement Video Reader#356
edgarriba merged 21 commits intokornia:mainfrom
as1100k-forks:issue-257

Conversation

@AS1100K
Copy link
Copy Markdown
Member

@AS1100K AS1100K commented Apr 13, 2025

Fixes #257
Fixes #113

Example

I have created a simple video player example with egui

Demo

demo.mp4

TODOs

  • Add Simple Video Player Example

@edgarriba edgarriba requested a review from Copilot April 22, 2025 10:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a new VideoReader feature to enable video playback functionality after recording from a webcam. It also updates the example code, documentation, and the underlying stream module to support video reading and playback controls.

  • Implements VideoReader with methods to start, grab, seek, set playback speed, and restart the video.
  • Updates the example application and README to demonstrate recording and reading video.
  • Adds pipeline accessors in the stream capture module to support new functionality.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
examples/video_read/src/main.rs Adds video recording and subsequent playback using VideoReader.
examples/video_read/README.md Updates usage instructions (with a noted typo) for video reading.
examples/video_read/Cargo.toml Introduces necessary workspace dependencies for video reading.
crates/kornia-io/src/stream/video.rs Implements VideoReader along with several playback control methods.
crates/kornia-io/src/stream/capture.rs Adds getters for the pipeline used in the video stream capture.

Comment thread examples/video_read/src/main.rs Outdated
Comment thread examples/video_read/README.md Outdated
Comment thread crates/kornia-io/src/stream/video.rs Outdated
@abdulrahman-riyad
Copy link
Copy Markdown

abdulrahman-riyad commented Apr 23, 2025

@AS1100K @edgarriba With all my respect and love, I think it is disrespectful for @AS1100K to work on the issue that I already made a pull request for, especially after he asked me if I am working on it, and I answered "yes, I am working on it." and I did finish it a week ago. Correct me if I am wrong, but I think it is against the rules set by the community here, or at least disrespectful.

Comment thread crates/kornia-io/src/stream/video.rs Outdated
Comment thread crates/kornia-io/src/stream/video.rs
Comment thread examples/video_player/Cargo.toml Outdated
Comment thread examples/video_player/src/lib.rs Outdated
Comment thread examples/video_player/src/lib.rs
Comment thread examples/video_player/src/lib.rs Outdated
Comment thread examples/video_player/src/lib.rs Outdated
Comment thread examples/video_player/src/lib.rs Outdated
Comment thread examples/video_player/src/lib.rs Outdated
Comment thread crates/kornia-io/src/stream/capture.rs
Comment thread crates/kornia-io/src/stream/capture.rs Outdated
Comment thread examples/video_player/Cargo.toml Outdated
Comment thread crates/kornia-io/src/stream/video.rs Outdated
Comment thread crates/kornia-io/src/stream/video.rs Outdated
Comment thread crates/kornia-io/src/stream/video.rs Outdated
Comment thread crates/kornia-io/src/stream/video.rs Outdated
Comment thread crates/kornia-io/src/stream/video.rs Outdated
Comment thread crates/kornia-io/src/stream/video.rs Outdated
Comment thread examples/video_player/src/lib.rs Outdated
Comment thread crates/kornia-io/src/stream/capture.rs Outdated
Comment thread crates/kornia-io/src/stream/capture.rs Outdated
AS1100K added 6 commits May 13, 2025 16:09
- Introduced `AppState` enum to manage video player states.
- Simplified error handling and state transitions.
- Modularized UI rendering into separate functions.
- Added `TextureStore` for efficient texture management.
- Improved image resizing logic for better performance.
Comment thread crates/kornia-io/src/stream/video.rs Outdated
@AS1100K
Copy link
Copy Markdown
Member Author

AS1100K commented May 15, 2025

@edgarriba I split the example into three functions to make it more easy to understand what's going on and have implemented AppState

Copy link
Copy Markdown
Member

@edgarriba edgarriba left a comment

Choose a reason for hiding this comment

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

LGTM. Just minor things.

Some else I notice is that when you pause the video it goes black and you cannot see the frame where you paused nor being able to seek.

If that's too much work to do, we can skip to not overcomplicate things

Comment thread crates/kornia-io/src/stream/video.rs Outdated
Comment thread crates/kornia-io/src/stream/video.rs Outdated
Comment thread crates/kornia-io/src/stream/video.rs Outdated
Comment thread examples/video_player/src/lib.rs Outdated
Comment thread examples/video_player/src/lib.rs Outdated
Comment thread crates/kornia-io/src/stream/capture.rs Outdated
@sonarqubecloud
Copy link
Copy Markdown

@AS1100K
Copy link
Copy Markdown
Member Author

AS1100K commented May 16, 2025

Some else I notice is that when you pause the video it goes black and you cannot see the frame where you paused nor being able to seek.

Done 😀


// Video is now finished
if current_pos == duration {
is_finished = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why don't you jsut set the state to finished?

}
}

if is_finished {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

check the app state

@edgarriba edgarriba merged commit 53a9ba4 into kornia:main May 18, 2025
14 checks passed
andrew-shc pushed a commit to andrew-shc/kornia-rs that referenced this pull request Aug 2, 2025
* Implement Video Reader

* Add documentation for video webcam recording example

* Remove video_read example

* Remove unnecessary arguments for pipeline

* Add more utility methods to `VideoReader`

* Add Video Player Example

* Fix docs

* Fix Flickering Issue

* Accept Suggestions

* Document get_fps method in StreamCapture

* Allocate resize image only if size changes

* Add `VideoReaderError`

* Accept Suggestions

* Refactor video player state management and rendering

- Introduced `AppState` enum to manage video player states.
- Simplified error handling and state transitions.
- Modularized UI rendering into separate functions.
- Added `TextureStore` for efficient texture management.
- Improved image resizing logic for better performance.

* Make `pipeline` field in StreamCapture public to crate

* Fix video restart logic and update image rendering dimensions

* fmt

* Accept Suggestion

* Make last frame render even when video is paused
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.

Implement VideoReader api via gstreamer Implement VideoWriter / VideoReader

4 participants