Simultaneous Post Processing Scripts Fail

Server Version#: 1.19.1.2589
Player Version#: NA
Tuner Make/Model: HDHomeRun Quatro (latest)
Guide/Lineup name: Built-in
Using XMLTV?: No
Channel number/Name: NA

I’ve duplicated an issue where simultaneous post-processing scripts will fail due to Plex removing the temporary recording folder/files in .grab after one of the scripts is completed. More information in the thread on github: https://github.com/nebhead/PlexPostProc/issues/15

I believe this may be a bug in how Plex manages (or doesn’t manage) simultaneous scripts that are running. My theory is that it just does it’s clean-up of the temporary .grab folders after the first script completes, disregarding the other scripts that are running.

Would be great to get one of the Ninja’s or dev’s to look into this.

Easy to duplicate. The easiest way I found to test was just go into the DVR Guide, and click to record two different shows, then click cancel on each of them. When you cancel them they execute the post process script.

Then just watch the destination folder you set with something like watch -n 1 ls -la .grab

1 Like

Found a duplicate issue on the forums that had gone unanswered, from last year here: Post Processing - Simultaneous TV shows

Hopefully just more data for the devs to look at here.

Thanks!

I am seeing the same issue…The first script runs and exits. Then the .grab file for the second steam suddenly disappears.

The postprocessing script option is a great feature in Plex if it would work correctly.

1 Like

Agreed that this seems broken. My post processing started failing when I added two new tuners (total 3). I can’t seem to capture any errors, however. I have my script command output piping to a tmp file. It isn’t getting created. The post process seems to be failing before it executes the script.

So, I’ve managed to cobble together a fix that seems to be working for me, but I didn’t seem to work for @wrender in this thread. Basically, it pauses itself and waits for any other pending scripts to complete before end the script. Your mileage may vary, but you can give it a try here: https://github.com/nebhead/PlexPostProc

Hopefully Plex will fix this one day so we don’t have to do this workaround.

1 Like

Wow. I like your script. I’m gonna steal it and try on my end. I like your BASH a lot better than my elementary effort. I did use the built-in transcoder in my BASH to avoid needing any extra installs (in a docker container):

I like your locking approach. I’ll give it a go in my test script… but I’m perplexed why even my rudimentary script is failing to generate a tmp log file:

#!/bin/bash

tmpfile=$(mktemp /tmp/dummy_log.XXXXX)

echo $@ > $tmpfile

3 tuners ending at the same time do not generate a single log file. Script is in the new recommended location. TMP directory rwx for plex:plex.

UPDATE: My simple script above had an empty line before the #!. that was its problem. Now on to the transcoding script… and it is working now. I believe I had compounding issues that didn’t necessarily concern the multiple tuners.

  1. When I added the extra tuners, I think I gave my Plex docker container a restart. This pulled the next Plex version that enforced the Scripts be in a new location (unknown to me).
  2. As I was troubleshooting the postprocessing failures from the script location change, I may have copy + pasted script content into the file and inserted a blank line before the #!. This caused the transcode error to return an exit code 8.

Just had a successful NVDEC/NVENC transcode of 3 simultaneous programs as they all ended at the same time (2x SD, 1xHD).

I still intend to adapt your script framework into my NVENC transcode to spruce the place up a bit.

Thanks!

@nebhead, two successful runs of 3-simultaneous post processes. So, looks like I’m in a better place now.

I did steal your code and extend it to use the built-in Plex Transcoder (for NVENC acceleration). Here’s the added clause:

   elif [[ $ENCODER == "nvtrans" ]]; then
     export FFMPEG_EXTERNAL_LIBS="$(find ~/Library/Application\ Support/Plex\ Media\ Server/Codecs/ -name "libmpeg2video_decoder.so" -printf "%h\n")/"
     check_errs $? "Failed to convert using smart Plex Transcoder (NVENC). libmpeg2video_decoder.so not found."
	 export LD_LIBRARY_PATH="/usr/lib/plexmediaserver:/usr/lib/plexmediaserver/lib/"

     # Grab some dimension and framerate info so we can set bitrates
     HEIGHT="$(/usr/lib/plexmediaserver/Plex\ Transcoder -i "$FILENAME" 2>&1 | grep "Stream #0:0" | perl -lane 'print $1 if /, \d{3,}x(\d{3,})/')"
     FPS="$(/usr/lib/plexmediaserver/Plex\ Transcoder -i "$FILENAME" 2>&1 | grep "Stream #0:0" | perl -lane 'print $1 if /, (\d+(.\d+)*) fps/')"

     if [[ -z "${HEIGHT}" ]]; then
	   # Failed to get dimensions of source... try a dumb transcode.
	   /usr/lib/plexmediaserver/Plex\ Transcoder -y -hide_banner -hwaccel nvdec -i "$FILENAME" -s hd$RES -c:v h264_nvenc -preset veryfast -c:a copy "$TEMPFILENAME"
	   check_errs $? "Failed to convert using simple Plex Transcoder (NVENC)."
	 else
	   # Smart transcode based on source dimensions and fps
       # Bitrate vlaues (Mb). Assuming 1080i30 (ATSC max) has same needs as 720p60
       # Assuming 60 fps needs 2x bitrate than 30 fps
       MULTIPLIER=$(echo - | perl -lane "if (${FPS} < 59) {print 1.0} else {print 2.0}")
       ABR=$(echo - | perl -lane "if (${HEIGHT} < 720) {print 1*${MULTIPLIER}} elsif (${HEIGHT} < 1080) {print 2*${MULTIPLIER}} else {print 4*${MULTIPLIER}}")
       MBR=$(echo - | perl -lane "print ${ABR} * 1.5")
       BUF=$(echo - | perl -lane "print ${MBR} * 2.0")
       /usr/lib/plexmediaserver/Plex\ Transcoder -y -hide_banner -hwaccel nvdec -i "$FILENAME" -c:v h264_nvenc -b:v "${ABR}M" -maxrate:v "${MBR}M" -profile:v high -bf:v 3 -bufsize:v "${BUF}M" -preset:v hq -forced-idr:v 1 -c:a copy "$TEMPFILENAME"
	   check_errs $? "Failed to convert using smart Plex Transcoder (NVENC)."
	 fi

This is outstanding! I think I’ll definitely grab this. I didn’t even know this was possible (using the embedded transcoder).

OK, updated the github repo with your change. Thanks again!

@nebhead, it took a bit to figure out how it worked. But, it is just a re-badged FFMPEG. I’m using the NVDEC/NVENC options.

Also, FFMPEG_EXTERNAL_LIBS is needed to be set for it to work.

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