go-flutter-desktop / go-flutter

Flutter on Windows, MacOS and Linux - based on Flutter Embedding, Go and GLFW.
https://hover.build/
BSD 3-Clause "New" or "Revised" License
5.85k stars 283 forks source link

Plugin for flutter.io/videoPlayer #134

Open chunhunghan opened 5 years ago

chunhunghan commented 5 years ago

Can we have video player plug-in for Windows?

Thank you for your amazing work.

Flutter version

Flutter 1.5.4-hotfix.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 7a4c33425d (2 weeks ago) • 2019-04-29 11:05:24 -0700 Engine • revision 52c7a1e849 Tools • Dart 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

Go.mod file

module C:\go-flutter-master\example\test_template/desktop

go 1.12

require ( github.com/go-flutter-desktop/go-flutter v0.16.0 github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 // indirect github.com/pkg/errors v0.8.1 github.com/stretchr/objx v0.2.0 // indirect )

pchampio commented 5 years ago

Yes WE can, but work needs to be made on: #102 #103. Once those issues are resolved we could implement the plugin

pchampio commented 5 years ago

Progress on #102 has been made. The Texture api is in beta release (use hover run -b '@beta' to test it)

The texture_tutorial has been updated with a video example.

What is left to do is to align ourself with the way the flutter.io/videoPlayer do things

pchampio commented 5 years ago

Looking for maintainer: A first implementation is available at: https://github.com/go-flutter-desktop/plugins/tree/master/video_player A partial rewrite needs to be done, more info in the video_player's readme.

j4qfrost commented 4 years ago

I've reimplemented the backend logic using gocv here https://github.com/Knights-of-the-Functional-Calculus/gfd-plugins/blob/master/video_player/cv.go

It's still showing memory leaks. I can't find any place where it might be leaking in my implementation nor in the flutter go embedder. Is there anyway we can renew interest in this subject? I'm not particularly great at leak hunting myself.

Edit: One thing I forgot to mention is that memstat appears to say that the leak isn't happening on the golang side, and I've made sure that my Mats are closed after usage. This could point to a leak in the flutter texture implementation, but I don't see it.

pchampio commented 4 years ago

@j4qfrost I'll take a look at this once I have more time. It's awesome to see someone working on this subject!

j4qfrost commented 4 years ago

Bump. Is there anything I can do to get better at tracking down the leaks?

pchampio commented 4 years ago

I don't time at the moment, I'm very sorry but I can't help. To track the memory leaks we can use valgrind, but it will interfere with the C-based engine.

lmx01 commented 4 years ago

I use this in Mac.But I got error like these:

(This is taking an unexpectedly long time.) ⢿go-flutter/plugins/video_player WARNING MethodCall to ' setLooping ' isn't supported by the Golang video_player

Can U help me?Thanks.

j4qfrost commented 4 years ago

Edit: This isn't it. Handled here: https://github.com/go-flutter-desktop/go-flutter/blob/f67b5ecc81024ff9adb9abe5d06d2667e6130007/texture-registry.go#L91

@pchampio I think I may have found a solution. I'm ashamed I hadn't thought of it earlier. The guys over at flutter-rs got around to fixing the memory leak issue by calling the destruction_callback https://github.com/flutter-rs/flutter-rs/blob/696d4b1ecce501e061523d01d8476280f88f3d2e/flutter-engine/src/texture_registry.rs#L122. The downside to this is that I ran into high CPU usage. I am not sure if that's due to the constant frequent destruction, but that's the only thing I can think of.

I'll see if I can get something working.

pchampio commented 4 years ago

@j4qfrost I'm not sure why they call this callback manually. ALSO, I've removed this the destruction_callback from go-flutter because it wasn't working, and I didn't really know what to do with it.. Seeing flutter-rs manually collecting the frame does indicate that I missed something. Here is the destruction_callback commit: https://github.com/go-flutter-desktop/go-flutter/pull/217/commits/3f8aa3a95ad7fa4eeaf3294fd230ad92028ce6c3#diff-be67eb30388f811db5d0770a2f2c0a8aR138-R141 With this, I'll have more pointer to easily help us^^

j4qfrost commented 4 years ago

I'm not quite sure either. Maybe it's because The allocation for an OpenGL texture happens first and this is to ensure that the texture gets destroyed in case registering on the engine doesn't take place.

What I seem to be observing with the memory leak seems to be in line with some framebuffer not clearing. When I ran the video player examples under flutter-rs some months ago, I didn't have the same memory leak issues, but I did have insane CPU usage, and after looking at it for a bit I think the reason is that at each interval, the actually replace the texture handler rather than push in a new PixelBuffer, https://github.com/flutter-rs/flutter-video-plugin/blob/99b6133b8cdee38432d45c762c12318818ff1ad7/src/video.rs#L116

post_rgba calls post_internal which calls destruction_callback which calls glDeleteTextures, and this happens each time there's a new frame.

I'll reach out to the flutter-rs guys tomorrow and ask about this. Last I checked their development has slowed. csnewman is still working on it.

pchampio commented 4 years ago

last time I checked flutter-rs I saw those 2 commits:

The high CPU usage might of come from their event loop, not their texture ABI.

On the go-flutter side we are still in the process of merging: https://github.com/go-flutter-desktop/go-flutter/pull/390 and the way we handle tasks differ from flutter-rs. I thinks we shouldn't encounter the same high CPU usage.

pchampio commented 4 years ago

Quoting from csnewman (gitter.im):

I've managed to track down the poor performance issues, they were being caused by the render_task_runner, with this unset (we can implement a proper runner at some point), we now have equal performance to the other platforms. This should improve video playback and the likes

j4qfrost commented 4 years ago

So it would be fine to throw away the texture at each redraw? I'm also kind of confused about what the purpose of the destruction_callback is. Is it actually called within the flutter api if it gets set or is it just there for convenience?

pchampio commented 4 years ago

Looking a bit deeper at the flutter-rs code, it seems they are Creating a new texture on every new frame. This isn't what we do, we are reusing the same texture, instead of creating/deleting on each frame.

FWI: the go-flutter implementation was based of https://github.com/flutter/engine/pull/9822

pchampio commented 4 years ago

Also another FWI, @befovy has started to port his video player to go-flutter, I think he stop because of https://github.com/go-flutter-desktop/go-flutter/issues/311

https://github.com/befovy/fijkplayer

j4qfrost commented 4 years ago

Yeah, I recognized that go-flutter and flutter-rs differed in that respect. I was considering deleting the texture at each frame to see if that solved the memory leak but wasn't quite sure how to do that, so I held off until I got a response.

I actually was able to somewhat successfully use webcloudrtc's branch, but I stopped when I realized how much of a pain working with Makefiles would be moving forward. By then I had a stuttering demo working, and it was also a pain to keep my flutter install at the right version for everything to work correctly.

j4qfrost commented 4 years ago

Also forgot to mention that I can't use valgrind on my machine due to some paging issues with mac. I haven't gotten my linux machine set up yet.

pchampio commented 4 years ago

Even if you use valgrind, it's going to fail. Since the engine is written itself in C, the output will just be a bunch of unrelated mess.

MattNguyen commented 4 years ago

We began our own ffmpeg-based implementation as we needed to get video and audio to work:

https://github.com/telefuel/video_player_testbed

Currently we’re stuck on getting the audio and video to sync, most likely the result of some missing ffmpeg incantations or worst case some compatibility issues with the hardware.

We also have an open bounty to get this resolved.

@pchampio @j4qfrost any thoughts on our implementation?

Having a functioning video/audio player is critical for us and other applications. We’d be happy to support this effort.

Cc @kiasaki

pchampio commented 4 years ago

@MattNguyen this is so cool! I've quickly glance through you implementation, it's much more cleaner than what I've previously done.

I'm always surprised on how the community is using go-flutter :heart:

I currently don't have much time to work on such plugin, I respect the time and money you put into this. (But, I'll also like to point-out that other embedder exist. And in the future, they'll certainly have a working video_player plugin.)

hamidabdulmalik commented 3 years ago

@MattNguyen Where are we on this Video Player thing man. Anything new yet?

MattNguyen commented 3 years ago

@MattNguyen Where are we on this Video Player thing man. Anything new yet?

We've since moved on from the project, and was unable to progress on the video player. The issue is certainly related to some ffmpeg incantations that we're not familiar with. Hopefully someone can take over the work and solve the issue.

ablockhead commented 3 years ago

我打包出的 windows桌面应用字体有点问题 请问我如何修复它

Leadrive commented 3 years ago

@ablockhead 能贴个windows的例子吗?正在弄这个,我还没搞通。

Leadrive commented 3 years ago

the flutter video_player plugin change a lot. this version does not run with it. Please update.

I use the version v0.10.9+2 to test in Windows 10, only the tests-sample.mp4(https://github.com/3d0c/gmf/blob/master/examples/tests-sample.mp4) can play, the other mp4 report Resource temporarily unavailable error.

Leadrive commented 3 years ago

https://github.com/flutter/engine/pull/20714 https://github.com/flutter/engine/pull/19405 maybe the texture supported on Windows and Linux.

pchampio commented 3 years ago

@Leadrive this is related to the official linux embedder. GoFlutter is another implementation of the flutter embedding API (read our readme if you are lost). Differences between both project are listed here: https://github.com/go-flutter-desktop/go-flutter/issues/191#issuecomment-511384007

The PR you referenced above have nothing to do with go-flutter.

In this un-official implementation, we have merge texture back in Aug 2019 in https://github.com/go-flutter-desktop/go-flutter/pull/217

We need contributor to implement our go-flutter compatible version of the videoPlayer. Some work has already been done: https://github.com/telefuel/video_player_testbed

https://github.com/go-flutter-desktop/examples/tree/master/texture_tutorial