Skip to content

Render libmpv video through Avalonia's OpenGL control - #8

Open
amaztony wants to merge 3 commits into
Bitpainter75:mainfrom
amaztony:fix/macos-video-playback
Open

Render libmpv video through Avalonia's OpenGL control#8
amaztony wants to merge 3 commits into
Bitpainter75:mainfrom
amaztony:fix/macos-video-playback

Conversation

@amaztony

@amaztony amaztony commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • render libmpv frames through Avalonia's OpenGL control instead of a platform-native child window
  • serialize libmpv commands away from the UI and render callbacks
  • keep one Avalonia video control across fullscreen transitions and video navigation, while reattaching libmpv if Avalonia recreates the OpenGL context
  • synchronize playback state immediately and keep video controls readable over the frame
  • hide image-only histogram content while viewing video
  • discover system-installed libmpv in conventional Homebrew, Intel Homebrew, and MacPorts locations on macOS

Motivation

The previous native child-window approach used platform window handles and did not compose reliably with Avalonia layout and overlays on macOS. In failure cases, the embedded surface could remain black while mpv opened a separate window.

This change uses the libmpv Render API with an Avalonia OpenGL control. Avalonia owns the framebuffer, clipping, controls, and fullscreen layout, while libmpv commands are kept away from the UI thread and OpenGL render callbacks. The same rendering and composition path is now used on Windows, Linux, and macOS.

macOS also has a separate library-discovery issue. A Homebrew-installed libmpv normally lives under /opt/homebrew, which is not necessarily searched by the .NET native-library resolver when FerrumPix is launched as an application bundle. The resolver now checks the default library names first, then conventional Homebrew, Intel Homebrew, and MacPorts library directories before retaining the existing application-local fallback.

Dependency policy

This PR does not bundle libmpv or codecs and does not add package references or packaging changes. It preserves the existing system-first policy. On macOS, libmpv must still be installed separately, for example with:

brew install mpv

Validation

  • user-level testing completed on a Mac mini with an M4 chip and Homebrew mpv
  • video frames render inside the FerrumPix window without a separate mpv window
  • playback, pause, resume, seeking, fullscreen entry and exit, returning to the gallery, and application exit were verified
  • Windows and Linux now use the same Avalonia OpenGL composition path; build and runtime validation on both platforms is still required before cross-platform behavior can be considered verified

amaztony added 2 commits July 31, 2026 12:21
Replace native child-window embedding with libmpv's OpenGL render API so video frames participate in Avalonia layout, clipping, overlays, and fullscreen transitions on macOS. Serialize media commands away from the UI and render threads, preserve playback state across view changes, and hide image-only histogram content for videos.
@amaztony
amaztony force-pushed the fix/macos-video-playback branch from 7612ea2 to 0f9363a Compare July 31, 2026 06:57
@amaztony amaztony changed the title Render libmpv video inside Avalonia Render libmpv video through Avalonia's OpenGL control Jul 31, 2026
@amaztony
amaztony marked this pull request as ready for review July 31, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant