Project

General

Profile

Tvheadend post recording scripts » History » Version 7

ruud -, 2010-09-13 18:54
added wine-core

1 2 Hein Rigolo
= Post recording scripts =
2 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.
3 2 Hein Rigolo
4
== post recording basics ==
5
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:
6
7
'''Post-processor command'''
8
 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.
9
10
{{{
11 3 Hein Rigolo
 Support format strings:
12
    Format	Description					Example value
13
    %f		Full path to recording				/home/user/Videos/News.mkv
14
    %b		Basename of recording				News.mkv
15
    %c		Channel name					BBC world
16
    %C		Who created this recording			user
17
    %t		Program title					News
18 5 Anonymous
    %d		Program description				News and stories...
19 3 Hein Rigolo
    %S		Start time stamp of recording, UNIX epoch	1224421200
20 1 Hein Rigolo
    %E		Stop time stamp of recording, UNIX epoch	1224426600
21 5 Anonymous
    %e          Error message                                   Aborted by user
22 1 Hein Rigolo
}}}
23 2 Hein Rigolo
24 6 Anonymous
Example usage: /path/to/ffmpeg -i %f -vcodec libx264 -acodec copy "/path/with white space/%b"
25
You need to use quotes or escape white spaces if you want white spaces in an argument.
26 2 Hein Rigolo
27
== possible uses ==
28
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.
29
30
=== Commercial Flagging ===
31
[[span('''Work in Progress''', style=color: red; font-size: 100%)]]
32
33
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.
34
35
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.
36
37
A possible be script would do these steps:
38
 * recode the MKV to a MPEG-TS file
39
 * Flag commercials to a cut list
40
 * remove the suggested frames from the mpeg-ts
41
42
flagging the commercials using mythcommflag could possibly be done like this:
43
 * use the "--file filename" option to point to the mpeg file
44
 * use the "--gencutlist" option to generate a new cutlist for the file
45
 * use the undocumented "--outputfile FILE " option to dump the cutlist to a file
46
47 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)
48
49
What about prospect of recording everything on specified channels/transponders then afterwards specifying channel name and in and out points to cut it up?
50 5 Anonymous
51
==== Flagging with Comskip.exe ====
52
53 7 ruud -
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 [http://forum.xbmc.org/showpost.php?p=602568&postcount=894 a/v sync problems] with recordings and comskip I needed to use the following to convert recordings into a format comskip can decode: 
54 5 Anonymous
{{{
55
ffmpeg -v 10 -i "%f" -vcodec mpeg2video -sameq -acodec copy -f vob -copyts "title.mpg"
56
}}}
57
58
As %b contains .mkv you will need to use a script to achieve the output filename (title.mpg). 
59
60
Here's a script which I made for the purpose of transcoding and then running comskip.exe on the resulting file:
61
62
{{{
63
#!/bin/sh
64
65
# Variables
66
MKVVIDEO=$1	#Full path to recording				/home/user/Videos/News.mkv
67
b=$2		#Basename of recording				News.mkv
68
c=$3		#Channel name					BBC world
69
C=$4		#Who created this recording			user
70
t=$5		#Program title					News
71
c=$6		#Program description				News and stories...
72
S=$7		#Start time stamp of recording, UNIX epoch	1224421200
73
E=$8		#Stop time stamp of recording, UNIX epoch	1224426600
74
b=$(echo "$b" | sed "s/....$//")    # Remove file ext (4 char)
75
MKVPATH=$(echo "$MKVVIDEO" | sed "s/....$//")    # Remove file ext (4 char)
76
77
TRANSCODEPATH='~/Videos/TranscodedRecordings/'					# EDIT
78
EDLFILE="$TRANSCODEPATH$b.edl"
79
COMSKIPPATH="c:/Program Files/comskip80_032/comskip.exe"			# EDIT
80
COMSKIPLOGS="/home/nick/.wine/dosdevices/c:/Program Files/comskip80_032/logs/"	# EDIT
81
82
MPGVIDEO=$TRANSCODEPATH$b".mpg"	# Add new extention to filename
83
84
/bin/sync	# flush diskbuffer
85
86
# Transcode to mpg
87
echo "*****" >/var/log/tvheadendpp.log
88
echo "*****" >>/var/log/tvheadendpp.log
89
echo "Starting Transcode to .mpg" >>/var/log/tvheadendpp.log
90
echo "*****" >>/var/log/tvheadendpp.log
91
echo "***** INPUT = $MKVVIDEO *****" >>/var/log/tvheadendpp.log
92
echo "***** OUTPUT = $MPGVIDEO *****" >>/var/log/tvheadendpp.log
93
echo "*****" >>/var/log/tvheadendpp.log
94
/usr/bin/whoami >>/var/log/tvheadendpp.log	# for debugging purposes, who is running this script?
95
/bin/date >>/var/log/tvheadendpp.log
96
echo "*****" >>/var/log/tvheadendpp.log
97
echo "*****" >>/var/log/tvheadendpp.log
98
99
ffmpeg -v 10 -i "$MKVVIDEO" -vcodec copy -acodec copy "$MPGVIDEO" </dev/null >>/var/log/tvheadendpp.log 2>&1	
100
101
echo "*****" >>/var/log/tvheadendpp.log
102
echo "*****" >>/var/log/tvheadendpp.log
103
104
105
echo "Starting Commercial Flagging" >>/var/log/tvheadendpp.log
106
echo "*****" >>/var/log/tvheadendpp.log
107
echo "***** INPUT = "$MPGVIDEO" *****" >>/var/log/tvheadendpp.log
108
echo "***** OUTPUT = "$EDLFILE" *****" >>/var/log/tvheadendpp.log
109
echo "*****" >>/var/log/tvheadendpp.log
110
/usr/bin/whoami >>/var/log/tvheadendpp.log	# for debugging purposes, who is running this script?
111
/bin/date >>/var/log/tvheadendpp.log
112
echo "*****" >>/var/log/tvheadendpp.log
113
echo "*****" >>/var/log/tvheadendpp.log
114
115
wine "$COMSKIPPATH" "$MPGVIDEO" </dev/null >>/var/log/tvheadendpp.log 2>&1 
116
117
echo "*****" >>/var/log/tvheadendpp.log
118
echo "*****" >>/var/log/tvheadendpp.log
119
120
# Move Comskip Log File
121
echo "Moving Log file to '$COMSKIPLOGS$b.log'" </dev/null >>/var/log/tvheadendpp.log 2>&1 
122
123
mv "$TRANSCODEPATH$b.log" "$COMSKIPLOGS"
124
125
# Move .edl back to MKV Path
126
echo "Copying edl file to '$MKVPATH.edl'" </dev/null >>/var/log/tvheadendpp.log 2>&1 
127
cp "$EDLFILE" "$MKVPATH.edl"
128
129
echo "EDL for $MKVVIDEO:" >>/var/log/tvheadendpp.log
130
131
echo "Finished at `date`" >>/var/log/tvheadendpp.log
132
}}}
133
134
Use the following in Tvheadend 
135
{{{
136
/path/to/script.sh %f %b
137
}}}
138
139
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.
140
141
==== Flagging with Mythcommflag ====
142
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.