9

I have a MacBook Pro with a Kaby Lake processor running macOS High Sierra (10.12). Is it possibe somehow to setup FFmpeg to utilize hardware encoding of HEVC with toolbox, instead of libx265?

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
Misha
  • 225
  • 1
  • 4
  • 11

2 Answers2

10

On MacOSX there’s Videotoolbox, a low-level framework that provides direct access to hardware encoders and decoders. It provides services for video compression and decompression, and for conversion between raster image formats stored in CoreVideo pixel buffers. These services are provided in the form of session objects (compression, decompression, and pixel transfer), which are vended as Core Foundation (CF) types.

FFmpeg implements Videotoolbox in both hardware contexts (for H/W acceleration bring-up) and as encoder wrappers (for transcoding supported codecs).

Check out the private encoder options for hevc_videotoolbox encoder wrapper:

ffmpeg -hide_banner -h encoder=hevc_videotoolbox

Output:

Supported pixel formats: videotoolbox_vld nv12 yuv420p
hevc_videotoolbox AVOptions:
  -profile           <int>        E..V.... Profile (from 0 to 3) (default 0)
     main                         E..V.... Main Profile
     main10                       E..V.... Main10 Profile
  -allow_sw          <boolean>    E..V.... Allow software encoding (default false)
  -realtime          <boolean>    E..V.... Hint that encoding should happen in real-time if not faster (e.g. capturing from camera). (default false)
  -frames_before     <boolean>    E..V.... Other frames will come before the frames in this session. This helps smooth concatenation issues. (default false)
  -frames_after      <boolean>    E..V.... Other frames will come after the frames in this session. This helps smooth concatenation issues. (default false)

Note that the output may change over time as more features are exposed in more recent ffmpeg builds.

Maybe you can test with that, if you have a recent Mac.

As you can see, it taps into the hardware-based encoders available on macOS, offering a unified API for video encoding across multiple vendor-specific abstractions, ranging from Intel (Quicksync) and AMD GPUs (Prior generation VCE and current generation VCN SIP blocks) on x86, and including the latest Apple Silicon's M-series ARM SoCs.

Grab a build here: https://evermeet.cx/ffmpeg/

Dennis Mungai
  • 3,074
  • 1
  • 22
  • 33
  • Are args like `-crf` or `-b:v` available in hevc_videotoolbox? Or how to check an arg is common or specific to an encoder? Thanks! – amdyes Aug 19 '19 at 03:45
  • @amdyes Nope. I am running macOS Mojave (10.15) on a 2019 MacBook Air with the latest install of FFmpeg from Homebrew, and honestly using `hevc_videotoolbox` is quite horrible. Speed is 2x to 3x playback speed of the source video, which is great! But the quality of the output is abysmal to be honest. The only way I got it to show decent (but still not great) quality for 720p video was by using `-profile:v main -b:v 5500k` but the filesize is not much different than the source 1080p video. Might be useful for streaming crappy video but seems like a experimental feature for now. – Giacomo1968 Dec 13 '19 at 04:16
1

Not sure if this has changed since the OP's comment, but in FFmpeg 4.x the command is:

ffmpeg -hide_banner -h encoder=hevc_videotoolbox
Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
csimon2
  • 81
  • 5