Plex on Docker on Synology: enabling Hardware Transcoding

Today, I wanted to find out how to enable hardware transcoding in Plex, running in a Docker container, on a Synology DiskStation Manager system.

To show you what the situation was like before enabling hardware transcoding, I played the movie Joker on my mobile phone, transcoding to 720p. As you can see in the image below, Plex used almost 100% of the CPU without hardware transcoding. The fan of the device was sounding like a jet engine!

After some fiddling around, I found a way to do this pretty easily. I thought it would be a good idea to share the solution with the world (which took more time to do), so here you are! Grab a cup of coffee, because it may be going to take a while to read and execute. 😅

What needs to be done

  1. Grant access to graphics device nodes.
  2. Create or change a Plex Docker container.
  3. Have fun!

Find out if your Intel® processor supports Intel® Quick Sync Video here, which you need if you use the integrated graphics of your Intel® processor. For hardware transcoding support on other processors, try this article from Plex.

If you are a Xpenology user, you may need a modified extra.lzma and extra2.lzma for having DSM 6.2.3 to recognize your Intel® integrated graphics (i915). Click for more info.

Another point of attention

I can highly recommend to have a shared folder for docker containers. For example, I have a shared folder called “docker” and created a subfolder called “plex”. The docker/plex folder will be case sensitive in every step, so make sure that when you used capital letters in the folder name, you also use those in the following commands and scripts.

If you have an existing Plex container without using a shared folder for the configuration, you need to copy the /config and /transcode folders from an existing Plex docker container to the shared docker/plex folder. Have a look at this article to learn how to copy folders from docker containers. Then SSH into DiskStation Manager and copy the folders. I used these commands for example (the /config folder can take a long time):

sudo su
docker cp plexinc-pms-001:/config /volume1/docker/plex/
docker cp plexinc-pms-001:/transcode /volume1/docker/plex/

Make sure that you mount the volumes docker/plex/config to /config and docker/plex/transcode to /transcode before you run the adjusted container afterwards.

Grant access to graphics device nodes

First we need to allow the Docker containers to have access to the graphics device nodes. Those device nodes are most likely /dev/dri/card0 and /dev/dri/renderD128. You can check that if you SSH into DiskStation Manager:

cd /dev/dri/
ls -l

In my case that returns the following result:

total 0
crw------- 1 root root 226, 0 Aug 3 20:41 card0
crw------- 1 root root 226, 128 Aug 3 20:41 renderD128

Note that the device permissions are crw--------. The c stands for “character device” and rw stands for read and write permissions for the user root. There are no group permissions or other permissions set at this time.

You could go ahead and use the command chmod to edit the permissions, but the permissions will be reset to their defaults after a reboot of your DiskStation Manager system. You can solve this by running a script that handles this every time the system boots.

  1. Create the following file in your docker/plex folder: devicepermissions.sh
  2. Edit the file, add the following lines and save the file.
#!/bin/sh
sudo chmod 666 /dev/dri/*

When executed, this command sets the permissions of all device nodes in /dev/dri/ to crw-rw-rw-. The group root and other users now have read and write access as well. I should mention that this makes your system less secure, as other users than the root user will now have access to the device nodes. Let’s say that danger is my middle name.

You can also set the permissions for the specific device nodes if you use the following lines:

#!/bin/sh
sudo chmod 666 /dev/dri/card0 /dev/dri/renderD128
  1. Now go to the Control Panel and open the Task Scheduler.
  2. Create a task: click Create > Triggered Task > User-defined Script.
  3. Give your task a name (eg. Device Permissions), set the user to root and set event to Boot-up.
  4. Set the following line as run command and click OK.
bash /volume1/docker/plex/devicepermissions.sh

Manually run the script from the Task Scheduler to set the permissions without having to perform a reboot. If you list the device nodes again, it looks like this:

total 0
crw-rw-rw- 1 root root 226, 0 Aug 3 20:41 card0
crw-rw-rw- 1 root root 226, 128 Aug 3 20:41 renderD128

Create or change a Plex Docker container

I hope that I don’t have to explain how you download the image and create a Docker container. If that is the case, this article probably isn’t for you. There are however some things that you have to make sure:

  1. You need to run the container using high privilege.
  2. Don’t run the container immediately after creating it. If you have a Plex container already running, stop the container.

Now you need to edit some settings that are not available through the Docker GUI on DiskStation Manager. Select your freshly created or current Plex container in the Docker GUI and click on Settings > Export. Select Export container settings and export the settings to a location of your choice.

Now open the exported settings file (.json) in a program like notepad. There you will find the following line:

"devices" : null,

Replace that line with the following lines. Adjust it to your needs if you have different graphics device nodes. Read more about adding devices in this article.

"devices" : [   {     "CgroupPermissions": "rwm",     "PathInContainer": "/dev/dri/card0",     "PathOnHost": "/dev/dri/card0"   },   {     "CgroupPermissions": "rwm",     "PathInContainer": "/dev/dri/renderD128",     "PathOnHost": "/dev/dri/renderD128"   }],

Save the file and go back to the Docker GUI. Click on Settings > Import and select the edited file. Enter a unique container name, because it will create a new container with the settings from the settings file. After that, make sure that you disable auto-restart on the old container.

Let’s try this thing out

So, let’s fire up Plex and see if hardware transcoding is working now. I watched the movie Joker on my mobile phone, transcoding to 720p again. Note that Transcode now has (hw) behind it, indicating that hardware transcoding is working. The results speak for themselves! As you can see in the image below, the CPU usage is reduced drastically.

Initially, the CPU usage is about 40%, probably because it is transcoding ahead. After some time, the CPU usage drops even more! Mission success.

If it is still not working for you, make sure that you have Use hardware acceleration when available enabled on the Transcoder settings page in Plex.

Wrapping things up

I hope that this article helped you to configure hardware transcoding too. If you have some remarks or questions, feel free to leave a comment. I will not help you to set up the whole thing. 😜