Skip to content
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

Unable to use libmpv on macOS (No render context set.) #12518

Closed
Vernoxvernax opened this issue Sep 29, 2023 · 16 comments · Fixed by #12947
Closed

Unable to use libmpv on macOS (No render context set.) #12518

Vernoxvernax opened this issue Sep 29, 2023 · 16 comments · Fixed by #12947
Labels

Comments

@Vernoxvernax
Copy link

Important Information

  • mpv version: v0.36.0-415-g5638fcabfd-dirty
  • macOS Version: Monterey 12.7 (VM, with no ded. GPU)
  • Source of the mpv binary or bundle: github?

Reproduction steps

mpv.conf:

vo=libmpv
hwdec=no

Just try to create the most basic simple libmpv handle and load a file.
I've stripped down the options and all of the unnecessary stuff (except for the above mpv.conf).

(the exact same code works on windows and linux)

Expected behavior

playing

Actual behavior

not playing

Log file

https://pastebin.com/t10dUGig

don't look at the comments!

I've tried troubleshooting this myself and ended up getting stuck at line 250 in macosx_events.m.
_is_application is set to false (or NO in objc??), which results in render_context (at least) never being assigned.
I have never written any macOS application, nor have I ever heard of objective c before yesterday.
I'm incompetent.
Please help.

@mlindner
Copy link
Contributor

mlindner commented Oct 15, 2023

What is this bit exactly?

macOS Version: Monterey 12.7 (VM, with no ded. GPU)

You're running Monterey in a VM? I also use Monterey, but on an actual mac computer and mpv works fine. Perhaps something is wrong in your VM setup.

@Vernoxvernax
Copy link
Author

@mlindner
I've had a conversation with a few devs before and they assured me that the problem couldn't be the VM but how libmpv and macOS works.
So if I understand this correctly, you can properly use libmpv with the default render context and without embedding it in your application?

@mlindner
Copy link
Contributor

mlindner commented Oct 15, 2023

So if I understand this correctly, you can properly use libmpv with the default render context and without embedding it in your application?

I use mpv directly from the command line which uses the libmpv video output. I'm not embedding it in any application.

@Vernoxvernax
Copy link
Author

Ok, maybe my issue description isn't clear enough. Mpv on the command line works fine. But when I try to call it from the application I am building, I experience the errors mentioned above. It's a pretty annoying edge-case, since most people either use mpv directly or write programs where they embed libmpv itself.

@mlindner
Copy link
Contributor

Ah ok, sorry for the confusion. Is your application open source? I'm not busy at the moment and I could try testing it without the VM to eliminate that case.

@Vernoxvernax
Copy link
Author

It's a CLI client for jellyfin and emby, so without having that already setup you can't test it. Don't bother with it, if it requires too much work.

@mlindner
Copy link
Contributor

Ah okay, I've never heard of jellyfin or emby so sounds like learning everything required to set it up may be difficult.

@Vernoxvernax
Copy link
Author

Vernoxvernax commented Oct 15, 2023

Yep, don't worry. I'll just wait for akemi or some macos dev to look into this.

@Akemi
Copy link
Member

Akemi commented Nov 23, 2023

looking at the code, using vo=libmpv won't work out of the box like you expect, eg it won't use the cocoa-cb backend for rendering. it was never supposed to work and i believe it shouldn't.

though using the macvk vulkan/gpu-next backend, which is supposed to work, doesn't work either. i found one problem and it is something i broke. though fixing that one problem gets me to the next one. long story short, i need to look further into this.

Akemi added a commit to Akemi/mpv that referenced this issue Nov 23, 2023
NSApp is only an Application when initialised from mpv itself. when used
via libmpv an Application is never initialised and mpv would always
immediately exit.

make the retrieval of the vo and mac options static so they can be
retrieved in all cases.

Fixes mpv-player#12518
@Akemi
Copy link
Member

Akemi commented Nov 23, 2023

fixed the usage with macvk with #12947. though keep in mind, since macOS is a bit special about the main thread/queue libmpv needs to be used/created in its own thread (none main thread), see the basic cocoa example (https://github.com/mpv-player/mpv-examples/blob/57d26935c0525585482748b7236b60fe83d3f044/libmpv/cocoa/cocoabasic.m#L94-L126). otherwise it will create a deadlock in the main thread.

