mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.25k stars 2.9k forks source link

no hardware decoding using MPV on egpu #3653

Closed wizzopro closed 5 years ago

wizzopro commented 8 years ago

I can not get hardware decoding to work in MPV with a Zotac GTX 970 in an Akitio Thunder2 box on OSX 10.10.5 Yosemite (tested both a Mac Mini late 2012 and Macbook Pro mid 2012). This is while trying to play a standard “older” H264 file, which should be easily supported. Hardware decoding on the Intel igpu works fine, however when I try to play the files using the egpu, videotoolbox has trouble initiating and MPV falls back to software decoding.

I have tried multiple files in both .mp4 and .mkv container format, all without success. Also a lengthy google search did not reveal an answer. I tried the pre-compiled MPV, as well as a self-compiled —HEAD version using homebrew. does videotoolbox only support natively supported cards? This would exclude the entire Maxwell series from using gpu decoding (and will spell more trouble for much- needed Pascal-based h265 decoding when Nvidia will get around to release their new web-driver!).

I run the latest homebrew-compiled mpv as follows:

mpv --no-config -v --hwdec=auto h264_file.mkv I disconnect the HDMI on the Mac Mini to ensure OpenGL context is set for Nvidia:

[vo/opengl] GL_VENDOR='NVIDIA Corporation' [vo/opengl] GL_RENDERER='NVIDIA GeForce GTX 970 OpenGL Engine' [vo/opengl] GL_SHADING_LANGUAGE_VERSION='4.10'

However the result is always:

IOVARendererID property not found [12:30:54.700] vtDecompressionDuctCreate signalled err=-8973 (err) (Could not select and open decoder instance) at /SourceCache/CoreMedia_frameworks/CoreMedia-1562.240/Sources/VideoToolbox/VTDecompressionSession.c line 1181 [vd] failed to init videotoolbox decoder: -1313558101

Although the first line is suspect I think it is just a warning, as it also appears when playing on the igpu (on which, as mentioned, hardware decoding works fine), so the problem appears to me to be videotoolbox not wanting to do hardware decoding on the 970.

Does anyone know what's going on here? Any help would be greatly appreciated.

ghost commented 8 years ago

Does anyone know what's going on here?

Nope.

haasn commented 8 years ago

Does it work in other applications?

wizzopro commented 8 years ago

First of all, thanks for your interest in this problem.

Any advice which apps to use to properly test this? I tried VLC 2.2.2 Weatherwax but enabling GPU acceleration doesn't seem to make a difference. However VLC does not use videotoolbox but VDA for acceleration and VDA I believe is deprecated. Also I read that GPU acceleration is broken in some 2.2 versions of VLC: https://forum.videolan.org/viewtopic.php?t=132805

The OS acceleration works fine and also opengl in games and the Heaven and Valley benchmarks is without problems. I moved from Yosemite to El Crapitan by now to see if that makes a difference for MPV hwdec but no joy.

MPV hardware acceleration in Windows 10 under bootcamp seems to work ok, but it would be a real mess to have to reboot into windows every time I simply want to play a video using hardware acceleration.

Any help in solving this is greatly appreciated.

wizzopro commented 8 years ago

By now also tested hardware acceleration in Google Chrome on youtube and it seems to work as expected: Playing a VP9 codec video at 4k shows a very high load on the CPU, as the 970 does not support hardware decoding for this codec. Switching to using AVC codecs on the same videos (using the h264ify plugin) drastically reduces processor usage. Consequently switching off hardware decoding manually, in the Chrome settings, increases the CPU usage by a factor 3-4 again.

IOW hardware decoding for the h264 codec seems to be able to work in this setup, only MPV can not initialise it properly for some reason.

ghost commented 8 years ago

Well, the FFmpeg VT wrapper still seems to be doing some things wrong sometimes. I wonder if this patch changes anything: http://ffmpeg.org/pipermail/ffmpeg-devel/2016-October/201431.html (CC @tmm1 )

wizzopro commented 7 years ago

Sorry for my slow response. Had to figure out first how to patch homebrew installations from a file first. The patch does not make any difference. Perhaps this is as it was only originally intended to help in iOS, as specified above the patch in the link wm4 placed above.

I did some more experimenting however, that lead to some very interesting results. I have at my disposal for testing a late 2012 iMac that has an Nvidia 675MX gpu only, as well as a mid 2012 MBP with both integrated Intel hd4000 and Nvidia 650M discrete GPU and a mid 2012 mac mini with integrated Intel hd4000 as well, only.

Hardware acceleration on the iMac works fine. In this imac the (possible) Intel HD4000 is disabled by OSX: As there is no real reason to save power on this non-portable machine it always uses the Nvidia 675MX card. Due to logistics I have not yet been able to test the egpu on this machine however.

The MBP does not do hardware acceleration in the integrated nor the discrete gpu! This can however be fixed by plugging in an external monitor! With an external monitor the system somehow forces the Nvidia 650M as the active graphics card and the acceleration works fine! Hence I tried forcing on this discrete gpu using the graphicscardstatus app to see if I could get hardware acceleration started on the internal screen, but that doesn't work. On the internal screen getting any acceleration to work seems impossible for now.

