Plex DVR Device Settings - Use HW-Accelerated Video Encoding

I’ll be updating my server soon and will be able to take advantage of hw transcoding

I see that in Plex DVR Device Settings there is an option to Convert Video While Recording and also a checkbox to Use hardware-accelerated video encoding

Has anyone used this setting?
Indicated as “Experimental”. (How is the experiment going :slight_smile: )

Would using ffmpeg with h264 hw encoding in a post processing script be a better option? Or is this exactly what the setting does?

I’ve performed some (limited) testing with it recently and it seems to be stable and functioning as advertised. That is, the recording is made, it is indeed transcoded in real-time during recording, and the resulting file size is lower than what the equivalent mpeg2video file would be.

My testing was performed in conjunction with another experimental feature, encoding to H.265 (HEVC). This feature was recently enabled in server versions 1.41.3.x and allows transcoding to H.265, for servers which have GPUs (integrated or dedicated) which support it.

Regarding filesize, that is impacted by the Transcode Quality setting in your DVR’s configuration, in the same place where you would enable conversion while recording. Higher transcode quality equals a larger output file… I’ve not done a great deal of testing with this; I just set it to 50 and left it.

In the past I didn’t generally recommend using conversion while recording. I experienced some issues where tuners would become “hung” due to recordings never stopping. I haven’t seen that in my recent tests (I hadn’t used the feature for a few years).

1 Like

Thanks. Have you tried the transcoding with a Post Processing Script with ffmpeg?
(I should have my new server up this weekend and plan to try both)

I plan on using Quality 99 as my DVRs will be deleted after watching and I just want the Direct Stream to my Roku.

I’ve not done much with post-processing scripts to be honest. I played around with them a bit out of curiosity. I don’t really have any specific information to share.

I know at one point only one script could be running at a time. So if you had two recordings end at the same time, access to the script needed to be serialized by implementing some sort of locking on entry into the script. I’m not sure if this is still the case, however.

As I side note, I started a test recording when I replied earlier. It should be ending in about five minutes or so. I’ll follow up after that.

I just recorded ~44 minutes of an episode of Stargate SG-1 which I’d originally recording without using conversion. The original recording is the full 60 minutes.

Original recording:
Output codec - MPEG2VIDEO
Container - Transport Stream (.ts)
Audio codec - AC3 (Stereo)
Resolution - 480i
Final file size - 743 MB

New, with convert while recording:
Output codec - HEVC
Container - Transport Stream (.ts)
Audio codec - AC3 (Stereo)
Resolution - 480p (it was apparently de-interlaced while recording)
Final file size - 397 MB

Even with the difference in recording time, there appears to be a fairly decent file size savings. (Halving the original would give ~371.5 MB, which is not that far off of the converted version.)

This was with the Transcode Quality set to 50, so I don’t know how much you’ll save on file size with it set to 99.

One other quick note: I noticed that the original I recorded had closed captions; the new one with conversion did not. I don’t know if that’s an artifact of the conversion or if they just weren’t present in the broadcast for some reason.

I’m going to record another full episode in about 40 minutes with the quality set to 99 to have a more apples-to-apples comparison.


[Edit]
@Tony_T For the full hour recording, with conversion to HEVC and quality set to 99, the final recording was 1.14 GB in size. This is compared to the original MPEG2VIDEO recording which is 778 MB in size. (To my eyes the perceived quality is identical between my earlier recording at 50 versus 99.)

I’m performing a final test in about 10 minutes which will be the same, but converting to H.264 instead of HEVC. The HEVC encoding work in PMS is still ongoing, so there may be some other factors at play affecting the results above; clearly an MPEG2 being converted to HEVC resulting in a near double file size is undesirable.

1 Like

I’ve just completed the test with conversion to H.264 instead of HEVC. Transcode Quality still set to 99. Original recording file size is 815 MB; the new recording is 1.53 GB.

So, to see a file size decrease, you’ll need to adjust the quality down. I didn’t perceive any quality difference between 99 and 50 using HEVC, but my eyes aren’t what they used to be.

1 Like

I’m not too concerned about the file size as I delete after watching, but I’m surprised at the large increase at 99.
Anyway, looks like I will be using the Plex settings. Not sure why they still have it as “experimental”

Thanks,

1 Like

I was reading this thread with interest and thought I’d have a little experiment with the demands on my N100. It looks like I was able record and HW encode (HEVC) 1 DVR TV show and stream a transcoded show to my Roku stick without any problem. If I wanted to record another show at the same time with HW encoding enabled, the show streaming on the Roku stick would fail due to lack of resources from the N100.

