This is my first whack at a Post Processing script for the TVHeadend DVR software.
It has it’s faults but it does work. I have future ambitions of creating a script complete with commercial removal and .nfo file generation for the Plex Media Server and Kodi (XBMC) to pick up.
So without further ado here’s a script that takes recording from TVHeadend and transcodes it to an h264/AAC mp4 file using the “Normal” preset in Handbrake(CLI).
************************************************************************
In the Post Processing configuration of TVHeadend I have this line:
/home/hts/Convert %f %t %S
That executes my bash script I created called “Convert” in the home directory of TVHeadend (/home/hts/) on Ubuntu and passes in the Full file name and path (%f), the title of the show (%t) and the Unix time stamp of the start of the recording %S.
************************************************************************
And here’s the contents of Convert:
#!/bin/bash
# $1 Full File Name with path (%f)
# $2 Show name without path or extension (%t)
# $3 Unix time-stamp for recording start (%S)
# Convert Unix time-stamp to YYYY-MM-DD.HH-MM-SS set to variable $t using perl
t=$(perl -e “use POSIX qw(strftime); print POSIX::strftime(‘%Y-%m-%d.%H-%M-%S’, localtime($3))”);
###################################################
# Encode with Handbrake.
# Change to Output path is needed here for your setup.
# Also you can remove -X 720 from the command to keep the full resolution.
# I’m scaling to max width 720 (480P) as my server is only running an Intel
# Core-2-Duo and doing this affords me about 60fps encoding speed.
# Which is a 1:1 on 720P content (1hr show takes an hour to encode).
###################################################
HandBrakeCLI -i “$1″ -o “/path/to/output/folder/$2.$t.MP4″ -X 720 –preset=”Normal”
#delete original file after transcoding.
rm -f $1
************************************************************************
One downfall to this is that since the last line deletes the original recording without updating the TVHeadend database the next time you login to TVHeadend it will show the recording as a failed recording with a missing file. You could of course delete that line and keep the original file too.