How to Encode H.265 HEVC Video that will Play in Quicktime on MacOS using FFMPEG

Posted on December 29, 2017

There are quite a few ways to produce HEVC video with MacOS. Indeed, the new Macs have hardware-accelerated encoding. While that's certainly preferable, at the moment it's difficult to find solutions that make use of that acceleration. Apple's own Compressor no doubt does, but who wants to shell out $50 to compress a video now and then?

Quicktime itself will output HEVC exports for 1080p and above, but you can't tweak the settings, framerate, or much of anything, really.

So, I guess hardware-accelerated encoding is not for the cheapskates. What else is there?

Loads of people try to use Handbrake or ffmpeg to produce HEVC videos but they won't play in Apple's ecosystem. I spent quite some time to find the magic setting, so I'll save you the trouble and share it with you now.

First get an ffmpeg build with libx265 built in. You can compile it or I think the static downloads have it built in.

I used homebrew and built it myself like so:

brew install ffmpeg --with-tools --with-fdk-aac --with-libvpx --with-x265 --HEAD

To produce a 720p video (1280x720) with HEVC, I use the following:

ffmpeg -i input.MOV -filter:v scale=1280:-1 -r 30 -c:v libx265 -crf 21 -c:a aac -b:a 128k -f mp4 -pix_fmt yuv420p -tag:v hvc1 -movflags faststart output.mp4

The key ingredients here are the libx265, pix_fmt, and hvc1 tag. The hvc1 tag clues Apple in that the video should indeed play with Quicktime. The pixel format is also important for Apple-compatibility. movflags moves the metadata to the beginning, which helps in scrubbing on iOS and streaming over networks. Tweak your video quality with the crf flag and pretty much everything else is standard ffmpeg.

No, it's not hardware-accelerated but it works and doesn't cost a dime.

comments powered by Disqus