Interestingly, if I turned off hardware accelerated video encoding for DVR it worked much better and I was able to continue watching the show on the Roku whilst recording and encoding (HEVC) 2 live TV streams.

I know this comment isn’t strictly on topic but I thought it was interesting enough to share.

This is a very interesting observation, thank you for sharing!

I’ve done some more testing this morning. I think this is going to be highly dependent upon the client being used to view the live TV stream. For example, I started recordings for 3 channels (being transcoded to HEVC with a quality of 25) and then attempted to view live TV with 2 different clients: Plex Web and Plex for Mac Desktop.

With Plex Web, it failed to start with a generic playback failed error. This is presumably because it needed to transcode MPEG2.

With the Plex for Mac app, it was able to play the same channel without issues. The app supports MPEG2, so no transcoding was required.

For what it’s worth, this Plex server is running on Ubuntu 22.04 LTS on a Jasper Lake-based Celeron (N5105). So, Gen11 Intel graphics. It’s pretty capable, but it’s no N100. Running intel_gpu_top showed ~30% utilization of the Video engine while doing these 3 recordings (though it did spike to around 50% occasionally).

1 Like

I’ve not done much with post-processing scripts to be honest. I played around with them a bit out of curiosity. I don’t really have any specific information to share.

Got my NUC up and running.
Testing the Plex DVR Settings for hw encode while recording,
I’m also testing hw encoding with a Post Processing Script, but while this script works when I test it, once I place it in the Scripts Directory, it won’t run (a sw encoding script does work):

Any idea why this isn’t working for me:

#!/bin/bash

inFile="$1"
outFile="${inFile%.*}.mkv"

ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i "$inFile" -map 0 -c:v h264_vaapi -c:a copy "$outFile"

Found the error, just need to find out why this only occurs when in the Plex Script directory:

[AVHWDeviceContext @ 0x60fa83689a00] Failed to initialise VAAPI connection: -1 (unknown libva error).
Device creation failed: -5.
 
No device available for decoder: device type vaapi needed for codec mpeg2video.

Found the solution (with ChatGPT)

Needed to add:
export LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri

Full Post Processing Script with hw encoding:

#!/bin/bash

# Plex DVR Post Processing

export LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri
inFile="$1"
outFile="${inFile%.*}.mkv"

# Hardware encode:
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i "$inFile" -map 0 -c:v h264_vaapi -c:a copy "$outFile"
rm "$inFile"

Also got quicksyc working with sudo apt install libmfx-gen1.2, but I’m getting better results with vaapi, so I’m sticking with that.

1 Like

Glad you got it figured out. I’m not very experienced using FFMPEG on the command-line, so I’m not sure I’d have gotten you there :slight_smile: .

Took awhile but now that I can do the hw encode in a post processing script I have more flexibility than using the DVR Settings (didn’t really like that it was transcoding while recording, I prefer to do it after). HW Transcoding on the NUC is working very fast. So far I’ve only done limited tests and I’m going to record the 3 Late Night Shows Monday, so I’ll have 3 concurrent streams recording. I’ll also continue testing the Convert Video While Recording w/hw Plex settings to compare (I’ll have to remember to turn that off when the post processing script is active).

Cool, the post-processing script will definitely provide more flexibility, at the potential cost of complexity. But that is a one-time cost (mostly).

Are you handling locking/serialization to access the script? I’m curious if that’s still necessary. I think I mentioned it above, but it used to be the case that Plex could only post-process one recording at a time.

Sounds like you’re getting things set up in a way that’s going to work for you. It’s been fun to play with this stuff again, so thanks for raising the topic!

P.S. I’d love to see your post-processing script once it’s finalized. No pressure. I’ve been on a bit of a Python kick lately and I’ve playing around converting some stuff from other languages as mini challenges.

I’ve been using sw in post processing for awhile (but not too long, just installed an OTA a few months ago), and never locked the script (but I know what you mean, I’ve seen that mentioned),. I did have a few missed recordings, but that was probably due to my using a Pi5 server. Now with the NUC and hw encoding, I don’t expect to miss any recordings.

P.S. I’d love to see your post-processing script once it’s finalized. No pressure. I’ve been on a bit of a Python kick lately and I’ve playing around converting some stuff from other languages as mini challenges

The one I posted above is working and final. If I make any adjustments, I’ll post here.

Thanks!

I started playing with the settings in my DVR recordings and found that using Transcode Quality set to 25 gave me good-quality pictures for live TV and decent file size. However what I found strange is that using the hw encoding at Transcode Quality 25, the file size is the same for HEVC encoding and H.264 encoding. I was expecting a smaller file size in HEVC at the same perceived quality. I’m using an Nvidia GPU with NVENC. Can anyone else validate if this is the same situation for you?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.