-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplex_pp.sh
More file actions
52 lines (41 loc) · 1.48 KB
/
plex_pp.sh
File metadata and controls
52 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /bin/bash
#
# Plex DVR Postprocessing
# Version 0.0.1
# twitter.com/thatvirtualboy
# www.thatvirtualboy.com
#
# FIRST, RUN COMCUT TO REMOVE COMMERCIALS, THEN TRANSCODE AND COMPRESS
lockFile='/tmp/dvrProcessing.lock'
inFile="$1"
tmpFile="$1.mp4"
dvrPostLog='/tmp/dvrProcessing.log'
handbrake=/PATH/TO/YOUR/INSTALL (mine is /usr/bin/HandBrakeCLI)
cut=/PATH/TO/YOUR/COMCUT/INSTALL (mine is /home/ryan/comchap/comcut)
function timestamp {
echo $(date '+%Y-%m-%d %H:%M:%S')
return 1
}
echo $(timestamp) "Plex DVR Postprocessing script started" | tee $dvrPostLog
# Check if post processing is already running
while [ -f $lockFile ]
do
echo $(timestamp) "$lockFile' exists, sleeping processing of '$inFile'" | tee -a $dvrPostLog
sleep 10
done
# Create lock file to prevent other post-processing from running simultaneously
echo $(timestamp) "Creating lock file for processing '$inFile'" | tee -a $dvrPostLog
touch $lockFile
# Run comcut
echo $(timestamp) "Comcut started on '$inFile'" | tee -a $dvrPostLog
$cut "$inFile"
# Encode file to MP4 with handbrake-cli
echo $(timestamp) "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 $(timestamp) "File rename started" | tee -a $dvrPostLog
mv -f "$tmpFile" "$inFile"
#Remove lock file
echo $(timestamp) "All done! Removing lock for '$inFile'" | tee -a $dvrPostLog
rm $lockFile
exit 0