AllenDang / giu

Cross platform rapid GUI framework for golang based on Dear ImGui.
MIT License
2.35k stars 135 forks source link

Play a video #239

Closed NetForces closed 3 years ago

NetForces commented 3 years ago

Is there a way to play a video within an app build with gui ?

I know it's possible to pass mplayer the ID of a window with the -wid switch:

       -wid <window ID> (also see -gui-wid) (X11, OpenGL and DirectX only)
              This tells MPlayer to attach to an existing window.  Useful to embed MPlayer in a browser (e.g. the plugger extension).  This option fills the given window completely, thus aspect scaling, panscan, etc are no longer handled by MPlayer  but  must
              be managed by the application that created the window.

I have done this in the past in Windows with AutoIT and would like to do something similar for Linux with Go and gui...

Thanks.

AllenDang commented 3 years ago

@NetForces I didn't give a try to embed a video player, but I think it should work if we could get the window ID for master window, problem is this is platform dependent, I think the proper solution is to integrate with some video lib like libvlc-go. But currenlty I may not have enough time to do that...

AllenDang commented 3 years ago

@NetForces A second thought just came out. You could decode the video with ffmpeg, convert video frame to rgba image and display it at certain framerate like 24 fps.

NetForces commented 3 years ago

FYI just tried it and it works. I used wmctrl to grab the window ID and pass it to mplayer. Indeed it's platform dependent but for me it will do.

Now follow-up question, if I have an image defined by canvas.AddImage is there a way to bring it back to the top layer ?

24fps is too slow for my usecase.

AllenDang commented 3 years ago

@NetForces Just draw image after video frame is rendered. I don't quite sure this will work, maybe mplayer occupies whole event processing of the master window.

NetForces commented 3 years ago

Yeah I'll give it a try. I thought the -wid with mplayer worked but as soon as I move the mouse the screen flickers between the video and the main window...

gucio321 commented 3 years ago

Lets note: https://github.com/ocornut/imgui/issues/2422

NetForces commented 3 years ago

We can close this. I am using mplayer in slave mode and it works for my usecase.