On the contrary, on the mac mini (the system I intend to use as home theatre system with the egpu) the hardware acceleration works when using the integrated graphics, however not using the egpu. It does not matter whether I plug in the HDMI port (that connects to the integrated gpu) or not. Judging from the experience with the MBP above, perhaps disabling the integrated gpu completely during boot would enable/force hardware decoding on the egpu, but AFAIK there is no way to do this. Perhaps deleting kexts manually would work? I am not sure how to approach this.

So to me it seems there may be some problem where ffmpeg does not recognise the proper video card and hence does not recognise that hwdec may be supported on the current card and so falls back on software decoding.

So for now I am still stuck.

tmm1 commented 7 years ago

Did you try this?

On a Retina MBP you can switch between the Intel HD Graphics 4000 and the NVIDIA GeForce GT 650M gpu's in System Preferences > Energy Saver. UNcheck "Automatic Graphics Switching" if you want to always use the GT650M.

wizzopro commented 7 years ago

Hi tmm1, thanks for your reply. Indeed, that trick does activate hwdec on the 650M on the internal screen as well! I saw it mentioned before as well and thought I checked it, but somehow couldn't find the option before. So this trick work and gfxcardstatus does not on the MBP.

However I am still stuck with the original mac mini / egpu problem.

wizzopro commented 7 years ago

OK, so one last discovery: Using the egpu on the MBP also seems to enable hwdec on the egpu! The MBP shows all three graphics cards in "about this mac". In MPV the output is as follows:

[vo/opengl] GL_VENDOR='NVIDIA Corporation' [vo/opengl] GL_RENDERER='NVIDIA GeForce GTX 970 OpenGL Engine' [vo/opengl] GL_SHADING_LANGUAGE_VERSION='4.10'

so hwdec for the 970 seems possible! It is still giving the warning

IOVARendererID property not found

but right below that mpv confirms that

[vd] Using hardware decoding (videotoolbox).

So let's call this is a partial success. However I really would really like to get hwdec working on the mac mini as that has all the home theatre stuff connected to it. I need the MBP to be mobile for work purposes and don't want to have to reboot both computers all the time just for watching a movie. Perhaps I should add a third gpu to the mac mini to get it to work ;-)

Akemi commented 7 years ago

okay i have two branches that possible fix this issue. cocoa_forcegpu adds an option to force the dedicated GPU, --force-dedicated-gpu. the second branch cocoa_forcegpu2 also has this option and additional allows rendering on GPUs not connected to a display. could you please test branch 1 with --force-dedicated-gpu=yes and the second branch with --force-dedicated-gpu=yes and --force-dedicated-gpu=no?

i am aware hat those changes only apply to rendering and not decoding, but it seems rendering and decoding are somehow dependent on each other in the case of macOS.

wizzopro commented 7 years ago

Unfortunately, since I could not properly use the eGPU features on the Mac Mini I ended up accepting the fact that reboots remain required. Long story short I upgraded the 970 to a 1070 and play HEVC movies in Windows only. Since no OSX web-drivers for the 1070 exist as of yet I can no longer test this. If Nvidia finally decides to release those drivers I will happily test this for you and keep you posted.

skubic commented 7 years ago

I was not lucky either, and I've had an infinite number of trials. It really seems like you can not use h265 hardware decoding in macOS with Maxwell GPU.

This has nothing to do with the used player. With "mvp" I was hoping that through the used FFMPEG library something would be possible, or that one might bring Cuda to work... (mpv --hwdec=cuda ...)

Everything brought nothing.

Mac Pro (Late2013) - macOS 10.12.3 - Latest NVIDIA Web Driver + CUDA - GeForce GTX 970

wizzopro commented 7 years ago

Maxwell only supports H265 hwdec on 960 and 950 cards. The 970, 980 and 980ti are older cards that, because of their age, simply lack this feature, despite their higher model number. What card do you have?

-Edit- Ah I see now. You have a 970. The above has been well-documented for a long time on e.g. https://en.wikipedia.org/wiki/Nvidia_PureVideo

Lack of h.265 hwdec on faster Maxwell cards is why I switched to 1070.

wizzopro commented 7 years ago

My concern was that I couldn't even get h.264 playing with hwdec on an eGPU.

skubic commented 7 years ago

I did not know that yet. Had some read to the encode of h265, but then I probably transferred it to decode in mind. Yes you are right. This was about h264... Sry.

Perhaps something is going to happen. NVIDIA is nevertheless so nice to offer drivers for a "closed system". Apparently, this is not Apple's policy. But there is no "Web Driver" for Pascal GPUs. Windows is not an option.

I will probably just keep playing around with different cards and Mac systems. And also some Hackintosh Systems.

With a newer AMD GPU I had also no luck with h265 UHD files. But that does not belong here ;-)

wizzopro commented 7 years ago

