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

Fix some videos having offsetted (incorrect) timestamps #8029

Merged
merged 14 commits into from
Nov 8, 2024

Conversation

Wumpf
Copy link
Member

@Wumpf Wumpf commented Nov 7, 2024

What

.. and adds a few more "expert" information fields to video blob plus improving the selection panel view overall a bit

Before:
image

After:
image

-> note how the timestamp component and the timestamped etched into the video are now the same.

The problem is that in the presence of B-frames it can happen that presentation timestamps don't start at 0. This is because in MP4 (and other formats?) timestamps can't be negative and the first timestamp may have a decode timestamp of zero but a presentation timestamp some point later. Turns out this happens in a bunch of the example video material I'm using - not too surprising given that ffmpeg's default encoding settings on h264 tend to produce this!
From what I found (see links in comments) this is compensated by players. We do so now on the fly in key locations, preserving the internal PTS/DTS values of the samples. I tried to sharpen the docs where appropriate.

(on a personal note: I don't quite fully follow yet how this makes sense practically given that the first frame should be an IDR frame (it is, right?). But that's 100% what's happening and I found strong indication that players compensate for this just like we do here now)

Checklist

  • I have read and agree to Contributor Guide and the Code of Conduct
  • I've included a screenshot or gif (if applicable)
  • I have tested the web demo (if applicable):
  • The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG
  • If applicable, add a new check to the release checklist!
  • If have noted any breaking changes to the log API in CHANGELOG.md and the migration guide

To run all checks from main, comment on the PR with @rerun-bot full-check.

@Wumpf Wumpf added 🪳 bug Something isn't working 📺 re_viewer affects re_viewer itself include in changelog 🎞️ video labels Nov 7, 2024
@Wumpf Wumpf changed the title Fix some videos having offseted timestamps Fix some videos having offseted (incorrect) timestamps Nov 7, 2024
crates/store/re_video/src/demux/mod.rs Outdated Show resolved Hide resolved
crates/viewer/re_renderer/src/video/player.rs Outdated Show resolved Hide resolved
@Wumpf
Copy link
Member Author

Wumpf commented Nov 7, 2024

tested on firefox & chrome now to have correct timestamps

@Wumpf Wumpf requested a review from emilk November 7, 2024 15:31
@Wumpf Wumpf added the do-not-merge Do not merge this PR label Nov 7, 2024
@Wumpf
Copy link
Member Author

Wumpf commented Nov 7, 2024

just noticed a bug here
image

@Wumpf
Copy link
Member Author

Wumpf commented Nov 7, 2024

@Wumpf Wumpf removed the do-not-merge Do not merge this PR label Nov 7, 2024
crates/store/re_video/src/decode/webcodecs.rs Outdated Show resolved Hide resolved
crates/store/re_video/src/demux/mod.rs Outdated Show resolved Hide resolved
}

#[inline]
pub fn from_nanos(v: i64, timescale: Timescale) -> Self {
Self::from_secs(v as f64 / 1e9, timescale)
pub fn from_nanos_since_start(
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a single fn from_duration_sicne_start(duration: std::time::Duration, …) could replace all these, to produce a more minimal interface

Copy link
Member Author

Choose a reason for hiding this comment

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

still have to keep a nanos version one because std::time::Duration has imho waaaay too much overhead for converting to our VideoTimestamp (we expect to converts hundereds of thousands in some cases)

Copy link
Member Author

Choose a reason for hiding this comment

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

the other nastiness is that duration panics when using negative values.

Actually that last one compells me strongly to roll back what I did. std::time::duration is not safe when dealing with user data

crates/store/re_video/src/time.rs Show resolved Hide resolved
Comment on lines 68 to 70
/// Convert to a duration
#[inline]
pub fn duration(self, timescale: Timescale) -> std::time::Duration {
Copy link
Member

Choose a reason for hiding this comment

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

It seems like it is time to split Time into two types; one for time-points and one for durations. Both require timescale, but only one require the start_time offset.

Copy link
Member Author

Choose a reason for hiding this comment

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

let's not explode and delay this PR even further with cosmetics like that. The time type was never meant to be all that complex, it's just a typed "this is a video time that uses a video time scale"

@Wumpf
Copy link
Member Author

Wumpf commented Nov 8, 2024

Not going to follow through on std::time::Duration suggestions: It is too error prone since its constructors panic on negative values, causing us to do lots of extra checking in various places.
Also, specifically for conversion to VideoTimestamp it would be a costly detour since it uses a u128+u64 to represent its time.

@Wumpf Wumpf merged commit e59451c into main Nov 8, 2024
42 checks passed
@Wumpf Wumpf deleted the andreas/fix-video-timestamp-offset branch November 8, 2024 10:19
@Wumpf Wumpf changed the title Fix some videos having offseted (incorrect) timestamps Fix some videos having offsetted (incorrect) timestamps Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪳 bug Something isn't working include in changelog 📺 re_viewer affects re_viewer itself 🎞️ video
Projects
None yet
2 participants