media-kit / media-kit

A cross-platform video player & audio player for Flutter & Dart.
https://github.com/media-kit/media-kit
MIT License
916 stars 132 forks source link

[Question] ARF(Automatic Frame Rate) Supported ? #315

Closed michalss closed 10 months ago

michalss commented 10 months ago

Hi, Is ARF(Automatic Frame Rate) supported please ? Mostly releated to mobile platforms..

AFR (auto frame rate) – is function which designed to match the media player's output frame rate to the original frame rate of (video) content. This applies to content that's mastered at different frame rates, for example 24fps film-based content or other international video content encoded at 60, 50, 30, 25, and 24fps.

Some more exmaplanation why is needed.. https://tvbox-app.com/en/autoframerate/ https://ugoos.com/system-auto-frame-rate-for-tv-boxes

Regards

alexmercerind commented 10 months ago

Is ARF(Automatic Frame Rate) supported?

You test & tell. We have pre-compiled demo application links in our README.

Currently, video is rendered at the FPS of the video (& not the display). Additional behavior may depend upon Flutter itself. We can pin FPS to any value from our side (not present as a feature at the moment), but still AFAIK Flutter will limit it.

sbenmeddour commented 10 months ago

You must create or use an existing plugin to change framerate.

Active display (screen) framerate can only be changed with platform specific code, and cannot be changed with low level code from mpv

Doc for android: https://developer.android.com/media/optimize/performance/frame-rate

alexmercerind commented 10 months ago

It's necessary to configure things on libmpv side as well. It will control the rate at which callback from mpv_render_context_set_update_callback gets called (& thus FPS). FYI: --override-display-fps.

On Flutter side, package:flutter_displaymode seems to be a good choice.

alexmercerind commented 10 months ago

Still, not sure how big of a difference it will make. By default, video's FPS will be used. I don't think any issue will surface.

sbenmeddour commented 10 months ago

Still, not sure how big of a difference it will make. By default, video's FPS will be used. I don't think any issue will surface.

I'm not sure (didn't tested) if video playback will be as smooth as a display with same refresh rate of video

Example: Play a video with 24.0 FPS on a 60 FPS display can show "micro stuttering"

alexmercerind commented 10 months ago

Displaying a 24 FPS video on 60 FPS display will be fine AFAIK (all video players do it the same). But displaying a video that has higher/near FPS to the display, can definitely cause tearing.

michalss commented 10 months ago

It is a huge difference, shuttering is a real thing unfortunately.. You can see it, you can see its micro stepping on the screen. I have a video file where it can be clearly see. But i cannot share it in public since it is DRM. But it is perfect candidate for test can be privately shared. Also tested with MPVnet and it works perfectly, but with flutter and media kit you can clearly see a performance issue or shuttering during the playing...

alexmercerind commented 10 months ago

Provide clear details.

It's not "performance" if the frame rate is actually being limited. What are you even saying?

My 300$ Android can play 8 videos (more if added) simultaneously without any jerks.

michalss commented 10 months ago

OK let me explain. I did some testing with video file 1920x1080 HEVC/MJPEG+AC3 and size 2.8 GB, i need to mention i worked with PC Windows so far. I know media kit is mpv based, so i made sample application in flutter, turn HW accc on and test this video file. It works, playing, but you can see is shuttering video on certain parts. So i took MPVnet and test it in there and play is very smoot and working perfectly. There must be some different with implelentation for sure since giving me different results...

alexmercerind commented 10 months ago

WHICH PLATFORM?

michalss commented 10 months ago

so far i did test only PC... Windows

alexmercerind commented 10 months ago

Microsoft Windows?

michalss commented 10 months ago

Yes. this different can be seen by eyes clearly. What i can't tell if this is coz of dart/flutter or mpv implementation..

alexmercerind commented 10 months ago

Is it this specific media?

michalss commented 10 months ago

OK her you go... take it pls i need to remove it after you got it...

michalss commented 10 months ago

you will see it clearly on the start of the media with cinematics.. its really a huge different...

michalss commented 10 months ago

i did also compared with VLC, same thing vlc,mpvnet works ok, media-kit is not

michalss commented 10 months ago

BTW i have millions of this examples if you need to. I can privately share a huge lib of all formats. They are all online..

alexmercerind commented 10 months ago

My Ryzen 3 2200U is taking around 10% CPU, this isn't a performance issue clearly.

I can't really see the difference either. If I play a higher FPS video, I feel everything is smoother, which is an indication of everything working as intended. I don't really see a problem, video is being played fine & isn't taking any redundant resources.

https://github.com/alexmercerind/flutter-windows-ANGLE-OpenGL-ES/assets/28951144/32637cc3-05e2-4918-8f68-8fa5ba343fcf

https://github.com/alexmercerind/flutter-windows-ANGLE-OpenGL-ES/assets/28951144/240ee195-5133-4848-ba58-44262e9926b8

There can be a number of things that I'd like to add:

You can subscribe to #296 for direct D3D11VA/DXVA2 rendering on Windows; if we feel the requirement. Further details are present there. That still does not guarantee any changes in experience, since there's a significant interop/syncing involved.

In your C#/.NET, if you embed a native HWND, you'd face airspace issues. This is certainly better than that.

You are free to play around with libmpv options yourself e.g. adding --override-display-fps=60 here: https://github.com/media-kit/media-kit/blob/e5ab431183c81272e0a5545fb791273d751dbd8e/media_kit_video/windows/video_output.cc#L35-L36

Let us know if you find a sweet spot, everyone will be helped.

alexmercerind commented 10 months ago

Lastly... make sure you're in release mode :)

michalss commented 10 months ago

Ok thx for test, but it is happening to me. ill send it to more ppl if they can confirm this.. Im on Rizen9 48GB Ram, but ill make another test without the external monitors...

https://github.com/media-kit/media-kit/assets/1000729/684f26ce-d91b-409d-8e29-ab4b3ceb3222

alexmercerind commented 10 months ago

You can join our Discord server (where we talk development), it'll be easier to communicate there:

michalss commented 10 months ago

Thx a lot I will...

alexmercerind commented 10 months ago

We'd need details to find out a fix. And... We're committed.