# Simultaneous Post Processing Scripts Fail

**URL:** <https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716>\
**Category:** Live TV & DVR\
**Tags:** server-linux\
**Created:** [April 1, 2020, 12:47am UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716 "2020-04-01T00:47:38Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nebhead](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/nebhead/32/93809_2.png) [@nebhead](https://forums.plex.tv/u/nebhead)\
**Post date:** [April 1, 2020, 12:47am UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/1 "2020-04-01T00:47:38Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![nebhead](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/nebhead/32/93809_2.png) [@nebhead](https://forums.plex.tv/u/nebhead)\
**Post date:** [April 1, 2020, 3:59am UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/2 "2020-04-01T03:59:14Z")

</div>

Found a duplicate issue on the forums that had gone unanswered, from last year here: [Post Processing - Simultaneous TV shows](https://forums.plex.tv/t/post-processing-simultaneous-tv-shows/401146)

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

Thanks!

---

<div class="post-metadata">

**Author:** ![wrender](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@wrender](https://forums.plex.tv/u/wrender)\
**Post date:** [April 1, 2020, 3:44pm UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/3 "2020-04-01T15:44:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cedarrapidsboy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/cedarrapidsboy/32/183658_2.png) [@cedarrapidsboy](https://forums.plex.tv/u/cedarrapidsboy)\
**Post date:** [May 5, 2020, 1:15pm UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/4 "2020-05-05T13:15:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nebhead](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/nebhead/32/93809_2.png) [@nebhead](https://forums.plex.tv/u/nebhead)\
**Post date:** [May 5, 2020, 2:07pm UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/5 "2020-05-05T14:07:38Z")

</div>

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](https://github.com/nebhead/PlexPostProc)

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

---

<div class="post-metadata">

**Author:** ![cedarrapidsboy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/cedarrapidsboy/32/183658_2.png) [@cedarrapidsboy](https://forums.plex.tv/u/cedarrapidsboy)\
**Post date:** [May 5, 2020, 2:48pm UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/6 "2020-05-05T14:48:22Z")

</div>

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):

> [@DVR Post Process Transcoding MPEG2/TS to h264/MKV w/ NVENC Acceleration](https://forums.plex.tv/t/dvr-post-process-transcoding-mpeg2-ts-to-h264-mkv-w-nvenc-acceleration/582781):
>
> Server Version#: 1.19.2.2737 Player Version#: 4.32.2 The Plex (Pass) DVR allows for recording of OTA broadcasts via various tuner devices. In my experience (in NA), these devices simply capture the ATSC MPEG2 stream and drop it on the disk in a TS file format (some tuner devices may support their own real-time transcoding – not mine). MPEG2/TS is a pretty fat format and takes up a good amount of disk space (11 Mbps for some ATSC channels). Goal: Upon recording completion, automatically conver…

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:

```auto
#!/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.

---

<div class="post-metadata">

**Author:** ![cedarrapidsboy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/cedarrapidsboy/32/183658_2.png) [@cedarrapidsboy](https://forums.plex.tv/u/cedarrapidsboy)\
**Post date:** [May 5, 2020, 3:27pm UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/7 "2020-05-05T15:27:25Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![cedarrapidsboy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/cedarrapidsboy/32/183658_2.png) [@cedarrapidsboy](https://forums.plex.tv/u/cedarrapidsboy)\
**Post date:** [May 5, 2020, 6:14pm UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/8 "2020-05-05T18:14:48Z")

</div>

@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:

```auto
   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

```

---

<div class="post-metadata">

**Author:** ![nebhead](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/nebhead/32/93809_2.png) [@nebhead](https://forums.plex.tv/u/nebhead)\
**Post date:** [May 5, 2020, 7:05pm UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/9 "2020-05-05T19:05:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nebhead](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/nebhead/32/93809_2.png) [@nebhead](https://forums.plex.tv/u/nebhead)\
**Post date:** [May 5, 2020, 7:15pm UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/10 "2020-05-05T19:15:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cedarrapidsboy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/cedarrapidsboy/32/183658_2.png) [@cedarrapidsboy](https://forums.plex.tv/u/cedarrapidsboy)\
**Post date:** [May 5, 2020, 7:17pm UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/11 "2020-05-05T19:17:21Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [August 3, 2020, 7:17pm UTC](https://forums.plex.tv/t/simultaneous-post-processing-scripts-fail/565716/12 "2020-08-03T19:17:23Z")

</div>

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