Tuesday, November 28, 2017

Plex DVR Postprocessing Script

I've been using Plex DVR the last couple months, testing the Plex Pass and Beta capabilities, and figuring ways to make it a solid solution for me and my family. The DVR aspect works well on the latest Beta release, and the GUI is very simple to use. Setting up recordings and having them auto-added to my library works almost like magic.

But amidst the magic, I had some requirements that took more than out-of-the-box configuration. My two requirements were

  1. Remove commercials
  2. Reduce the final file size while preserving quality
Through lots of trial and error (lots), I was able to provide Plex with a script that takes care of both of these requirements. This script is provided to Plex via its path on the server in the DVR settings of the web console. Here, you can see I have added the script plex_pp.sh

The Plex Pass beta build mentioned above introduced commercial cutting natively within the Plex GUI. For those just starting out with Plex DVR, this is a fantastic addition they've added, and will greatly reduce the technical challenges of implementing it yourself. This newly built-in feature is still, however, in beta and may come with some unwanted bugs.

This script is a combination of information found online and tweaks for my needs (my household is mostly Apple products, hence the transcoding presets). All of this is maintained on my GitHub page, so check there for the latest bits.

My Environment (not earth shattering by ANY means)

  • PMS (latest Plex Pass Beta) running on a virtual Ubuntu 16.04
  • 4vCPU / 2GB RAM
  • AMD A-10 6800k APU in host running Windows 10 Pro
  • HDHomeRun Connect Tuner


  1. Comcut
    1. Comskip
    2. ffmpeg
  2. Handbrake-CLI
This script is used to run comcut on completed Plex DVR recordings, then transcode them using handbrake with the Apple TV 1080p preset.

Shout out
Original inspiration for this script came from this post

  • Be sure to change permissions on the .sh file, something like chmod 777 or u+x
  • Edit the script to put the paths to your Comcut and Handbrake-CLI locations. I've included mine as examples within the script
#! /bin/bash
# Plex DVR Postprocessing
# Version 0.0.1
# twitter.com/thatvirtualboy
# www.thatvirtualboy.com


time=`date '+%Y-%m-%d %H:%M:%S'`
handbrake=/PATH/TO/YOUR/INSTALL (mine is /usr/bin/HandBrakeCLI)
cut=/PATH/TO/YOUR/COMCUT/INSTALL (mine is /home/ryan/comchap/comcut)

echo "'$time' Plex DVR Postprocessing script started" | tee $dvrPostLog

# Check if post processing is already running
while [ -f $lockFile ]
    echo "'$time' $lockFile' exists, sleeping processing of '$inFile'" | tee -a $dvrPostLog
    sleep 10

# Create lock file to prevent other post-processing from running simultaneously
echo "'$time' Creating lock file for processing '$inFile'" | tee -a $dvrPostLog
touch $lockFile

# Run comcut
echo "'$time' Comcut started on '$inFile'" | tee -a $dvrPostLog
$cut "$inFile"

# Encode file to MP4 with handbrake-cli
echo "'$time' Transcoding started on '$inFile'" | tee -a $dvrPostLog
$handbrake -i "$inFile" -o "$tmpFile" --preset="Apple 1080p30 Surround" --encoder-preset="veryfast" -O

# Overwrite original ts file with the transcoded file
echo "'$time' File rename started" | tee -a $dvrPostLog
mv -f "$tmpFile" "$inFile"

#Remove lock file
echo "'$time' All done! Removing lock for '$inFile'" | tee -a $dvrPostLog
rm $lockFile

exit 0

Once the recording is complete, the script will kickoff and get to work on the file before adding it to the Plex library. While the script is running, you'll see that the recording sits at a 100% complete status until it's done.

If you have two shows recording back-to-back, this script will also process one recording at a time, to not tax your system.

I hope you find this useful. Thanks for reading!

Tuesday, November 14, 2017

Using Ubuntu 17.10 For Work

While my MacBook Pro was in the shop (that issue-riddled machine) I found myself in need of a substitute. The iPad Pro is great for quick bursts of productivity and for trips, but for work requiring 8 hours of sitting down at a desk, you just can't find a replacement for a mouse and keyboard.

I had a 2009 white MacBook in my garage running Linux Mint that was used for garage things, you know, playing classic rock, YouTube, etc. I decided to take it in, install the latest Ubuntu 17.10 on it and see how easy it would be to get by doing my day to day work.

I'm not missing macOS at all
After reading the news several months ago that Ubuntu was ditching Unity for GNOME 3, I thought, "Oh great, they're replacing a bad DE with an even worse one." However, I've been pleasantly surprised at the usability of Ubuntu 17.10, and dare I say, I've actually really enjoyed using it. I'm not missing macOS at all. The minimalist and streamlined top panel works great to show me the system info I need. Desktop notifications are front and center without getting in the way.
Once I configured a proper theme (took all of 5 minutes using GNOME Tweaks) I was ready to go. It's strange saying this, but Ubuntu 17.10 feels like the mashup of Windows 10 and macOS that I've always wanted. Between the system's Activities (mission control) screen, Application Drawer, and multi-monitor support, everything works in a way that makes sense and is a joy to use.
Ubuntu 17.10 feels like the mashup of Windows 10 and macOS that I've always wanted.
One example is having multiple Firefox windows open. In macOS, if all these windows are minimized, clicking the Firefox icon on the dock will maximize just one of the windows, causing me to have to right click the icon and figure out which window I meant to maximize. Ubuntu 17.10 handles this way better. When I click on the icon in the dock, instead of picking a random window to maximize, it shows me a preview of the open windows to ensure I open the desired one. Seems small enough, but it makes a big difference in your workflow.

Ok, I brought his thing inside to do work... Luckily, we use our very own Workspace ONE at VMware as well as an O365 subscription allowing access to the full Office suite from the browser, so almost all of my work could be done right in Firefox.
There were scenarios where the full PowerPoint exe was necessary, as well as Skype for Business, and that's where our internal Horizon View VDI came into play, again, completely accessible from Firefox.
All in all, I feel comfortable saying that Ubuntu 17.10 is the best Ubuntu yet. Now if only we can get Linux working on the latest MacBook Pros!

Follow by Email