# Synology Post Processing Script

**URL:** <https://forums.plex.tv/t/synology-post-processing-script/730735>\
**Category:** Live TV & DVR\
**Tags:** livetv-dvr\
**Created:** [July 22, 2021, 12:14pm UTC](https://forums.plex.tv/t/synology-post-processing-script/730735 "2021-07-22T12:14:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![macowens](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@macowens](https://forums.plex.tv/u/macowens)\
**Post date:** [July 22, 2021, 12:14pm UTC](https://forums.plex.tv/t/synology-post-processing-script/730735/1 "2021-07-22T12:14:05Z")

</div>

Server Version#: 1.23.4.4805 and about to update

I use a HDHomeRun Connect to record live TV and have been struggling for a while getting a Post Processing script to run successfully, I am using FFMPEG and I believe I have it installed correctly (but I’m not 100% sure) but I consistently get “An error occurred while postprocessing the recording”  
Under DSM7.0 I have the script in /volume1/@apphome/PlexMediaServer/‘Plex Media Server’/Scripts and I again believe all the permissions are set correctly.  
I have no idea on how to troubleshoot this, can someone ‘give’ me a Synology script that will just do something simple like putting a customised message into a log file so I can prove that at least the script is being found and run?

Thanks

---

<div class="post-metadata">

**Author:** ![manish\_vallabh\_mv\_gmail\_com](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@manish\_vallabh\_mv\_gmail\_com](https://forums.plex.tv/u/manish_vallabh_mv_gmail_com)\
**Post date:** [July 22, 2021, 12:57pm UTC](https://forums.plex.tv/t/synology-post-processing-script/730735/2 "2021-07-22T12:57:13Z")

</div>

This is the script I use. It save’s a log in /volume1/Media

#!/bin/bash

# this is a shell script to call ffmpeg to transcode Plex videos to h264

dvrPostLog=‘/volume1/Media/DVRPostProcessing.log’

echo “=================================” | tee -a $dvrPostLog

[$# -ge 1 -a -f “$1”]

infile=$1

outfile=“${1%.ts}TMP.ts”

echo “`date '+%Y-%m-%d'`” | tee -a $dvrPostLog

echo “`date '+%H:%M:%S'` file ‘$1’ is opened, trying to use hardware accel.” | tee -a $dvrPostLog

echo “`date '+%H:%M:%S'` writing transcode to temp file: ‘$outfile’” | tee -a $dvrPostLog

#make sure you use the version of FFmpeg that is installed with the package. DSM ships with an older version that is default. Here is how to call the newer build explicitly, with hardware encoding flags:  
#This version directs the errors to a log file for debugging.  
/var/packages/ffmpeg/target/bin/ffmpeg -init\_hw\_device vaapi=foo:/dev/dri/renderD128 -hwaccel vaapi -hwaccel\_device foo -hwaccel\_output\_format vaapi -i “$infile” -filter\_hw\_device foo -acodec copy -vcodec h264\_vaapi -preset veryfast -loglevel info “$outfile” \> /dev/null

# finished with ffmpeg encode

echo “`date '+%H:%M:%S'` ffmpeg has finished encoding. Renamed old file to .ts” | tee -a $dvrPostLog

# remove the old file; rename the converted file to .ts bc Plex wants this.

rm -f “$infile”  
mv -f “$outfile” “$infile”

echo “`date '+%H:%M:%S'` conversion done. old file deleted. new file saved in .ts” | tee -a $dvrPostLog

M.

---

<div class="post-metadata">

**Author:** ![macowens](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@macowens](https://forums.plex.tv/u/macowens)\
**Post date:** [July 22, 2021, 1:13pm UTC](https://forums.plex.tv/t/synology-post-processing-script/730735/3 "2021-07-22T13:13:10Z")

</div>

Food for thought - but all I want at this stage is a simplified script that does no processing apart from putting a message in a log file, once I know the (correct) script is being executed (correctly) then I can start to build some functionality into it

---

<div class="post-metadata">

**Author:** ![manish\_vallabh\_mv\_gmail\_com](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@manish\_vallabh\_mv\_gmail\_com](https://forums.plex.tv/u/manish_vallabh_mv_gmail_com)\
**Post date:** [July 22, 2021, 1:34pm UTC](https://forums.plex.tv/t/synology-post-processing-script/730735/4 "2021-07-22T13:34:39Z")

</div>

Create your post processing scipt call it test.sh and stick it in

/volume1/@apphome/PlexMediaServer/‘Plex Media Server’/Scripts

Just use these two lines to create a log and the contents of the log will be “testing Log Creation”

dvrPostLog=’/volume1/Media/DVRPostProcessing.log’  
echo “testing Log creation” | tee -a $dvrPostLog

If the file gets created you know it’s working, just change the path to where you want the log to be created. mine gets created in the Media share.

M.

---

<div class="post-metadata">

**Author:** ![macowens](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@macowens](https://forums.plex.tv/u/macowens)\
**Post date:** [July 22, 2021, 1:35pm UTC](https://forums.plex.tv/t/synology-post-processing-script/730735/5 "2021-07-22T13:35:44Z")

</div>

Thank You

---

<div class="post-metadata">

**Author:** ![macowens](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@macowens](https://forums.plex.tv/u/macowens)\
**Post date:** [July 22, 2021, 2:13pm UTC](https://forums.plex.tv/t/synology-post-processing-script/730735/6 "2021-07-22T14:13:42Z")

</div>

Within Plex do you put

/volume1/@apphome/PlexMediaServer/‘Plex Media Server’/Scripts/DVRPostProcessing.sh

or just

DVRPostProcessing.sh

---

<div class="post-metadata">

**Author:** ![macowens](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@macowens](https://forums.plex.tv/u/macowens)\
**Post date:** [July 23, 2021, 9:13am UTC](https://forums.plex.tv/t/synology-post-processing-script/730735/7 "2021-07-23T09:13:39Z")

</div>

Any ideas what error or exit code 13 means?

Jul 22, 2021 14:04:58.013 [0x7f75cdc22b38] DEBUG - [Grabber/08e66cf25e04557e7d79173ddc5c0aa62bfc029a/JobRunner] Job running: ‘/volume1/@apphome/PlexMediaServer/Plex Media Server/Scripts/DVRPostProcessing.sh’ ‘/volume1/Secondary/Media/Media/TV/DVR TV/.grab/08e66cf25e04557e7d79173ddc5c0aa62bfc029a-7608c1f0c61c8ad31df23f15c8669cda7d221372/Law & Order (1990) - S10E13 - Panic.ts’  
Jul 22, 2021 14:04:58.013 [0x7f75cdc22b38] DEBUG - [Grabber/08e66cf25e04557e7d79173ddc5c0aa62bfc029a/JobRunner] Jobs: Starting child process with pid 20151  
Jul 22, 2021 14:04:58.013 [0x7f75d3014b38] DEBUG - Jobs: ‘/volume1/@apphome/PlexMediaServer/Plex Media Server/Scripts/DVRPostProcessing.sh’ exit code for process 20151 is 13 (failure)  
Jul 22, 2021 14:04:58.013 [0x7f75cdc22b38] ERROR - [Grabber/08e66cf25e04557e7d79173ddc5c0aa62bfc029a] Recorder: Postprocessing script ‘/volume1/@apphome/PlexMediaServer/Plex Media Server/Scripts/DVRPostProcessing.sh’ exited with error code 13.

I have added the ‘server-synology’ tag back in to indicate it is a Linux script.

---

<div class="post-metadata">

**Author:** ![manish\_vallabh\_mv\_gmail\_com](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@manish\_vallabh\_mv\_gmail\_com](https://forums.plex.tv/u/manish_vallabh_mv_gmail_com)\
**Post date:** [July 23, 2021, 2:18pm UTC](https://forums.plex.tv/t/synology-post-processing-script/730735/8 "2021-07-23T14:18:17Z")

</div>

I’m afraid I don’t know… usually I test the DVR scripts by SSH’ing into the Synology elevating myself to root, and running the scripts from there. Once I’m sure it’s working the last step is to put it into the GUI and test a recording.

error 13 could be permission denied but to sure…

M.

---

<div class="post-metadata">

**Author:** ![macowens](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@macowens](https://forums.plex.tv/u/macowens)\
**Post date:** [July 23, 2021, 2:38pm UTC](https://forums.plex.tv/t/synology-post-processing-script/730735/9 "2021-07-23T14:38:33Z")

</div>

Thanks again

I have SSH’d in and run the script and while it did run there was a logfile called ‘dvrProcessing.log’$’\r\r’ created which contained the line ‘testing Log creation’

---

<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:** [October 21, 2021, 2:39pm UTC](https://forums.plex.tv/t/synology-post-processing-script/730735/10 "2021-10-21T14:39:00Z")

</div>

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