-
-
Notifications
You must be signed in to change notification settings - Fork 664
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
graphics: play a movie or a video #110
Comments
I'm not sure how feasible this would be 🤔 |
MP4 Library. |
Thanks, but I think this doesn't include codecs. |
Is going ffmpeg route an option ? I've seen quite a few go bindings, but I'm afraid this would add some CGO again, idk if it's an issue |
Cgo is not an option especially for Windows, unfortunately. Another issue is that ffmpeg is LGPL and even if we had pure Go version of ffmpeg, this would conflict with Ebiten's license. |
One side note regarding CGo issues, I think some can be mitigated using WASM based bindings and pure Go WASM runtime like this one: For most C libraries which are portable, I think this approach works. |
This seems like a fine approach. Playing back a variety of formats would be ideal, but is understandably difficult to manage - it might be fine to simply create a script or tool to invoke FFMPEG on the developer's computer and convert videos to the correct format. Either this could be distributed as part of ebitengine's toolset, or simply mentioned on a wiki / knowledgebase for the developer to run as a script (like the Linux game building script).
I'm not knowledgeable on WebAssembly, so forgive me if I'm not understanding how this works, but if I understand you correctly, your idea is to compile FFMPEG into a web assembly binary (?), use wazero to run the binary, use bindings to call FFMPEG in the web assembly runtime to decode videos, and finally get that data and play the audio and display the frames? |
@SolarLune Yes, I'm not sure how different the performance will be. (The WASM runtime compiles the code to machine code, also the execution part is written in assembly, so I assume it is performant, or at least as performant as CGo) |
Hi, I added an Ebitengine example here https://github.com/gen2brain/mpeg/blob/main/examples/player-eb/main.go. There are some issues though, the audio is crackling. I tried to play the SDL example with the |
The latest Ebitengine v2.5 should mitigate the issue, but I failed
Related: #2376 |
@gen2brain I made a couple tests, and the audio issues may not be directly related to Ebitengine. I used some code to capture the audio being served by mpg, then saving it to a file at the end, and then using another Ebitengine program to play the captured audio in isolation, without video nor your mpeg package or anything... and it has the same artifacts. The capture was a simple wrapper that did only this: n, err := mpgAudioReader.Read(buffer)
rawAudio = append(rawAudio, buffer[0 : n]...) So I'd suspect something with the S16 format, or maybe Ebitengine trying to read too far ahead in advance at the start (it tends to issue two initial buffer reads) and that causing some issue with data not being yet ready (or not, haven't really checked how your audio streaming code works, and I also played around with Regarding By the way, awesome work, this is kind of a big deal for Ebitengine, so you are making a lot of people happy! |
@tinne26 Thanks, I did not know about |
Yes, sorry, just to point out this, the decoder will preallocate the memory for the audio sample, and it should be used in the callback function, i.e. write the received sample to buffer. That is usually nice and enough for many libraries. In this case, I just added a |
So, if I understand correctly, the issue is that when the callbacks are set, data should be consumed there. The fact that we are using both the audio reader directly and If that's correct, that's great, as it means both projects are working properly and we only need to figure out the best way to sync things in Ebitengine. Don't worry if you are more unfamiliar with Ebitengine, with all that info we can totally figure it out by ourselves if you need to focus on something else. |
Well, yes, the Decode() is called with the Also, just to mention, this is of course rewrite of the C library, everything is single-threaded, there are no go routines, etc. Both audio and video constantly check if there are more bits with the |
@gen2brain Do you have any suggestion about this issue? #110 (comment) |
@hajimehoshi No idea, mpeg package only uses the standard library. I get the same, I wanted to try and build a master without modules, but then the problem is v2. |
I'd avoid nested go.mod if possible. You can move the examples to other repositories or simply remove child go.mod files. Both should not break backward compatibility |
Ok, I removed modules, tidy now works, thanks! I also switched to inpututil. |
I made a small package to make it easier to manage this on Ebitengine: https://github.com/tinne26/mpegg. Still a work in progress, but it works. The key idea is to let Ebitengine handle the audio, decoding from the mpeg as much as Ebitengine requests, and then using the I can help with the standalone example for gen2brain too, but to point to the critical code in that new package:
|
@tinne26 Awesome! I could play the same video as @gen2brain's test video without noises! I found an error after finishing the video:
|
@tinne26 Feel free to modify whatever you need directly in the library. I added a lot of helper functions like |
I'll open an issue on your mpeg repository instead if that's fine with you and we can debate it there. This issue is already resolved and both mpeg and Ebitengine are doing fine, but it's true that there may be some room for improving ease of use for a couple use-cases on mpeg, and they are not related to Ebitengine itself, but rather to the "allow audio to be arbitrarily buffered and then have video catching up to a specific point in time" approach. We could make a much more compact single-file example for Ebitengine from that (or for anything else that wishes to use a similar approach). |
At least I want to create an example to play a video (probably with https://github.com/tinne26/mpegg and/or https://github.com/gen2brain/mpeg). |
@tinne26 Based on your https://github.com/tinne26/mpegg, I've created a simple example, thanks! https://github.com/hajimehoshi/ebiten/tree/main/examples/video |
No description provided.
The text was updated successfully, but these errors were encountered: