PlexDVR post processing script - Comcut, CCextractor and FFmpeg

livetv-dvr

#1

So I modified a post processing script here - forums.freenas.org/index.php?threads/plex-dvr-commercial-skipping-with-comskip.46081/page-2
to get what i wanted. I'm funning on Debian 8.5 and this assumes mpeg-2 ts files. It will still run on h264 pre-encoded files but you will need the beta nonfree version of comskip or it will be much slower due to 30fps limitation

Using ffmpeg allows me to get passthrough of audio and mux in closed captions. Also allows experimentation with Nvenc quicksync and AMD hardware h265 encoding with simple changes in script commands when calling ffmpeg.

Script flow is:
create lockfile
executes comcut
ccextractor to pull out closed captions and convert to srt file
Encode to h264 using ffmpeg and combine in srt file from previous step
Remove srt file
Overwrite original ts recording
delete lockfile

Depends on: ccextractor, comskip, comcut/(can also use comchap instead to not cut stuff out), ffmpeg and a created comskip.ini file. Adjust your directories and ffmpeg encoding options to taste. CRF is left at ffmpeg default of 23. I've since adjusted it by adding -crf 21 to ffmpeg encode line


#2

Is this working for you, I use MCE Buddy to do the same?


#3

Yes it is working perfectly so far. I didnt care for mcebuddy when i tested it with nextpvr but whatever tool works. This is just really clean and streamlined way to do it. I really wanted to do everything inside linux directly. I have to run windows in virtualbox and just dont care for it. Windows needs a lot more handholding to stay running smoothly in my experiences. Im looking for long uptime and easy maintenance. Plus ive been using lunux for 12 years now in my servers so really comfortable with command line


#4

@ShottotheDome said:
It will still run on h264 pre-encoded files but you will need the beta nonfree version of comskip or it will be much slower due to 30fps limitation

Could you please explain this further? How did you build comskip on Debian to be the donation version? I see the git for it here but feel like I am missing a couple of steps. And thank you for this script!

edit: looks like the comskip author says the git is the full version. I am working through your script and having a hard time figuring out where the comcut executable should be after building (got it built from source OK) or where the ini comes from.


#5

@ShottotheDome you should create a git repository for your script; maybe add your comskip.ini etc.

this guy has a pretty good python version but bash is nice :wink:


#6

Love the idea, but it looks like the script copies the created mkv with subs back to original file so it would have ts extension but actually be an mkv container. Or am I missing something?


#7

Yes so far got it working but the script outputs in TS format instead of MKV did anyone figure this out?


#8

I can see that the output file should be MKV container “set tmpEncode = “$1.mkv”” the output file is “”$tmpEncode"". So does that mean the extension is .ts but the actual container is MKV. Also are the subs copied to file or are they burned into the encoded video?


#9

Does anyone know how I could copy the srt file to the same directory plex places the encoded video?


#10

I managed to edit the script by ShottotheDome, thank you for that. I changed a couple of things:

  • Deleted some unnecessary variables - tmp file to hold the encoded file.
  • Removes the .ts from filename.ts.mkv
  • Added timestamp to log file - I wanted to know how long encoding takes.
  • Setup a temp directory to move the raw files just in case something goes wrong - every week all files are deleted. <- you need to setup a cronjob if you go with this option.

If you want delete the raw simply replace “mv “$origFile” /tmp/” with “rm -f “$origFile””.
Also play around with the FFMPEG setting if want faster encoding or better quality. I found the setting to be best for my case.

Remember to change the path to FFMPEG, comchap, etc…


#11

So for some reason when i run the script: ./post filename it works fine but when plex runs the post.sh script it does not run FFMPEG. Anyone get any ideas?