jlesage / docker-handbrake

Docker container for HandBrake
MIT License
818 stars 95 forks source link

QNAP low CPU usage #243

Open B85S5DSG opened 1 year ago

B85S5DSG commented 1 year ago

Hi,

I installed the "latest" version yesterday (1/22/23) from container station on my QNAP TVS-872XT with the mapped volumes pointing to folders on the host. I'm using a custom x265 10 bit encode - basically RF20 medium limited to 4k resolution and with automatic passing of audio and subtitles in three languages. Nothing fancy, just a modification of a Matroska preset.

The TVS-872XT has a 6 core Intel i5 8400T, and 64GB of RAM. It's set up with QuTS Hero, so it's running ZFS. The volume that the folders are mapped saturates my gigabit connection when writing to it, so I'm getting at least 128MB/s write speeds. I've also transferred to an older NAS over a 5gigabit connection at 300MB/s. So, no disk bandwidth problems (6X 8TB WD Red in ZFS RAID6 equivalent, and the OS and container station on a 2X 1TB ZFS RAID1 equivalent SSD array).

However, container station is showing only 25% CPU usage during the encode, even though I have it set to use 100%. Is the docker not able to use all cores? There is no setting in container station for how many cores to allocate to the docker unlike virtualization station.

Thanks for looking into it.

khromov commented 1 year ago

Which video encoder are you using? If you are using the QSV (Intel QuickSync) encoder then you will be limited to as fast as the GPU on your CPU is able to convert. If you want to go faster (or rather use more CPU resources), try the non-QSV option.

Docker does not have limit CPU usage (unless your QNAP implementation applies one). Docker is not virtualization, it runs programs natively but in an isolated namespace.

B85S5DSG commented 1 year ago

I am using x265 10 bit. Quicksync is not an option in the Handbrake container even through the QNAP has an 8400T CPU. Plex running natively supports hardware transcoding, but Handbrake in the container does not appear to be able to use it. In any case, I would rather use software encoding and use the CPU's full power, or limit it to 80% or so. At this point neither that nor QSV are possible. Encoding performance is quite poor.

jlesage commented 1 year ago

Can you try the latest image ? For me all cores are at 100% when doing a x265 encoding.

B85S5DSG commented 1 year ago

Even with the latest image I'm having the same issue - HanBrakeCLI CPU usage is steady at about 30% with peaks up to 43%. I wonder if it's a Container Station issue. Are you using x265 10-bit or 8-bit in your tests?

UPDATE: Actually, when I went in through the webpage and started the encode there manually rather than letting it run automatically it's faster, using the same custom preset. I'm getting about 50% CPU usage now - 27% from HandBrakeCLI and about 25% from a process called "ghb." Total CPU usage on the NAS is now about 90%.

B85S5DSG commented 1 year ago

And further testing reveals that H264 basically maxes out the CPU. The container runs using 60-80% with the total NAS CPU usage being near 98%. I did not make an H264 preset to run automatically so this was getting it started manually through the browser. It does appear that H265-10bit still cannot use as much CPU as H264 with the container on the QNAP.

Using the same encoding settings on my Windows machine on a normal installation of HandBrake, it will scale to about 20 logical cores per encode. If I run 2 encodes or more, the CPU (Ryzen 5900X) will max out at 100%.

jlesage commented 1 year ago

I'm getting about 50% CPU usage now - 27% from HandBrakeCLI and about 25% from a process called "ghb." Total CPU usage on the NAS is now about 90%.

Are you running 2 simultaneous encodings ? HandBrakeCLI is the automatic video converter and ghb is the HandBrake GUI.

jlesage commented 1 year ago

And what is the average encoding speed do you get (in fps) ?

jlesage commented 1 year ago

On one of my machine, using the GUI, I use the official Fast1080p30 preset and only change the encoder to H.265 (x265). With this, I have 12 cores that run at 60-70% (according to htop). The average encoding speed is 22fps. The source is Sintel movie in 720p (https://durian.blender.org/download/).

B85S5DSG commented 1 year ago

I'm getting about 50% CPU usage now - 27% from HandBrakeCLI and about 25% from a process called "ghb." Total CPU usage on the NAS is now about 90%.

Are you running 2 simultaneous encodings ? HandBrakeCLI is the automatic video converter and ghb is the HandBrake GUI.

No, just one encode.

jlesage commented 1 year ago

Using the 4K version of the movie pushes all my 12 cores to 98-99%.

jlesage commented 1 year ago

I found this link: https://www.reddit.com/r/handbrake/comments/fimfw7/x265_encoding_not_maxing_out_cpus/, where you can see the following comment:

x265 doesn't scale as well as x264, since some of what they do for higher efficiency creates more dependencies on other encoded blocks. This is especially notable at sub-4K resolutions; the same resolutions where x265 doesn't have much advantage over x264 (at the same speed).

This is the behaviour I seem to observe.

B85S5DSG commented 1 year ago

On one of my machine, using the GUI, I use the official Fast1080p30 preset and only change the encoder to H.265 (x265). With this, I have 12 cores that run at 60-70% (according to htop). The average encoding speed is 22fps. The source is Sintel movie in 720p (https://durian.blender.org/download/).

Using the movie file referenced above, setting up a container to use the general Fast 1080p30 preset I'm seeing good CPU utilization - basically maxing out the 8400T (with the system overhead of running other dedicated tasks) averaging about 64.5 fps. This is using the watch folder - so no difference with starting it manually.

Changing to Matroska H.265 MKV 1080p30 preset and modifying by sliding to Fast from Slow, CPU utilization goes down as before, and the average framerate of the encode drops to 12.2 fps. I only see ghb, no HandBrakeCLI in the processes list.

Starting with the settings above, raising the resolution limit to 4k, turning off all filters, using passthrough for the audio, and using the 4k source of the Sintel movie, the fps drops as expected to and average fps of 2.41 through the first 5.00% of the encode, but CPU utilization has not increased. The 8400T has 6 physical cores with no hyperthreading. This should be utilizing more CPU. "ghb" is using about 40% CPU, and the total system usage is 65%. It looks like the x265 encoder does not play nicely with the Intel 8400T CPU.

B85S5DSG commented 1 year ago

Both the 720p and 4k Sintel sources encoding with AV1 10-bit uses as much CPU as it can. So I will confirm that on the QNAP with the 8400T, HEVC is not as good encoder to use. If only AV1 had the playback support of HEVC, it would be my encoder of choice.

jlesage commented 1 year ago

It looks like the x265 encoder does not play nicely with the Intel 8400T CPU.

I think it's more about how x265 works and how it is configured/used.