-
Notifications
You must be signed in to change notification settings - Fork 614
flet-video: add mpv_properties to VideoConfiguration #6041
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
flet-video: add mpv_properties to VideoConfiguration #6041
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've reviewed this pull request using the Sourcery rules engine
|
|
||
| mpv_properties: Optional[dict[str, str | int | float | bool]] = None | ||
| """ | ||
| Extra mpv/libmpv properties to set on native backend only (Windows/macOS/Linux/iOS/Android). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is mpv not Linux-only? (ref)
Also, can you please share a link to docs of these properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @ndonkoHenri , thank you for your comments.
The libmpv is internally used for everything but web as far as I am aware. The Flet docs mention it here:
The media_kit github shows the diagram splitting between NativePlayer and WebPlayer:
https://github.com/media-kit/media-kit?tab=readme-ov-file#packagemedia_kit-1
This site seems to mention the parameters, though I used mpv -h on my machine.
I am unable to test other systems but Linux as I do not use other OSs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I never knew their Github provided more detailed infos than their pub.dev page.
The libmpv is internally used for everything but web
Yeah, you are right from what I see.
Can you please add the link to the properties (https://mpv.io/manual/stable/#options) in this docstring too? And perhaps mention how they get translated. For ex: --hdr-compute-peak becomes key hdr-compute-peak, with possible value "yes" or boolean True...
I am unable to test other systems but Linux as I do not use other OSs.
Will see if I can test it on macOS later on.
|
quick developer survey :) |
The transition from 0.28 to 0.80 forced me to install a new OS. Flet 0.28 needed libmpv1, whereas Flet 0.80 requires libmpv2, which I was unable to install on my Ubuntu 22.04. Updating to Ubuntu 25.04 solved the issue. The video example works on Linux just fine, though where I found a mismatch is in local files. Other than that it all seems to work just fine :). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for custom MPV properties to the flet-video package, enabling users to pass advanced configuration parameters to the underlying media_kit/MPV player. This is particularly useful for scenarios where default playback configuration is insufficient, such as streaming from capture devices.
Changes:
- Added
mpv_propertiesfield toVideoConfigurationdataclass in Python to accept custom MPV parameters - Implemented
_applyMpvPropertiesmethod in Dart to apply these properties to the native player before media playback - Modified player initialization flow to apply MPV properties before opening the playlist
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| sdk/python/packages/flet-video/src/flet_video/types.py | Added mpv_properties field to VideoConfiguration dataclass with documentation and examples |
| sdk/python/packages/flet-video/src/flutter/flet_video/lib/src/video.dart | Implemented _applyMpvProperties method and integrated it into the player setup flow |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| All values are converted to String. Boolean values are converted to `yes`/`no`. | ||
| See the full list of parameters: https://mpv.io/manual/stable/#options | ||
| Example: | ||
| `{ | ||
| 'profile': 'low-latency', | ||
| 'untimed': True, |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation states "All values are converted to String" but the implementation only converts boolean values to "yes"/"no" and uses toString() for other types. This could be misleading since numeric values (int, float) will be converted using their default toString() representation, which may or may not match MPV's expected format for certain properties.
Consider clarifying in the documentation that numeric values are converted using their standard string representation, or add examples showing how different value types are converted.
| All values are converted to String. Boolean values are converted to `yes`/`no`. | |
| See the full list of parameters: https://mpv.io/manual/stable/#options | |
| Example: | |
| `{ | |
| 'profile': 'low-latency', | |
| 'untimed': True, | |
| All values are converted to strings using their standard Python string representation (for example, `str(42)` -> `"42"`, `str(0.5)` -> `"0.5"`). | |
| Boolean values are converted to `"yes"`/`"no"` to match mpv's expected format. | |
| See the full list of parameters: https://mpv.io/manual/stable/#options | |
| Example: | |
| `{ | |
| 'profile': 'low-latency', | |
| 'untimed': True, | |
| 'volume': 50, |
sdk/python/packages/flet-video/src/flutter/flet_video/lib/src/video.dart
Show resolved
Hide resolved
sdk/python/packages/flet-video/src/flutter/flet_video/lib/src/video.dart
Show resolved
Hide resolved
| final native = platform as dynamic; | ||
|
|
||
| for (final entry in mpvPropsRaw.entries) { | ||
| final key = entry.key.toString(); | ||
| final val = entry.value; | ||
| if (val == null) continue; | ||
| final valueStr = val is bool ? (val ? "yes" : "no") : val.toString(); | ||
| await native.setProperty(key, valueStr); |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting the NativePlayer to dynamic bypasses Dart's type safety and could lead to runtime errors if the setProperty method signature changes or doesn't exist. The code assumes that NativePlayer has a setProperty method available through dynamic invocation, but this is not type-safe.
Consider checking if the media_kit package provides a proper typed interface for setting properties, or add proper error handling around the dynamic method call to catch potential runtime errors.
| final native = platform as dynamic; | |
| for (final entry in mpvPropsRaw.entries) { | |
| final key = entry.key.toString(); | |
| final val = entry.value; | |
| if (val == null) continue; | |
| final valueStr = val is bool ? (val ? "yes" : "no") : val.toString(); | |
| await native.setProperty(key, valueStr); | |
| final native = platform; | |
| for (final entry in mpvPropsRaw.entries) { | |
| final key = entry.key.toString(); | |
| final val = entry.value; | |
| if (val == null) continue; | |
| final valueStr = val is bool ? (val ? "yes" : "no") : val.toString(); | |
| try { | |
| await (native as dynamic).setProperty(key, valueStr); | |
| } catch (e, stackTrace) { | |
| debugPrint( | |
| 'Error setting MPV property "$key" to "$valueStr": $e\n$stackTrace', | |
| ); | |
| } |
Description
Added the option for flet_video to accept MPV parameters by passing them through media_kit flutter package. This is needed in scenarios, where the default configuration is unable to play the selected media.
Test Code
Showing a real-time video stream from a capture device on Linux (with v4l2).
Type of change
Checklist