Project

General

Profile

Tvheadend post recording scripts » History » Version 10

Adam Sutton, 2012-08-23 10:35

1 9 ruud -
2
h1. Post recording scripts
3
4 1 Hein Rigolo
On this page you can find a number of (proposed) post recording scripts that you could use to process the Tvheadend recording.
5
6 9 ruud -
7
h2. post recording basics
8
9 2 Hein Rigolo
In the DVR configuration page you can specify a "Post-processor command". This can be reference to any program/script that tvheadend will run after the recording has been finished. In order to make it possible to give the program/script some information about the recording that has just finished you can use some variables to build up the actual command that will be executed. Here is the extract from the Tvheadend help page:
10 1 Hein Rigolo
11 9 ruud -
*Post-processor command*
12 2 Hein Rigolo
 Command to run after finishing a recording. The command will be run in background and is executed even if a recording is aborted or an error occurred. Use the %e error formatting string to check for errors, the error string is empty if recording finished successfully.
13
14 9 ruud -
<pre>
15 3 Hein Rigolo
 Support format strings:
16
    Format	Description					Example value
17
    %f		Full path to recording				/home/user/Videos/News.mkv
18
    %b		Basename of recording				News.mkv
19
    %c		Channel name					BBC world
20
    %C		Who created this recording			user
21 1 Hein Rigolo
    %t		Program title					News
22 3 Hein Rigolo
    %d		Program description				News and stories...
23 1 Hein Rigolo
    %S		Start time stamp of recording, UNIX epoch	1224421200
24 2 Hein Rigolo
    %E		Stop time stamp of recording, UNIX epoch	1224426600
25 1 Hein Rigolo
    %e          Error message                                   Aborted by user
26 9 ruud -
</pre>
27 1 Hein Rigolo
28 6 Anonymous
Example usage: /path/to/ffmpeg -i %f -vcodec libx264 -acodec copy "/path/with white space/%b"
29 1 Hein Rigolo
You need to use quotes or escape white spaces if you want white spaces in an argument.
30
31 9 ruud -
32
h2. possible uses
33
34 1 Hein Rigolo
The post-processor command can be used to start anything, like in the example about you could use it to transcode the recording to an other format, or anything else you would like. Here we will list some options. Some are complete scripts, others are just thoughts that need to be worked out further.
35
36
37 9 ruud -
h3. Commercial Flagging
38
39
[[span(*Work in Progress*, style=color: red; font-size: 100%)]]
40
41 2 Hein Rigolo
Tvheadend does not have it's own build in commercial flagging tool. This was done on purpose because Tvheadend wants to concentrate on the recording and streaming side and leave any post processing to applications/scripts that are much better at this. This means that in order to detect and possibly remove commercials you will need to use seperate programs.
42 1 Hein Rigolo
43 9 ruud -
One of the most known commercial detection programs is the one included with [[MythTV]]: mythcommflag. This program can also be run as a stand alone tool to detect and flag commercials in valid MPEG files. At the moment Tvheadend does not record directly to MPEG, but it is using the MKV container.
44 1 Hein Rigolo
45
A possible be script would do these steps:
46 9 ruud -
* recode the MKV to a MPEG-TS file
47
* Flag commercials to a cut list
48
* remove the suggested frames from the mpeg-ts
49 2 Hein Rigolo
50
flagging the commercials using mythcommflag could possibly be done like this:
51 9 ruud -
* use the "--file filename" option to point to the mpeg file
52
* use the "--gencutlist" option to generate a new cutlist for the file
53
* use the undocumented "--outputfile FILE " option to dump the cutlist to a file
54 2 Hein Rigolo
55 1 Hein Rigolo
removing the commercials from the file could posisbly be done by mythtranscode. This needs further investigation, because it looks that mythtranscode does not have an option to specify a cutlist from a file. It expects the cutlist to be available in the mythtv database (which we do not have ofcourse)
56
57
What about prospect of recording everything on specified channels/transponders then afterwards specifying channel name and in and out points to cut it up?
58 5 Anonymous
59
60 9 ruud -
h4. Flagging with Comskip.exe
61
62
63
Tvheadend can be used with Comskip and Wine (Please note that in order to keep your system as clean as possible you only need to install the wine-core package). However, due to "a/v sync problems":http://forum.xbmc.org/showpost.php?p=602568&postcount=894 with recordings and comskip I needed to use the following to convert recordings into a format comskip can decode: 
64
<pre>
65 5 Anonymous
ffmpeg -v 10 -i "%f" -vcodec mpeg2video -sameq -acodec copy -f vob -copyts "title.mpg"
66 9 ruud -
</pre>
67 5 Anonymous
68
As %b contains .mkv you will need to use a script to achieve the output filename (title.mpg). 
69
70
Here's a script which I made for the purpose of transcoding and then running comskip.exe on the resulting file:
71
72 9 ruud -
<pre>
73 5 Anonymous
#!/bin/sh
74
75
# Variables
76
MKVVIDEO=$1	#Full path to recording				/home/user/Videos/News.mkv
77
b=$2		#Basename of recording				News.mkv
78
c=$3		#Channel name					BBC world
79 8 ruud -
C=$4		#Who created this recording			user
80 5 Anonymous
t=$5		#Program title					News
81
d=$6		#Program description				News and stories...
82
S=$7		#Start time stamp of recording, UNIX epoch	1224421200
83
E=$8		#Stop time stamp of recording, UNIX epoch	1224426600
84
b=$(echo "$b" | sed "s/....$//")    # Remove file ext (4 char)
85
MKVPATH=$(echo "$MKVVIDEO" | sed "s/....$//")    # Remove file ext (4 char)
86
87
TRANSCODEPATH='~/Videos/TranscodedRecordings/'					# EDIT
88
EDLFILE="$TRANSCODEPATH$b.edl"
89
COMSKIPPATH="c:/Program Files/comskip80_032/comskip.exe"			# EDIT
90
COMSKIPLOGS="/home/nick/.wine/dosdevices/c:/Program Files/comskip80_032/logs/"	# EDIT
91
92
MPGVIDEO=$TRANSCODEPATH$b".mpg"	# Add new extention to filename
93
94
/bin/sync	# flush diskbuffer
95
96
# Transcode to mpg
97
echo "*****" >/var/log/tvheadendpp.log
98
echo "*****" >>/var/log/tvheadendpp.log
99
echo "Starting Transcode to .mpg" >>/var/log/tvheadendpp.log
100
echo "*****" >>/var/log/tvheadendpp.log
101
echo "***** INPUT = $MKVVIDEO *****" >>/var/log/tvheadendpp.log
102
echo "***** OUTPUT = $MPGVIDEO *****" >>/var/log/tvheadendpp.log
103
echo "*****" >>/var/log/tvheadendpp.log
104
/usr/bin/whoami >>/var/log/tvheadendpp.log	# for debugging purposes, who is running this script?
105
/bin/date >>/var/log/tvheadendpp.log
106
echo "*****" >>/var/log/tvheadendpp.log
107
echo "*****" >>/var/log/tvheadendpp.log
108
109
ffmpeg -v 10 -i "$MKVVIDEO" -vcodec copy -acodec copy "$MPGVIDEO" </dev/null >>/var/log/tvheadendpp.log 2>&1	
110
111
echo "*****" >>/var/log/tvheadendpp.log
112
echo "*****" >>/var/log/tvheadendpp.log
113
114
115
echo "Starting Commercial Flagging" >>/var/log/tvheadendpp.log
116
echo "*****" >>/var/log/tvheadendpp.log
117
echo "***** INPUT = "$MPGVIDEO" *****" >>/var/log/tvheadendpp.log
118
echo "***** OUTPUT = "$EDLFILE" *****" >>/var/log/tvheadendpp.log
119 1 Hein Rigolo
echo "*****" >>/var/log/tvheadendpp.log
120
/usr/bin/whoami >>/var/log/tvheadendpp.log	# for debugging purposes, who is running this script?
121 5 Anonymous
/bin/date >>/var/log/tvheadendpp.log
122 1 Hein Rigolo
echo "*****" >>/var/log/tvheadendpp.log
123
echo "*****" >>/var/log/tvheadendpp.log
124 5 Anonymous
125
wine "$COMSKIPPATH" "$MPGVIDEO" </dev/null >>/var/log/tvheadendpp.log 2>&1 
126 1 Hein Rigolo
127
echo "*****" >>/var/log/tvheadendpp.log
128
echo "*****" >>/var/log/tvheadendpp.log
129 5 Anonymous
130
# Move Comskip Log File
131
echo "Moving Log file to '$COMSKIPLOGS$b.log'" </dev/null >>/var/log/tvheadendpp.log 2>&1 
132
133
mv "$TRANSCODEPATH$b.log" "$COMSKIPLOGS"
134
135
# Move .edl back to MKV Path
136
echo "Copying edl file to '$MKVPATH.edl'" </dev/null >>/var/log/tvheadendpp.log 2>&1 
137
cp "$EDLFILE" "$MKVPATH.edl"
138
139
echo "EDL for $MKVVIDEO:" >>/var/log/tvheadendpp.log
140
141 9 ruud -
echo "Finished at @date@" >>/var/log/tvheadendpp.log
142
</pre>
143 5 Anonymous
144
Use the following in Tvheadend 
145 9 ruud -
<pre>
146 5 Anonymous
/path/to/script.sh %f %b
147 9 ruud -
</pre>
148 5 Anonymous
149
It is by no means complete or the best way to achieve this. It is just the best I could put together with the limited information I could find. I am looking forward to discussion and improvement in achieving commercial flagging with comskip as the results I have seen have been very good but the processing time is long due to having to transcode the recordings first.
150
151 9 ruud -
152
h4. Flagging with Mythcommflag
153
154 1 Hein Rigolo
Despite supposedly being possible, I was unable to get mythcommflag to work with the -skipdb option. It would work with recordings which it had in mythtv's database but renaming and using the same file with the -skipdb option would result in an empty edl. I am open to suggestions in this area too.