T2 and Video Encoding Wow

Scarpad

macrumors 68000
Original poster
Jan 13, 2005
1,881
366
Ma
I've started to reencode my library previously in MKV rip of Movies and TV Shows to H265 with handbrake and utilizing the T2 chip. I've always been impressed with H265 but previously with hardware encoding it just took too long. The T2 is amazing I'm encoding DVD's at 2000 avg bitrate and Blu Rays at 5000 avg bitrate and they look great. From my Mini , an I3 8gb model , i'm getting 325kbps for dvd's and for blu rays around an avg of 100kbps. My understanding is the processor is out of the equation so these should be the rates i would get on an I5 and I7 also , although more Ram and perhaps more cores would allow my set up more instances of Handbrake encoding, that i'm not sure about.

I've compared Hardware encoding to using the T2, there is a slight edge given to Hardware for image quality but it ever so slight that the time improvement wins out.

anyone have any video encoding stories to share?
 

treekram

macrumors 68000
Nov 9, 2015
1,849
401
Honolulu HI
There's a thread on the Apple discussion forums about this and in one of the responses, there was a link to an Apple PR release that says the T2 can do HEVC video transcoding "up to an incredible 30 times faster". Other people are saying more like 4x. YMMV. This thread also has a link to the Handbrake git site and there was a H.265 issue in Handbrake (but not if you used the High 5.1 setting?) that was fixed 2 weeks ago although I don't know if this fix has made it into the latest version.

I frequent the Mini and MBP forums here and I can't remember a recent thread on this (may have missed it). On my to-do list is some H.265 testing/research with my 2018 MBP and perhaps re-doing some of my videos. I wasn't aware of the T2 role until I saw this thread so thanks for posting.
 

treekram

macrumors 68000
Nov 9, 2015
1,849
401
Honolulu HI
Searching the Internet and it doesn't seem Handbrake supports Apple T2 yet.

One discussion on reddit. https://www.reddit.com/r/handbrake/comments/9zmn0k/does_handbrake_support_apples_t2_chips/
The post in the link is 2 months old. The latest Handbrake release, 1.2.0 was in mid-December (December 17 is when the release notes were posted on the GitHub site, another site says the release date was December 22).
https://github.com/HandBrake/HandBrake/releases/tag/1.2.0

