Skip to content

core: Add support for playing F4V (MP4) files#24038

Draft
torokati44 wants to merge 5 commits into
ruffle-rs:masterfrom
torokati44:f4v-video-re_mp4
Draft

core: Add support for playing F4V (MP4) files#24038
torokati44 wants to merge 5 commits into
ruffle-rs:masterfrom
torokati44:f4v-video-re_mp4

Conversation

@torokati44

Copy link
Copy Markdown
Member

Description

Take 2 of #14655, superseding it.

Compared to that, this relies on re_mp4 (by the awesome Rerun.io team, who are also the main sponsors of egui), not on Mozilla's mp4parse crate. The former is more actively maintained, while the latter hasn't seen a real "release" in years, so we'd have to use it from a git source.
It is also a lot nicer in that it directly gives us the "sample" (in MP4 lingo, it's an encoded video frame or audio chunk) offsets and lengths directly, so we don't have to calculate them in convoluted ways from the moov box.
One downside is that it doesn't provide a BoxIter mechanism, so we'd have to either contribute it, or manually pass in only complete boxes when streaming from a remote file, otherwise the parser errors out. I think an entirely missing mdat box would be tolerated though, just not a truncated one. This is one of the TODOs left.

This one also adds audio (AAC only) decoding!

Also includes #23985, which was motivated by this.

Now that streams.rs has grown a bit lengthy, in the future it might be worth it to refactor it into a "directory module", with the FLV and MP4 parts in separate submodules.

Testing

There's a basic test included.
#19531 isn't fixed by this alone, at least on desktop - there's a weird H.264 NALU encapsulation artifact in one of the files it plays, which is apparently accepted by WebCodecs but not by OpenH264. Fixing it is out of scope, unrelated to the MP4 format itself.
There's also something fishy on WeedToWonder.org last time I tested (frames not passed in for the video decoder in the right order, or key frames being missed?) - hence why this is also still a draft.

Checklist

  • I, a human, have self-reviewed this PR and fully understand the changes within.
  • I have made or updated tests where possible.
  • All of my commits are properly scoped, compile successfully, and pass all tests.
  • This PR does not make sense to split up into smaller PRs.
  • An LLM was involved in the authoring of this code.

@torokati44 torokati44 added A-video T-fix Type: Bug fix (in something that's supposed to work already) labels Jun 22, 2026
Instead, demux AudioSpecificConfig out-of-band, simplifying the decoder.

Add `extra_data: Option<Box<[u8]>>` to `SoundStreamInfo` to carry
codec-specific init data out-of-band. The FLV handler now stores AAC
sequence headers (AudioSpecificConfig) there instead of appending them
to the audio substream, and strips the leading packet-type byte from
AAC payloads since the enum variant already encodes that distinction.

AacSubstreamDecoder reads the config at construction time via
`codec_params.with_extra_data`, removing the mid-stream packet-type
dispatch that was previously in its decode loop.
@danielhjacobs

Copy link
Copy Markdown
Contributor

There's also something fishy on WeedToWonder.org last time I tested

Note for the curious, this is specifically: https://new.weedtowonder.org/ (more specifically, *.weedtowonder.org used to be this site, while the current https://weedtowonder.org/ used to only be accessible on https://old.weedtowonder.org/, but that was changed when it was found https://old.weedtowonder.org/ would work with Ruffle while, for the time being, https://new.weedtowonder.org/ was broken with Ruffle)

@torokati44

Copy link
Copy Markdown
Member Author

Do you have a simple way I could test some representative content from that site with the desktop player? Building and loading the extension after each change is a bit cumbersome.

@torokati44

Copy link
Copy Markdown
Member Author

Also, what exactly is different between the old. and new. sites?

@torokati44

Copy link
Copy Markdown
Member Author

(For testing: I guess just cargo run -- 'https://new.weedtowonder.org/w2w-home.swf' should work, as there's already an MP4 video there.)

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

Labels

A-video T-fix Type: Bug fix (in something that's supposed to work already)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants