简体   繁体   中英

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?

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.

VideoToolBox can only use the -b:v setting. The crf is ignored. You can run a few test encodes and get an idea what video bitrate is "equivalent" to the CF you desire, then use that bit rate.

After checking the source code, I found that there are constant quality mode on apple silicon (not working with rosetta2)

I have briefly tested. Here is 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, 65 seem to be acceptable]

for example

ffmpeg -i in.avi -c:v hevc_videotoolbox -q:v 65 -tag:v hvc1 out.mp4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM