From c23097132c81e61f9903dd951f98f3dc62b7ab4e Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 7 Oct 2024 18:20:15 +0200 Subject: [PATCH] Fix video spinner sometimes showing at the end of videos (#7622) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What * Closes https://github.com/rerun-io/rerun/issues/7570 I'm starting to lean more towards @Wumpf view that we should try to unify the native and web decoders to reduce code duplication… I think I'll tackle that next. ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7622?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7622?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/7622) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`. --- .../viewer/re_renderer/src/video/decoder/native_av1.rs | 1 + crates/viewer/re_renderer/src/video/decoder/web.rs | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/viewer/re_renderer/src/video/decoder/native_av1.rs b/crates/viewer/re_renderer/src/video/decoder/native_av1.rs index 66f12c2ecefe..691f6593e044 100644 --- a/crates/viewer/re_renderer/src/video/decoder/native_av1.rs +++ b/crates/viewer/re_renderer/src/video/decoder/native_av1.rs @@ -132,6 +132,7 @@ impl VideoDecoder for Av1VideoDecoder { return Err(DecodingError::NegativeTimestamp); } let presentation_timestamp = Time::from_secs(presentation_timestamp_s, self.data.timescale); + let presentation_timestamp = presentation_timestamp.min(self.data.duration); // Don't seek past the end of the video. let Some(requested_segment_idx) = latest_at_idx( &self.data.segments, diff --git a/crates/viewer/re_renderer/src/video/decoder/web.rs b/crates/viewer/re_renderer/src/video/decoder/web.rs index c2bba355cf54..a4a4d5537b04 100644 --- a/crates/viewer/re_renderer/src/video/decoder/web.rs +++ b/crates/viewer/re_renderer/src/video/decoder/web.rs @@ -192,6 +192,8 @@ impl WebVideoDecoder { return Err(DecodingError::NegativeTimestamp); } let presentation_timestamp = Time::from_secs(presentation_timestamp_s, self.data.timescale); + let presentation_timestamp = presentation_timestamp.min(self.data.duration); // Don't seek past the end of the video. + self.enqueue_requested_segments(presentation_timestamp)?; self.try_present_frame(presentation_timestamp) } @@ -304,8 +306,6 @@ impl WebVideoDecoder { let mut decoder_output = self.decoder_output.lock(); - let timescale = self.data.timescale; - let frames = &mut decoder_output.frames; let Some(frame_idx) = latest_at_idx( @@ -346,13 +346,10 @@ impl WebVideoDecoder { let frame_idx = 0; let frame = &frames[frame_idx]; - let frame_timestamp_ms = frame.composition_timestamp.into_millis(timescale); - let frame_duration_ms = frame.duration.into_millis(timescale); - // This handles the case when we have a buffered frame that's older than the requested timestamp. // We don't want to show this frame to the user, because it's not actually the one they requested, // so instead return the last decoded frame. - if presentation_timestamp.into_millis(timescale) - frame_timestamp_ms > frame_duration_ms { + if presentation_timestamp - frame.composition_timestamp > frame.duration { return Ok(VideoFrameTexture::Pending(self.texture.clone())); }