mpv 12cafdc (C) 2000-2017 mpv/MPlayer/mplayer2 projects (HEAD as of now)
ffmpeg version: git-2017-08-07-1bef008
Platform: macOS 10.12.5
Play any HEVC encoded video
Hardware decoding works
vo/opengl: Loading hwdec driver 'videotoolbox'
vo/opengl: Reported display depth: -1
vo/opengl: Assuming 59.940061 FPS for display sync.
vd: Container reported FPS: 23.976025
vd: Codec list:
vd: hevc - HEVC (High Efficiency Video Coding)
vd: Opening video decoder hevc
vd: Probing 'videotoolbox'...
vd: Trying hardware decoding.
vd: Selected video codec: hevc (HEVC (High Efficiency Video Coding))
ad: Codec list:
ad: eac3 - ATSC A/52B (AC-3, E-AC-3)
ad: eac3_at (eac3) - eac3 (AudioToolbox)
ad: Opening audio decoder eac3
ad: Requesting 1 threads for decoding.
ad: Selected audio codec: eac3 (ATSC A/52B (AC-3, E-AC-3))
cplayer: Starting playback...
mkv: queuing seek to 216.591000
cplayer: hr-seek, skipping to 216.591000
mkv: execute seek (to 216.591000 flags 40)
cache: Dropping cache at pos 80514398, cached range: 9072-48309104.
cache: Seeking underlying stream: 48309104 -> 80514398
mkv: seek done
vd: Pixel formats supported by decoder: yuv420p10le
vd: Codec profile: Main 10 (0x2)
vd: Requesting pixfmt 'yuv420p10le' from decoder.
vd: Falling back to software decoding.
vd: Detected 8 logical cores.
vd: Requesting 9 threads for decoding.
FFmpeg doesn't support HEVC + VT. Even if Apple supports it, they keep the API a secret, in their usual "fuck you" style.
I heard "native HEVC support" coming in macOS 10.13 (High Sierra) though...So does it mean that FFmpeg won't have HEVC hwdec support on macOS any time soon, even with capable hardware (say Kaby Lake integrated GPU)?
Once the API is known, it'll probably be relatively easy to add support for ffmpeg.
Be reminded that OSX is the worst OS for multimedia - on Windows and Linux, all this stuff has been working for a while.
HEVC acceleration requires 10.13. They added a new api call to create a CMVideoFormatDescriptionRef and that's it. https://developer.apple.com/documentation/coremedia/core_media_functions?changes=latest_minor&language=objc
That looks very undocumented.
I sure am "impressed" by Apple engineering.
There is some "documentation" in the actual header file, but it seems it did not make its way to the html documentation…
Anyone knows what needs to be changed on the ffmpeg side? Can someone submit a PR to them? I'm willing to help if anyone can provide some pointers...
Adding a hwdec requires an annoying number of small changes to some FFmpeg files, but most of the actual logic is in libavcodec/videotoolbox.c.
Here's a diff which shows some of the documentation for the new VideoToolbox api: https://github.com/xamarin/xamarin-macios/wiki/CoreMedia-iOS-xcode9-beta1
I haven't upgraded to macOS 10.13 yet to test this out, but something like this should work: http://github.com/tmm1/ffmpeg/commit/af620454283862e1bdea39f5f2d31cfcce56548c
I installed the 10.13 today and tested your changed, it doesn't seem to work. Are there any changes needed on the mpv side as well?
Here's an updated patch which worked for me: https://github.com/FFmpeg/FFmpeg/compare/master...tmm1:vt-hevc.patch
I took some shortcuts so it may not work on some HEVC files. Let me know how it works for you.
@pxia helped me test my patch and confirmed it works. I have submitted it to ffmpeg-devel here: http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/216879.html
@tmm1 Do you have a brew package to test?
The hevc patches have been committed to ffmpeg, so you could brew upgrade ffmpeg --HEAD
You also need to rebuild mpv: brew install --build-from-source mpv
I just came through a video where some segments become complete gibberish of random color strips. It plays fine in software decoding and in quicktime (in quicktime the colors are washed out though). Any thoughts?
Thank you very much @tmm1
I'll rebuild ffmpeg to test soon (i've some ROS stuff thats dependent on ffmpeg too)
@pxia If you can share the sample I can try to investigate.
You can try this file: hevc_sample_short.mp4.zip. You can see the badly decoded part by opening with mpv -hwdec=videotoolbox. You can also transcode with ffmpeg -hwaccel videotoolbox and the bad part will end up in the output file in whatever format (so it's a decoder issue not a gpu issue)
Thanks for looking into this.
@tmm1 I'm using latest High Sierra, and I'm testing with both ffmpeg and mpv built from HEAD, and here's what I got:
vo/gpu: Probing for best GPU context.
vo/gpu/opengl: Initializing GPU context 'cocoa'
vo/gpu: GL_VERSION='4.1 INTEL-10.28.26'
vo/gpu: Detected desktop OpenGL 4.1.
vo/gpu: GL_VENDOR='Intel Inc.'
vo/gpu: GL_RENDERER='Intel(R) HD Graphics 5300'
vo/gpu: GL_SHADING_LANGUAGE_VERSION='4.10'
vo/gpu: Loaded extension GL_APPLE_rgb_422.
vo/gpu: Testing FBO format rgba16
vo/gpu: Resizing texture: 16x16
vo/gpu: Using FBO format rgba16.
vo/gpu: No advanced processing required. Enabling dumb mode.
vo/gpu: Loading hwdec driver 'videotoolbox'
vo/gpu: Assuming 59.948830 FPS for display sync.
vd: Container reported FPS: 23.976404
vd: Codec list:
vd: hevc - HEVC (High Efficiency Video Coding)
vd: Opening video decoder hevc
vd: Probing 'videotoolbox'...
vd: Trying hardware decoding.
vd: Selected video codec: hevc (HEVC (High Efficiency Video Coding))
cplayer: Starting playback...
vd: Pixel formats supported by decoder: videotoolbox_vld yuv420p10le
vd: Codec profile: Main 10 (0x2)
vd: Requesting pixfmt 'videotoolbox_vld' from decoder.
ffmpeg/video: hevc: Unknown VideoToolbox session creation error 4294954390
vd: Pixel formats supported by decoder: yuv420p10le
vd: Codec profile: Main 10 (0x2)
vd: Requesting pixfmt 'yuv420p10le' from decoder.
vd: Falling back to software decoding.
vd: Detected 4 logical cores.
vd: Requesting 5 threads for decoding.
vd: Using software decoding.
vd: Decoder format: 3840x1600 yuv420p10 bt.2020-ncl/bt.2020/pq/limited SP=10.000000 CL=unknown (auto 0.000000/0.000000/0.000000)
vd: Using container aspect ratio.
The error from what I can see should be
ffmpeg/video: hevc: Unknown VideoToolbox session creation error 4294954390
Any updates?
Sorry I ran out of time to work on this. I guess maybe your samples have more than one VPS or more than one SPS. Right now multiple PPS are passed into the decoder, but only one VPS/SPS. You could set a breakpoint here and try to change the SPS section to match the loops used for PPS.
I've made the changes as you described: https://github.com/pxia/FFmpeg/commit/10d7a29d7a413af539d33baa3312df74b2af85e0
But it doesn't seem to fix the issue :(
@tmm1 Do you have any other idea what might cause this glitch since handling multiple VPS/SPS does not seem to fix it? Or am I handling them wrong?
Your patch looks correct. Did you try printing out num_* to see how many vps/sps that sample has?
I upgraded to High Sierra today and tried your sample. I see the same problem.
I think the issue is probably related to SEI_PREFIX/SEI_SUFFIX NALUs, which are currently not passed to the VT decoder.
I was able to fix this bug as part of a larger VideoToolbox patchset I'm working on. It has been submitted to ffmpeg-devel here: http://ffmpeg.org/pipermail/ffmpeg-devel/2017-November/219573.html
I compiled from your branch and got this error:
[ffmpeg] Assertion (frame->private_ref && frame->private_ref->size == sizeof(Fra
meDecodeData)) || !(avctx->codec->capabilities & (1 << 1)) failed at libavcodec/
decode.c:621
The branch probably misses this bit (didn't check): https://github.com/mpv-player/ffmpeg-mpv/blob/master/libavcodec/videotoolbox.c#L74
If you're trying to use it with mpv, better off applying the patchset to ffmpeg-mpv fork instead.
Tested and can confirm it's working. Thanks!
The patchset was pushed to ffmpeg master.
@wm4 Is mpv compiled against ffmpeg-mpv or upstream ffmpeg in the releases? Is there any easy way to compile mpv myself without installing both versions of ffmpeg?
You can compile using ./waf configure --enable-ffmpeg-upstream
For those who find this thread after running into visual glitches when playing 10-bit HEVC files, here's the tl;dr on what you need to run:
brew install nasm texi2html
brew upgrade --HEAD ffmpeg
brew upgrade --HEAD mpv
Most helpful comment
FFmpeg doesn't support HEVC + VT. Even if Apple supports it, they keep the API a secret, in their usual "fuck you" style.