Dvr post processing script help

This a linux computer running plex 3.69.1

I put a postprocessing script in the dvr settings, but I can’t it to run or do anything. This is what the logs look like:

Sep 15, 2018 22:31:30.263 [0x7feed53ff700] DEBUG - Job running: '/full/path/to/script.sh' '/full/path/to/plex/tv/.grab/a29ec49011b6c5c2997b8f8eb1cc080f7662aa12/show name.ts'
Sep 15, 2018 22:31:30.266 [0x7feed53ff700] DEBUG - Jobs: Starting child process with pid 15414
Sep 15, 2018 22:31:30.292 [0x7feed23ff700] DEBUG - Jobs: '/full/path/to/script.sh' exit code for process 15414 is 0 (success)
Sep 15, 2018 22:31:30.292 [0x7feed53ff700] DEBUG - DVR:Recorder: Postprocessing script '/full/path/to/my/script.sh' was successful in 0.0 seconds. Nicely done.

Now obviously, it cannot have actually done anything in 0.0 seconds.

My first version of the script was written to output to a temp file then replace the input file, like this:

#!/bin/bash
FILENAME=$1 
TEMPFILENAME="$(mktemp)" # Temporary File for transcoding

ffmpeg -i "$FILENAME" -f lavfi -i "movie=$FILENAME[out0+subcc]" -map 0 -map 1:s -c:a copy -c:s srt -c:v libx265 -crf 23 -preset faster -f matroska "$TEMPFILENAME"

rm -f "$FILENAME" && mv -f "$TEMPFILENAME" "${FILENAME%.ts}.mkv"

Since that exits immediately according to the log, I tried outputting to stdout, because I figured that plex might be executing this as part of a pipeline:

#!/bin/bash
FILENAME=$1

ffmpeg -i "$FILENAME" -f lavfi -i "movie=$FILENAME[out0+subcc]" -map 0 -map 1:s -c:a copy -c:s srt -c:v libx265 -crf 23 -preset faster -f matroska pipe:1

That had the same result though. The scripts “finish” immediately. I ran the first version manually against one of the TV shows again. And that took a while because it was actually doing its job.

The only difference I can see between when the script ran from plex vs me running it manually, is that plex provides what looks like a temporary file as its argument, whereas I specified the location of the recorded show after plex moved it. And I don’t know if that’s a lead or not.

Any help is appreciated if anyone knows how to get this working and actually encoding.

I got this working for myself. The problem is that dependencies’ versions in Plex’s library are not compatible the ffmpeg that I have installed. (Maybe one is newer than the other – I don’t know because I’m not going to look into it now that it is working)

So here is my complete, working script:

#!/bin/bash
 
(
FILENAME=$1     # %FILE% - Filename of original file
TEMPFILENAME="$(mktemp)" # Temporary File for transcoding
LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
export LD_LIBRARY_PATH
 
ffmpeg -y -i "$FILENAME" -f lavfi -i "movie=$FILENAME[out0+subcc]" -map 0 -map 1:s -c:a copy -c:s srt -c:v libx265 -crf 23 -preset faster -f matroska "$TEMPFILENAME"
 
rm -f "$FILENAME" && mv -f "$TEMPFILENAME" "${FILENAME%.ts}.mkv"
)
 
exit 0

Just a couple things I want to point out:

  1. I am loading my default library path for my system. This may be different for other people.
  2. I’m wrapping most of the code inside parentheses, which creates a subshell because that will prevent the library setting from interfering with Plex’s parent process.

I hope this helps.

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