Hi @Akemi. Nvidia has released Pascal drivers last night! Hence I tested the cocoa_forcegpu2 branch (the other branch is now merged with this one?). Unfortunately hwdec still does not work with h264 codec on a Zotac 1070 in an Akitio Thunder2 eGPU. For completeness: I upgraded to Sierra 10.12.4 today to get the new Nvidia drivers to work.

I ran mpv as follows:

./mpv -v --no-config --hwdec=auto --force-dedicated-gpu=yes h264_file.mkv

Important output:

[cplayer] mpv UNKNOWN (C) 2000-2017 mpv/MPlayer/mplayer2 projects [cplayer] built on Tue Apr 11 13:16:11 CEST 2017 [cplayer] ffmpeg library versions: [cplayer] libavutil 55.34.101 [cplayer] libavcodec 57.64.101 [cplayer] libavformat 57.56.101 [cplayer] libswscale 4.2.100 [cplayer] libavfilter 6.65.100 [cplayer] libswresample 2.3.100 [cplayer] ffmpeg version: 3.2.4 [cplayer] [cplayer] Configuration: waf configure [cplayer] List of enabled features: 52 any-gl apple-remote asm atomics bsd-fstatfs build-date c11-tls cocoa coreaudio cplayer debug-build dlopen dvdread encoding fchmod gcc-tls gl gl-cocoa glob gnuc iconv is_ffmpeg lcms2 libass libass-osd libav libavcodec libavdevice libdl libm lua nanosleep optimize osx-thread-name posix posix-or-mingw posix-spawn pthreads shm stdatomic subprocess termios tv videotoolbox-gl videotoolbox-hwaccel zlib

......

[vo/opengl] Initializing OpenGL backend 'cocoa' [vo/opengl] can't find an ambient light sensor [vo/opengl] GL_VERSION='4.1 NVIDIA-10.17.34 378.05.05.05f01' [vo/opengl] Detected desktop OpenGL 4.1. [vo/opengl] GL_VENDOR='NVIDIA Corporation' [vo/opengl] GL_RENDERER='NVIDIA GeForce GTX 1070 OpenGL Engine' [vo/opengl] GL_SHADING_LANGUAGE_VERSION='4.10' [vo/opengl] Loaded extension GL_APPLE_rgb_422. [vo/opengl] 16 bit texture depth: 16. [vo/opengl] Reported display depth: R=0, G=0, B=0 [vo/opengl] Testing FBO format 0x805b [vo/opengl] Create FBO: 16x16 (16x16) [vo/opengl] Using FBO format 0x805b. [vo/opengl] No advanced processing required. Enabling dumb mode. [vo/opengl] Loading hwdec driver 'videotoolbox' [vo/opengl] Assuming 59.996626 FPS for display sync. [vd] Container reported FPS: 23.976196 [vd] Codec list: [vd] h264 - H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 [vd] h264_vda (h264) - H.264 (VDA acceleration) [vd] Opening video decoder h264 [vd] Probing 'videotoolbox'... [vd] Trying hardware decoding. [vd] Selected video codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)

So it does seem to be properly finding the 1070 now! However later I again get:

IOVARendererID property not found [vd] failed to init videotoolbox decoder: Hardware doesn't support accelerated decoding for this stream or Videotoolbox decoder is not available at the moment (another application is using it). (-78) [ffmpeg/video] h264: Reinit context to 1920x1088, pix_fmt: yuv420p [vd] Falling back to software decoding. [vd] Detected 8 logical cores. [vd] Requesting 9 threads for decoding. [ffmpeg/video] h264: Reinit context to 1920x1088, pix_fmt: yuv420p [vd] Using software decoding. [vd] Decoder format: 1920x1080 [0:1] yuv420p bt.709/bt.709/bt.1886/limited CL=mpeg2/4/h264

The IOVARenderID warning does not matter; as I explained above on a macbook with built in Nvidia also gives this warning but does not result in lack of hwdec. The warning about the videotoolbox decoder not being available I get, despite the 1070 doing nothing else at all (except running the desktop and a terminal).

I hope this helps, and that this is not the end of the road. Now I again have my eGPU working under macOS I would love to switch back to using MPV and be done with endless reboots...

If there is any more info I can provide, just let me know!

ghost commented 7 years ago

Only Apple or nVidia probably know what's going on there.

wizzopro commented 7 years ago

Google chrome has no problem using h264 hardware acceleration on the eGPU, so others have cracked this as well.

vit9696 commented 7 years ago

Hi there, I was looking for other researchers of a similar problem, and unfortunately only ran into your bug. I guess I will leave a reply since I have a solution at least.

Here is the explanation of the issue, it has enough info to understand that fixing it for Maxwell only requires a single plist-only kext that injects IOVARendererID/IOVARendererSubID. For Pascal you are currently out of luck.

wizzopro commented 7 years ago

Thanks for the info @vit9696 ! This seems a promising lead! Guess I will have to show Pascal another round of patience, after already waiting for drivers for over 6 months ;)

Akemi commented 5 years ago

since the eGPU + nvidia situation is quite unclear and uncertain on apples part i am closing this.