Plex TV/DVR Postprocessing Script Synology DS418play

I’m trying to use the Postprocessing Script feature on the PlexDVR


to process the .ts files recorded from my HomeRun Quatro. I want to automatically reencode them as h.264 mp4 files using ffmpeg.

ffmpeg -i $file.ts -acodec copy -vcodec libx264 -f $file.mp4

I think this may be the right ffmpeg code to do the job, but I’m not sure of a few things.

  1. I imagine this needs to be saved in a .sh file and put on my synology, but I’m not sure of the filepaths for Synology Diskstations. I can’t seem to find that anywhere. volume1/homes/plex/filename.sh or something like that?
  2. How does it know what file to convert? Does Plex send it as an input, and if so, did I call it correctly?
  3. do I need anything other than the ffmpeg code in the sh file?

Sorry but I don’t really know what I’m doing with ffmpeg. This is a weak spot. I got everything else working through and would be super excited if this got going too.

Finally, where would I submit transcode after recording as a feature request? Presumably with the removal of commercials option encoding is done.

Mike,
I don’t support DVR/TV but did reach out to ask if there’s documentation anywhere, even in draft form.
I am sorry I didn’t see your post here in Synology until now

Thanks Chuck,

Any chance you could help me out on the Synology filepath part? What is the fullpath for a file?
See my above guess

-Mike

Sure, the Syno part is easy.

If you created a single RAID set, then everything is in /volume1/<sharename>/ (wherever you assigned).

If you have a movie, for example,

/volume1/movies/Avatar (2009)/Avatar (2009).ts

If a series,

/volume1/tv/Star Trek: Discovery/Season 1/Star Trek: Discovery - S01E01 - Battle at the binary stars.ts

The volume depends on how you provisioned the syno. If each disk is JBOD, then Disk 1 = volume1, Disk2 = volume2, etc

Thanks Chuck, Also, I apparently put this in General rather than Plex Features. I have re-tagged it and hopefully I’ll get support from someone on the LiveTV/DVR team

Because I couldn’t find it anywhere else, I wanted to make sure I posted the solution (lots and lots of trial and error)

And the DVRPostprocessing.sh file reads as follows:

#!/bin/bash
[ $# -ge 1 -a -f “$1” ]
ffmpeg -i “1" -acodec copy -vcodec libx264 "{1%.ts}.mp4”
rm “$1”

This converts the mpeg2 video in the ts file to h.264 and repackages the file as an mp4. It worked perfectly but it does take a LONG time on a DS418play. A 5 min test file (I started the recording with 5 min left in the episode) took about 17 min to convert. I’m now considering dropping the additional $130 to return my 418play and upgrade to the DS918+ which has a quad core processor. But this should work on either.

Actually, I added an additional parameter to the ffmpeg line and it’s MUCH faster now. Not as good compression, but still under of the 50% the ts files

#!/bin/bash
[ $# -ge 1 -a -f “$1” ]
ffmpeg -i “$1” -acodec copy -vcodec libx264 -preset superfast “${1%.ts}.mp4”
rm “$1”

Quality across the preset can vary though it’s generally the same. The file size increases with the faster encoding though.

ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo

1 Like

Hi @mikesssbb

I’ve look for this a million times and this is the first time I “think” I understand what to do, in order to get PostProcessing to work. Thank you for sharing your findings (and frustrations) :wink:

So I’ve installed the ffmpeg package on my Synology DS918+ through the package source “https://packages.synocommunity.com/

And now need to write the processing script, but with a slightly different setup.

My DVR recordings is from a HomeRun HD Expand through Cable, which typically outputs recordings into:
1080i H264
MP2 Stereo

I want the format to be
1080p H264
AAC

So my question to you is:

  1. Do I need anything else in my setup (ffmpeg and .sh script) to be able to PostProcess DVR recordings?

  2. How would I change your script to fit my needs? Is it as simple as this:

#!/bin/bash
[ $# -ge 1 -a -f “$1” ]
ffmpeg -i “$1” -c:a aac -b:a 192k -vcodec libx264 -preset superfast “${1%.ts}.mp4”
rm “$1”
  1. Still missing how to convert to 1080p?

Again, Thanks alot :slight_smile:
.Søren

I’m honestly not sure because I haven’t had any need to convert 1080i to 1080p. You could possibly use tinterlace or MBAFF encoding mode, but I’m honestly not sure because I haven’t played around with it.
Also, I would give you a warning, check your frame rate and frames vs fields. It’s very possible that it will mess with your frame rate when you convert from fields to frames or vice versa. This can cause your video to get laggy or reduce motion flow.
The only example I saw (on a quick search) of deinterlacing 1080i was https://cweiske.de/tagebuch/deinterlacing-1080i.htm
It looks like he solved his issue with ffmpeg so scroll down to that section.

I fiddle around with it last night with ALOT of trial and error - never before have I made Unix Shell file OR worked with ffmpeg… so I have many things to learn :wink:

Initially I got the script to work, but with a 0 byte file size output.. bummer.

I used your setup -that worked- and have now made a variant incl. a log-file etc.

#!/bin/bash
dvrPostLog='/volume2/Plex/dvrProcessing.log'
echo "=================================" | tee -a $dvrPostLog
[ $# -ge 1 -a -f "$1" ]
echo "`date '+%Y-%m-%d'`" | tee -a $dvrPostLog
echo "`date '+%H:%M:%S'` file '$1' is opened" | tee -a $dvrPostLog
ffmpeg -i "$1" -acodec copy -vcodec libx264 -preset superfast "${1%.ts}.mp4"
echo "`date '+%H:%M:%S'` conversion done. new file saved" | tee -a $dvrPostLog

A interesting part here:
My source video is often 1080i H264 and if I just did ‘-vcodec copy’ I of course got the exact same format in the MP4. But when I did your ‘-vcodec libx264’ the output format is set to 1080p H264 – which I aimed for. At least that is what Plex is showing

File size is also (as expected) reduced. Sometimes only 25% but in my test, I’ve seen up to 75%

====
My next step is to fiddle with cpulimit in order to reduce the workload on my DS918+ CPU.

1 Like

@sorenhlaursen If you want stream, with no convert (ex ipad…) and want limitation cpu :
ffmpeg -i "$1" -f matroska -threads 1 -acodec aac -strict -2 -vcodec libx264 -preset ultrafast "${1%.ts}.mkv"

Thanks for the insight on how to limit CPU usage with thread, I now have this setup which works partial to my needs. output is 1080p MP2 audio.

ffmpeg -i "$1" -threads 1 -acodec copy -vcodec libx264 -preset superfast "${1%.ts}.mp4"

Every time i do anything else than acodec copy i get and MP4 on 0 bytes. somethings go wrong, and I can’t seem to figure out what.

I’ve tried

-acodec aac
-c:a aac -b:a 160k
-acodec aac -strict experimental
-acodec mp3

It’s no big issue for now, since some streams I get from cable is AC3 which Plex can direct stream for some of my devices (or easily transcode on the fly) - but I would LOVE to get better performance on multiple streams and instead maybe schedule PostProcessing at night time.

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