In this document, under the Mac section, it says "Added initial support for VideoToolbox (hardware-accelerated) encoding" and it appears that using the T2 chip is part of this hardware acceleration for computers that have the T2. The bug that is being worked out (again, maybe it's OK if you use the High 5.1 setting) was fixed 14 days ago, so 1.2.0 does not have this fix. The GitHub page describing the bug is at:
https://github.com/HandBrake/HandBrake/issues/1689

To me, the people involved in this dialog seem to know what they're talking about and nowhere do they say that the T2 chip is not being used in the H.265 encoding (the title of the bug report is "HandBrake-20181124144208-2b2bf33 h.265 (videotoolbox) T2 encoding stops with error"). If you read this and disagree or have some other information that this is not the case, please post it.

Really, we should do some hands-on work with H.265 encoding on Handbrake. I haven't yet done this but to me, it doesn't seem like Handbrake 1.2.0 H.264 encoding (for the settings I use) is not any faster than would be expected given the CPU my 2018 MBP has compared to my other computers that I use HandBrake on. It would be good if the OP has some comparison between a non-T2 computer to the 2018 Mini they have.
 
Last edited:

WilliamG

macrumors G3
Mar 29, 2008
9,002
2,417
Seattle
I tested Handbrake 1.2.0 and it wasn’t using the T2 that I could tell. I had to use ffmpeg in the command line to get it to work.
 

treekram

macrumors 68000
Nov 9, 2015
1,849
401
Honolulu HI
At the moment, I don't have a lot of time to do in-depth testing. However, using HandBrake 1.2.0, in the Video tab, in the Video Encoder drop-down, there are options for "H.264 (Video Toolbox)" and "H.265 (Video Toolbox)". Using H.265 (Video Toolbox), I get an error maybe 10-20 seconds into the encode (probably the bug I linked in post #7). I can't set the Profile to "high" and Level to "5.1" (in the Encoder Options section) when using H.265 (Video Toolbox) (supposedly this will avoid the bug). I tried some other options but it didn't fix the problem. Using the H.264 (Video Toolbox) option, it does work and the encode is significantly faster than the default H.264 (x264) option (exact timings will need to wait) so I think that it is using the T2 chip when a Video Toolbox option is selected.
 

treekram

macrumors 68000
Nov 9, 2015
1,849
401
Honolulu HI
I've done some testing. For these encodes, I used a 2-minute 1080i video taken from a cable broadcast of a sporting event. The source file is H.264 but with little compression (230MB). I used the "Fast 1080p30" preset and other than the "Video Encoder" option, the default settings were left unchanged. The different encoder options I tried were "H.264 (x264)", "H.264 (VideoToolbox)", "H.265 (x265)" and "H.265 (VideoToolbox)". It's important to note that the "H.265 (VideoToolbox)" option does not appear on my 2012 Mini (2.6Ghz quad), only on the 2018 MBP (15" 2.2Ghz 6-core).

First, looking at H.264 since it's important for comparison purposes.
2012 Mini: x264: 3:13 (3 min, 13 sec) --- VideoToolbox: 1:15 (38.9% of x264)
2018 MBP: x264: 1:37 -- VideoToolbox: 0:40 (41.2% of x264)
So, the "H.264 (VideoToolbox)" encoder is significantly faster but doesn't seem to use the T2

For H.265, as I mentioned earlier, there is a bug in the latest public release but Nightly Builds are available and the one I used was from Jan. 30. The bug I was encountered earlier has been fixed in this build.
x265: 4:03 -- VideoToolbox: 0:39 (16.0% of x265)
So, either the VideoToolbox is better optimized for H.265 than H.264 (or conversely, x265 is a laggard) or H.265 encoding using the VideoToolbox encoder does use the T2 chip.

When using the x264 and x265 encoders, CPU utilization is near 100% (Activity Monitor reports a bit under 800% for the Mini or a bit under 1200% for the MBP). When using VideoToolbox, it is a bit less, a bit under 750% for the Mini and around 1000% when using H.264 and something a bit more than 1100% when using H.265. So, the CPU is still being heavily used even when doing H.265 VideoToolbox encoding. That makes it less than definitive that the T2 is the cause of the much better performance of H.265 encoding. One thing that I notice is that the CPU utilization difference between x264/x265 vs. VideoToolbox is enough to be audibly noticeable (fan noise) on my 2018 MBP.

File sizes after encoding were not that much different - 92MB or 93MB for all the files except x264 which was 96MB. I did not notice a quality difference between the four files when viewing them - this was just a quick run-through of the files. (Note: VLC says the H.265 files are indeed H.265-encoded.)

This is just a quick look. If you change the settings, use a better quality source, do a side-by-side frame-level comparison, then more useful insights will turn up. Also, as mentioned in the release notes for 1.2.0, this is the initial release of VideoToolbox support so perhaps there are improvements to come. There's certainly enough to keep me interested when the next public release is available.
 
Last edited:

treekram

macrumors 68000
Nov 9, 2015
1,849
401
Honolulu HI
In doing more work with this, I have the following observations:

- As mentioned earlier, a sports event video as a test file produced a compressed file about 40% of the size of the non-compressed file. I tried a couple of videos (1080p) which had less action with decent video production values (not a big-budget movie) and I got compression to 18% (test video 1) and 9% (test video 2) using the H.265 VideoToolbox option. There was a wider range of file sizes between H.264 and H.265 with and without VideoToolbox as well than was the case of the sports video.

- I found an online conversation between one of the Handbrake developers and some Handbrake users. The developer mentioned that Apple does not provide much in the way of tuning options for the VideoToolbox. From what I saw the only real option to control quality vs. file size was the "Average Bitrate" option (in the Video tab). Increase the bitrate and the quality and file size goes up. The Handbrake developer bemoaned the fact that a Quality setting (will appear just above the "Average Bitrate setting) is not available when using the VideoToolbox (as it is for the x264 and x265 encoders). This allows the bitrate to fluctuate so that more compression is done in the more static scenes, less in more active scenes.

- In taking the time to do a side-by-side, frame comparison (selected frames) on one of my 1080p test videos (not the sports video), there were obvious quality differences between the VideoToolbox H.265 and the uncompressed video where there is a lot of detail and then action around that detail. Now, if that detail is not important contextually to the content of the video, one may not notice the difference if one is asked to compare the videos in their entirety in real-time (not frame-by-frame or side-by-side). The default H.264 fast setting produced (in my opinion) better quality with a 24% larger file size.

- It is clear that the CPU plays a big role in the H.265 VideoToolbox encoding because I see high (90%+) CPU utilization over all cores on a consistent basis. Because we can't see what the T2 utilization is (if I'm wrong, please let me know), we don't know what role it plays - can it actually do a full encode or does it just do specialized tasks? I suspect it can do a full encode and so at this point, I also suspect the T2 and the CPU encode different portions of the video.

- In my opinion, the Handbrake default of x264 (fast) does a good job of balancing quality, processing time and file size. Because of the lack of flexibility in setting the quality, I don't see using the H.265 VideoToolbox as my default encoder. If there's more flexibility in using the T2/CPU hardware (either through VideoToolbox or other means), that may change. I probably will use it when file size/processing time considerations outweigh quality considerations but at this point, I'm not going out and re-encoding my Blu-ray-derived videos.

- Although the H.265 VideoToolbox is not yet part of the public release, and because it appears that Handbrake just hands off the encoding to the VideoToolbox, I would suspect that there won't be much difference in what is there now in the nightly build and what will be in the public release. More important is any new release of the VideoToolbox by Apple. So if you need the smaller file size/faster processing time now that H.265 VideoToolbox affords, then just use the latest nightly build for H.265 VideoToolbox encodes (but keep the public release as well).

UPDATE (after 4 days): In doing actual files (not 2-minute clips) - 1080p commercially-produced downloaded files, 15-30 minutes in length and comparing it with using the software x265 encoder, the VideoToolbox produces significantly larger files. For files that have been more compressed (looking at bytes per frame), I find it's non uncommon for files to be larger than the original. Also, doing files with lower resolution than 1980x1080 produced much larger files than the original (only tested 3 files but the files were at least 60% larger) - I don't know changing the settings will fix that. With my two 2-minute test files, the CPU utilization was close 90%+ but - in looking at the Activity Monitor during the processing on one file, the utilization didn't go over 300% (1200% is the max for my MBP). I haven't done enough testing to be able to make a good characterization of T2 vs CPU use for the files I'm working on.
 
Last edited: