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

video: Add support for playing F4V (MP4) files #14655

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

torokati44
Copy link
Member

@torokati44 torokati44 commented Jan 8, 2024

Similar to the somewhat related #14654, this is in a really early stage.

TODOs:

  • Don't hardcode track index
  • Precompute and store all frame ("sample" in MP4 lingo) offsets and lengths for all tracks?
  • Handle audio
  • Handle all supported video codecs
  • Seeking
  • Consider whether mp4 would be a better fit than mp4parse
    • Not really: It's larger (according to crates.io, and it includes writing as well as reading), and is really geared towards working with files on disk - unlike mp4parse, which is made for a really similar use case in Firefox.
  • How about Symphonia?
    • Nope, sadly it won't even give me the codec type or extradata of video tracks.
  • Resolve inevitable conflicts with Progressive download of video files #14647
  • Consider adding the ability to play MP4 files directly (as is on https://z0r.de/3099 - WARNING: content is not nice!)
    • Out of scope for this PR. Some other kinds of files (maybe images?) could also be opened this way.
  • Cleanup and testing, as usual

video_stream,
}) = &mut write.stream_type
{
println!("frame id: {:?}, end_time: {}", frame_id, end_time);
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to now be called max_time:

let max_time = write.stream_time + dt;

println!("F4V");

let mut cursor = slice.as_cursor();
let context = mp4parse::read_mp4(&mut cursor).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is still a draft, so I don't know if it's supposed to be panic-free yet, but on http://new.weedtowonder.org/, when click the play button on the video, this caused the panic :

panicked at core/src/streams.rs:850:63:
called `Result::unwrap()` on an `Err` value: InvalidData(CheckParserStateErr)

Copy link
Contributor

Choose a reason for hiding this comment

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

Every video on that site has that same result.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this on desktop for you? Or with the extension?

Copy link
Member Author

Choose a reason for hiding this comment

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

Aand now the site seems to have changed...?

Copy link
Contributor

Choose a reason for hiding this comment

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

On web after building the extension, and I changed the site to add https. It's now https://new.weedtowonder.org/.

@danielhjacobs danielhjacobs added the waiting-on-author Waiting on the PR author to make the requested changes label Mar 5, 2024
@torokati44 torokati44 force-pushed the f4v-video branch 2 times, most recently from de945d1 to 78c9928 Compare March 8, 2024 00:13
@torokati44
Copy link
Member Author

torokati44 commented Mar 8, 2024

Just found a cool web based MP4 dissector tool: https://gpac.github.io/mp4box.js/test/filereader.html
EDIT: This might also be useful: https://mpeggroup.github.io/FileFormatConformance/

@danielhjacobs
Copy link
Contributor

danielhjacobs commented Apr 1, 2024

Also note, this time testing with the attached files and a directory named mp4-1200 containing the files from https://github.com/danielhjacobs/danielhjacobs.github.io/tree/main/mp4-1200, I get this error when opening anastasia2017-teacher.swf with a Desktop app built from this PR and clicking one of the videos:

panicked at core/src/streams.rs:1384:26:
called `Result::unwrap()` on an `Err` value: DecoderError(DecoderError(MiddleOfBitstream))

anastasia.zip

@danielhjacobs
Copy link
Contributor

danielhjacobs commented Apr 1, 2024

Replacing https://github.com/ruffle-rs/ruffle/pull/14655/files#diff-894b995744e59b9d8803f92eb6b185191b9018cd571feeaeb4a7c53dbd9a0bc5R1380-R1385 with this removes the panic:

                match context.video.decode_video_stream_frame(
                    video_handle,
                    encoded_frame,
                    context.renderer,
                ) {
                    Ok(bitmap) => {
                        write.last_decoded_bitmap = Some(bitmap);
                    }
                    Err(e) => {
                        tracing::error!(
                            "Decoding video frame {} failed: {}",
                            frame_id.unwrap(),
                            e
                        );
                        return;
                    }
                }

But that doesn't fix the underlying issue, as then there is the message ruffle_core::streams: Decoding video frame 0 failed: Decoder error and the video won't open in browser anymore as a workaround as it attempts to be decoded (and fails).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
video waiting-on-author Waiting on the PR author to make the requested changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants