Skip to content

Enable VideoStream H264 on the web#10189

Merged
Wumpf merged 11 commits into
mainfrom
andreas/video/web-stream-playback
Jun 12, 2025
Merged

Enable VideoStream H264 on the web#10189
Wumpf merged 11 commits into
mainfrom
andreas/video/web-stream-playback

Conversation

@Wumpf
Copy link
Copy Markdown
Member

@Wumpf Wumpf commented Jun 10, 2025

Related

What

In order to enable streaming on the web we have to extract a fully qualified codec descriptor string, as specified by the webcodecs codec registry

Doing so means that we have to even deeper inspect the video bistream and extract this information on-the-fly.
Setting the stage:

  • for mp4, this information is readily available as part of the STDS box which in turn for HEVC/AVC contains the AVCC box
    • presence of AVCC box implies that the bitstream is in AVCC (also known as HVCC for HEVC, but essentially the same) rather than Annex B
      • WebCodec can handle both, phew!
  • we already startd doing some inspection of the bitstream, namely we extract group-of-pictures (GOP)
    • for AVC/h264 every GOP starting sample (== is_sync) is required to contain an IDR frame AND an Sequence Parameter Set (SPS)
    • SPS is sufficient for getting the codec string and has other juicy information we'd like to have around!

Therefore, this PR:

  • ...further evolves VideoDataDescription to not be as little reliant on AVCC, splitting out the optional VideoEncodingDetails (Q: better name? it's not like we're encoding something, it's more like some loosy goose information on what got encoded how)
  • ...enhances GOP detection to produce VideoEncodingDetails
    • a side effect is that we have now more powerful parsing for VideoEncodingDetails and have more things available more often \o/. Let's make use of that in to-be-added ui!
  • ...resets decoders whenever VideoEncodingDetails changes
    • we regard changes to VideoEncodingDetails over time as a bug and will always use the latest found VideoEncodingDetails

All this causes some shuffling around. The fact that I changed namespaces a bit didn't help either, but the arbitrary split between decode and demux didn't age well. I'll clean this up further in a follow-up.


Sideffect, more information from MP4 with H.264:

Before:
image

After:
image

@Wumpf Wumpf added 🕸️ web regarding running the viewer in a browser 📺 re_viewer affects re_viewer itself include in changelog feat-video anything video decoding, player, querying, data modelling of videos etc. labels Jun 10, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 10, 2025

Web viewer built successfully. If applicable, you should also test it:

  • I have tested the web viewer
Result Commit Link Manifest
56c0622 https://rerun.io/viewer/pr/10189 +nightly +main

Note: This comment is updated whenever you push a commit.

@Wumpf Wumpf requested a review from emilk June 10, 2025 14:35
// TODO(#10184): Add support for AV1.
//AV1,

/// VP8
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.

don't think it makes sense to support VP8, which is why it didn't get a ticket

on_output: Arc<Mutex<Option<Arc<OutputCallback>>>>,
}

fn try_get_sps_from_avcc(avcc: &re_mp4::Avc1Box, debug_name: &str) -> Option<sps::SeqParameterSet> {
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.

no need to look at the avcc in detail here anymore - we do so now agnostically by having a look at the new VideoEncodingDetails

Comment on lines +42 to +43
/// The sample is the start of a GOP and encoding details have been extracted.
StartOfGop(VideoEncodingDetails),
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.

in theory we can also detect a gop start but fail to extract those details. Went there at first but got needlessly complex for what effectively has to be a broken gop

if reader.nal_handler_ref().detected_gop() {
return true;
// In case of SPS parsing failure keep going.
// It's unlikely, but maybe there's another SPS in the chunk that succeeds parsing.
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.

... tbh I don't even now what that means if that would happen. But with everything video I generously assume everything can happen...

let result = detect_h264_annexb_gop(sample_data);
assert_eq!(
result,
Ok(GopStartDetection::StartOfGop(VideoEncodingDetails {
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.

the fact that this above ai generated bytes actually generated something we can parse makes me really curious about that IDR frame in there 😆

Comment thread crates/utils/re_video/src/demux/mod.rs Outdated
Yuv420,

/// No subsampling at all, since the format is monochrome.
Monochrome,
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.

merging monochrome into the ChromaSubsamplingModes made a bunch more things saner!

pub coded_dimensions: Option<[u16; 2]>,
/// Various information about how the video was encoded.
///
/// Should any of this change during the lifetime of a decoder, it has to be reset.
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.

another piece of loose contract on the mutability of VideoDataDescription. Makes me rather uneasy, but it's workable

/// Returns the subsampling mode of the video.
///
/// Returns None if not detected or unknown.
pub fn subsampling_mode(&self) -> Option<ChromaSubsamplingModes> {
Copy link
Copy Markdown
Member Author

@Wumpf Wumpf Jun 10, 2025

Choose a reason for hiding this comment

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

this parsing code moved into mp4.rs where it belongs

Copy link
Copy Markdown
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Great!

Comment thread crates/utils/re_video/src/demux/mod.rs Outdated
Comment thread crates/utils/re_video/src/demux/mod.rs Outdated
Comment thread crates/utils/re_video/src/demux/mp4.rs Outdated
@Wumpf Wumpf merged commit bef4689 into main Jun 12, 2025
41 checks passed
@Wumpf Wumpf deleted the andreas/video/web-stream-playback branch June 12, 2025 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat-video anything video decoding, player, querying, data modelling of videos etc. include in changelog 📺 re_viewer affects re_viewer itself 🕸️ web regarding running the viewer in a browser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants