Control Group Scripting w/HandbrakeCLI

Support for HandBrake on Linux, Solaris, and other Unix-like platforms
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
ahardy
Posts: 4
Joined: Thu May 07, 2020 3:12 am

Control Group Scripting w/HandbrakeCLI

Post by ahardy »

Problem / Description
I have created a cgroup to execute a bash script. The script works however annihilates my CPU and has been tested / proven to work. However my CPU tends to get annihilated when this happens, which is frankly expected as it is encoding after all. I created a control group and forced resource limits to the script to address the whole resource problem. With the cgroup, the file is made but seems like nothing happens.

Side note, I have tried to "set affinity" and use cpulimit aswell for alternatives with zero success. The control groups does indeed run the command with the resources it is set and does generate the new file, but never encodes. I am open to really anything at this point, but I need to control handbrakecli from just ripping into my CPU.

General Detail of Server
- XCP-ng / Xen Host
- Ubuntu 18.04
- HandBrake 1.2.1

Script
find /home/username/sharem/* -type f -size +4000M -exec bash -c 'HandBrakeCLI --encopts="coder=auto" -v0 -i "{}" -o "${0%.*}"-720p.mp4 --preset "Fast 1080p30"' {} \; -exec bash -c 'mv "${0%.*}"-720p.mp4 "${0%.*}".mp4' {} \; -exec bash -c 'rm "{}"' {} \;

Control Group

Code: Select all

[Unit]
Description=Encoding Video Files

[Service]
ExecStart=/bin/bash /home/username/maintain/bashhandbrake.py -d --foreground=true
MemoryAccounting=true
MemoryMax=1024M
CPUAccounting=true
CPUQuota=35%

[Timer]
OnCalendar=Mon *-*-* 5:00:00
Persistent=true

[Install]
WantedBy=multi-user.target

Log
There is no activity log, that I can find on the host. Open to providing it, if you can tell me what the name of the file is or command to make it. Yes I have read the article that was posted.
mduell
Veteran User
Posts: 8187
Joined: Sat Apr 21, 2007 8:54 pm

Re: Control Group Scripting w/HandbrakeCLI

Post by mduell »

The log is the output to stderr. You can write it to a file using the appropriate redirection syntax for your shell.
ahardy
Posts: 4
Joined: Thu May 07, 2020 3:12 am

Re: Control Group Scripting w/HandbrakeCLI

Post by ahardy »

Figured it out, had to modify the script a bit as I was using the wrong options for gpu encoder / adjusted the preset. The systemctl cpu limitations work but handbrake does not seem to do well by forcing low cpu use.
ahardy
Posts: 4
Joined: Thu May 07, 2020 3:12 am

Re: Control Group Scripting w/HandbrakeCLI

Post by ahardy »

There a way to increase the use of the GPU over CPU? Getting like 100MB use and like 1 to 2% use out of the GPU.
Woodstock
Veteran User
Posts: 4614
Joined: Tue Aug 27, 2013 6:39 am

Re: Control Group Scripting w/HandbrakeCLI

Post by Woodstock »

You would have to have a video card that implements a video encoder chip, such as Intel's QSV, or the equivalent tech from nVidia or AMD. The flatpak distribution can use QSV, but AMD and nVidia are experimental.

"Just" a GPU is not going to be used by handbrake.
ahardy
Posts: 4
Joined: Thu May 07, 2020 3:12 am

Re: Control Group Scripting w/HandbrakeCLI

Post by ahardy »

Okay, I have p2000 and the script was modified to include -e option for nvenc. However still really low use. I understand that a majority of the load would be on the CPU based from replies / documentation but there is not much documentation on how to increase that load to be more on the GPU oppose to the cpu.
User avatar
s55
HandBrake Team
Posts: 10350
Joined: Sun Dec 24, 2006 1:05 pm

Re: Control Group Scripting w/HandbrakeCLI

Post by s55 »

NVEnc is video encoding only. As such, Decode, A/V Sync, Filters, Audio, Muxing etc are all CPU bound and the CPU can bottleneck the nvidia card.

Also note, NVEnc is not a GPU encoder. It's an ASIC. It's dedicated hardware so it may not show up as GPU usage rather Encode Engine Usage instead.

Finally, We'd need to see an encode log to see if it's working correctly or not.
Post Reply