Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimally using hevc_videotoolbox and ffmpeg on OSX

I'm using ffmpeg 4.3.1 to convert videos from h264 to h265 and initially I was excited to discover that I can use my Mac's GPU to speed up the conversion with the flag hevc_videotoolbox.

My Mac hardware is the 10th generation Intel i5 with AMD Radeon Pro 5300

I'm using this command:

ffmpeg -i input_h264.mp4 -c:v hevc_videotoolbox -b:v 6000K -c:a copy -crf 19 -preset veryslow output_h265.mp4

The conversion speeds increased from 0.75x to 4x, almost a 500% improvement !

But then I noticed large filesizes and slightly fuzzy results. Then I noticed that changing the crf or the preset makes no difference, ffmpeg seems to ignore those settings. The only setting that seems to work is the video bit rate (-b:v).

So I started to google around to see how I could get better results.

But except for a few posts here and there, I'm mostly coming up blank.

Where can I get documentation on how to get better results using hevc_videotoolbox? How can I find out what settings work and which ones are ignored?

like image 374
Brajesh Avatar asked Dec 05 '22 08:12

Brajesh


2 Answers

Listing options

Run ffmpeg -h encoder=hevc_videotoolbox to list options specific to hevc_videotoolbox.

Use -b:v to control quality. -crf is only for libx264, libx265, libvpx, and libvpx-vp9. It will be ignored by other encoders. It will also ignore -preset.

hevc_videotoolbox isn't as good as libx265, but it is fast

Like most hardware accelerated encoders, hevc_videotoolbox is not as efficient as libx265. So you may have to give it a significantly higher bitrate to match an equivalent quality compared to libx265. This may defeat the purpose of re-encoding from H.264 to HEVC/H.265.

Avoid re-encoding if you can

Personally, I would avoid re-encoding to prevent generation loss unless the originals were encoded very inefficiently and drive space was more important.

like image 156
llogan Avatar answered Dec 29 '22 07:12

llogan


Use constant quality mode (CFR) of videotoolbox on apple silicon to achieve high speed, high quality and small size

(not working with rosetta2)

The change log https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/efece4442f3f583f7d04f98ef5168dfd08eaca5c

I have briefly tested. Here are my steps:

  1. Compile ffpmpeg there are no off the shelf binary available https://trac.ffmpeg.org/wiki/CompilationGuide/macOS

  2. run with -q:v 65 [the value should be 1-100, higher the number better the quality, 65 seem to be acceptable]

for example

ffmpeg -i in.avi -c:v hevc_videotoolbox -q:v 65 -tag:v hvc1 out.mp4
like image 42
Philip Mok Avatar answered Dec 29 '22 05:12

Philip Mok