@Vernoxvernax
Copy link
Author

Thank you so much! I'll try to test it as soon as possible with a fresh VM.

@Vernoxvernax
Copy link
Author

Vernoxvernax commented Nov 24, 2023

Ok. I've built mpv with the changes from your pull request.
Unfortunately, it still doesn't seem to work like expected. I've made sure to use the same configuration as in the cocoa example that you were so kind to share.

Here is a log when using libmpv using my program: https://pastebin.com/wP2hNMLP (get's stuck / deadlock?)
Here is a log when using the mpv command: https://pastebin.com/UHLiHjcW (works; so its not my graphics drivers I suppose)
This is what I get when trying to use the cocoa example from the example repo (compiled): https://pastebin.com/hw5XWTXk

@Akemi
Copy link
Member

Akemi commented Nov 24, 2023

the log of your program seems incomplete? it only tries to initialise 'displayvk' and never 'macvk'. if the log is not incomplete something is wrong on your end with your build.

the mpv log uses cocoa-cb/libmpv and not gpu-next and macvk.

set a log-file with the cocoa example please. the terminal log is not really useful. though i think it wants to initialise cocoa-cb and that doesn't work. you have to explicitly use vo=gpu-next like i said.

check_error(mpv_set_option_string(mpv, "vo", "gpu-next"));
check_error(mpv_set_option_string(mpv, "gpu-api", "vulkan"));
check_error(mpv_set_option_string(mpv, "gpu-context", "macvk"));
mpv_set_option_string(mpv, "log-file", "~/Desktop/log.log");

@Vernoxvernax
Copy link
Author

Vernoxvernax commented Nov 24, 2023

oh. Yeah I'm sorry, I totally missed that they use different configurations.

So if I'm correct, vulkan/gpu-next uses the GPU?
Does that mean, systems without supported hardware, like a VM, will not be able to use libmpv like I'm trying here?

I did see the ERROR_INCOMPATIBLE_DRIVER vulkan error before, but thought it should just fall back to sw-rendering like the command line tool.


Running the example code with your proposed edits: https://pastebin.com/Kg09YUDL

@Akemi
Copy link
Member

Akemi commented Nov 25, 2023

yeah it uses the GPU, like vo=gpu and vo=libmpv does. vo=libmpv is basically just a wrapper around vo=gpu with a public API and driving your own render loop.

VMs also have a GPU, it's just a software emulated one. it depends on the driver that are used in the VM itself and what it supports.

mpv cli does the same as the example. if you get VK_ERROR_INCOMPATIBLE_DRIVER with it, mpv will get the same error. if mpv from cli works with the macvk context and vulkan but not with the example that would be weird. if initialising works one might need to set --gpu-sw too.

i suppose that just means that either your VM doesn't support it or the vulkan driver/sdk doesn't support the VM. it's not a limitation of mpv.

@Vernoxvernax
Copy link
Author

Yes, vulkan is not supported in my VM.
I always thought it should be possible to get a working video output, since mpv does work as well.
Well, I guess having a legit mac system without vulkan support is basically impossible.
Thank you for the in-depth explanations!

Akemi added a commit that referenced this issue Nov 25, 2023
NSApp is only an Application when initialised from mpv itself. when used
via libmpv an Application is never initialised and mpv would always
immediately exit.

make the retrieval of the vo and mac options static so they can be
retrieved in all cases.

Fixes #12518
dyphire pushed a commit to dyphire/mpv that referenced this issue Dec 3, 2023
NSApp is only an Application when initialised from mpv itself. when used
via libmpv an Application is never initialised and mpv would always
immediately exit.

make the retrieval of the vo and mac options static so they can be
retrieved in all cases.

Fixes mpv-player#12518
xrun1 pushed a commit to xrun1/mpv-svp-fix that referenced this issue Mar 12, 2024
NSApp is only an Application when initialised from mpv itself. when used
via libmpv an Application is never initialised and mpv would always
immediately exit.

make the retrieval of the vo and mac options static so they can be
retrieved in all cases.

Fixes mpv-player#12518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants