Tutorial: The Perfect PostProcess System: Beautiful SRT Subtitles, Commercials Cut, Video Hardware Converted, & NFL Games Done Right - MCEBuddy Replacement For Linux

At the end of the day, this script is for all intents and purposes a Linux replacement for MCEBuddy. Which is an awesome program and I’ve used for years, but I’m getting away from windows, so needed something else.

(NOTE:: This may look complicated, and lengthy, but I promise the results are worth it, and even though this looks long, it’ll only take about 30 min total to complete. I’ve simply tried to be very through in description to avoid confusion. )

If you’re like my house, you need subtitles on for everything. However, the embedded ones (called eia-608, that are in Live tv almost always) look terrible, and their placement often blocks key scene details. SRT files allow all kinds of customization options, require NO transcoding to display, and play on just about everything. So that’s what we want.

Another thing that comes up, is if you have subtitles set to always on, like we do here, and the video file still contains the eia-608 subs, they will be displayed first, instead of the srt’s! and on some interfaces they display as ‘Unknown’ - which my OCD cannot handle. So we’re going to remove them from the video file.

You may also realize, like I did, that the EIA-608 subs are BETTER in one aspect, that their timing with the video scene is usually dead on, so for that reason they are preferred vs trying to download subs from online sources and hoping the timing matches. Ug! PITA!

Also, since I’ve recently upgraded my server with a nice p2000, I wanted to maximize my storage by converting my files to h.265(HEVC) and I always use mkv files to keep everything nice and tidy.

Enter the script below. This relies on some tools from mvktoolnix, which I’ll get into shortly and walk you through a couple of got-cha’s when running this script for yourself.

This script is designed to be run as a post processing script on your DVR in plex. I have another script that will do all of this functionality and a LOT more coming shortly that will handle tv episodes and movies from all other sources you may use. (i.e. torrents/nzb files, ect)

Here’s a few highlights of what this does:

  • 1.Use the latest Comcut/Comskip to automatically detect (and remove) commercials from the recorded file. (I’ll walk you through building comskip from source code, it’s really easy and gives amazing results)

    1. Rip the EIA-608 subs to an srt file if they are detected in the original video file then remove the original 608’s from the video.
    1. Switch containers from .ts files to .mkv file.
    1. Convert your video automatically to ANY configuration you want using handbrake. Use the graphical interface to create a pre-set and then we’ll export it and use it for all other conversions (again I’ll walk you though this… it’s not hard at all, or you can just use my profile - set to hardware encode h.265 files)
    1. Re-merge the SRT file we created back into the MKV file we just converted.
    1. Add a metadata to the resulting MKV file so any additional scripts on your system have the ability to check for it, and not process the file again. Which when I post my Tautulli script will make sense.
    1. If desired, this will process your NFL recordings renaming them correctly, and for the correct Season and Game Number. Then Drop them into a library you specify.
    1. A process limit is incorporated, so no more than 1 file at a time will be processed. All additional calls to the script are queued for processing when the current one is finished.
    1. Remove unwanted audio and subtitle tracks from the final file. This saves space, but also keeps things nice and tidy. I found a few rare instances where a tv show would have multiple audio tracks, and using the comcut program would remove them so the resulting file had NO AUDIO! This script accounts for that correctly.
    1. Output a h.265 file (very high quality, small size) with English audio set, and srt subtitles (with perfect timing) in one mkv file. Nice, neat and it works every time!

I’ve attached the script to this post, so for those who are ready to jump in it’s all yours. I’ve written it in Python3 so this SHOULD work on any platform, but I’m sure for windows users it will require some tweaking. Linux users should be gtg as is. Just add this to the PostProcess section of DVR settings: PlexPostProcess.py


PostPorcess.zip (3.2 KB)

Now here’s a few dependencies you’ll need and how to get them done.

**NOTE: all commands are run as root so make sure you either login as root sudo -i or add sudo in front of the various commands.

First make sure you install FFmpeg using this command:
sudo apt install ffmpeg

Install the package mkvtoolsnix, (use their instructions HERE)

Ok now on to the commercial cut (which I know plex has added a while ago, but I found building this yourself from source and using the comcut code to result in a much better commercial detection/removal solution over all. YMMV.

Run this command from a prompt to install needed dependencies:

apt-get install -y autoconf libtool git build-essential libargtable2-dev libavformat-dev libsdl1.2-dev

Now build the code:
git clone git://github.com/erikkaashoek/Comskip
cd Comskip
./autogen.sh
./configure
make
make install

( if you get an error about autoconf, just apt-get install autoconf and you’ll be all set)

Now Grab a copy of ComChap/ComCut (just the zip file is fine as it’s just a bash script, nothing for us to do really but unzip it and move it to a location like /usr/local/bin)

Now we need ccextractor for extracting the subtitles to srt files. Here’s another BIG gotcha, the latest version (.88 at the time of this writing) DOES NOT work correctly with mp4 files and others. The subs come out all wrong. In my testing version .85b is ‘old reliable’ and just works perfect.
BUT if you just apt-get ccextractor you’ll get the .88 version so either check which you have or go grab the source code and build it yourself like I did, following this:

sudo apt-get install -y libglew-dev libglfw3-dev cmake gcc libcurl4-gnutls-dev tesseract-ocr libtesseract-dev libleptonica-dev
cd ccextractor/linux
./build
Now test your build
./ccextractor # this should show you info about it, and the version number. If you got that, you're all set.

Move the file ccextractor to /usr/local/bin (or wherever you want on your path)

FINAL Step: (Only needed if you want to convert your recordings to some other format, h.264/h.265 or whatever.
Grab the latest version of handbrake for windows (you do have a windows machine handy right?) and install it and open a video file you’ve got lying around. Set all the options to what you want, and then under the ‘Presets’ box click the ‘Add’ button and finish setting up and saving your preset. Once it’s saved, click on the options and select export to file. Save this file on your linux server, we’ll use it for the conversions.

If you want to simply use my preset I’ll link to it below, it’s set to use nvidia hardware encoding at h.265, a constant quality of 26, does NO cropping, deinterlaces, decombs, and auto passthroughs on audio and subtitle tracks (although the way this script is written there won’t be any subs to add, we’re going to add them back in later).

handbrake_presets.zip (1.1 KB)

Download a copy of HandbrakeCLI from here (https://handbrake.fr/downloads2.php and place it on your path, I used /usr/local/bin but anywhere you want will work fine.

Now just open the script and edit the few settings at the top. Basically telling it where to set a temporary directory and pointing it to the various program locations. Choose a language you’d like to keep, and you’ll be all set.

enjoy!
{c}guy

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