This repository has been archived by the owner on Sep 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.sh
193 lines (175 loc) · 3.98 KB
/
test1.sh
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#! /bin/sh
#testcommand for media player
#parameters: command [filename] [...]
# test
# play filename xsize ysize
#return -1 if any error (no output!)
#this script is prepared for tools writing to stdout or requiring a file name
# for tools writing to stdout simple create a new convertXXX function
# that sends the tool to background and sets MPID to the pid
# for tools requiring a filename call createFifo first, then
# also create a function that sends the tool in background
# after starting the conversion tool call waitFkt, this will kill the conversion
# tool and the fifo reader if we are killed or if one of the tools finishes
#set -x
FIFO=/tmp/vdrfifo$$
log() {
echo >/dev/null
#echo "$$:`date `:$*" >> /tmp/test1.log
}
trapfkt() {
log "trap received"
if [ "$MPID" != "" ] ; then
kill $MPID > /dev/null 2>&1
kill -9 $MPID > /dev/null 2>&1
fi
if [ "$FPID" != "" ] ; then
kill $FPID > /dev/null 2>&1
kill -9 $FPID > /dev/null 2>&1
fi
if [ -p $FIFO ] ; then
rm -f $FIFO
fi
}
#create a fifo and start a cat
createFifo() {
mkfifo $FIFO >/dev/null 2>&1 || exit 1
cat $FIFO 2>&1 &
FPID=$!
}
#convert AVI to mpeg2, suing mencoder see
#http://www.wiki.csoft.at/index.php/MEncoder_Scripts
convertAVI() {
#mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:acodec=mp2:abitrate=192 $RTOP -o $FIFO $1 > /dev/null 2>&1 &
mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=5000:vbitrate=3000:keyint=15:acodec=mp2:abitrate=192 $RTOP -o $FIFO $1 > /dev/null 2>&1 &
MPID=$!
}
#convert WAV to mpeg using lame
convertWAV() {
lame -v -b 192 -S $1 - - 2>&1 &
MPID=$!
}
#convert pictures using GraphicsMagic
convertPicture(){
if [ "$2" != "" -a "$3" != "" ] ; then
fopt="-geometry ${2}x$3"
fi
gm convert $fopt "$1" jpeg:- 2>&1 &
MPID=$!
}
#cat data
catData() {
cat "$1" 2>&1 &
MPID=$!
}
#convert a playlist
#handle http:// as audio-url
convertList() {
cat "$1" 2>&1 | sed 's?^ *http:\(.*\)?/http:\1.http-audio?'
}
#get a HTTP url via wget
getHTTP() {
wget -q -O - "$1" 2>&1 &
MPID=$!
}
#wait until the cat or the converter have been stopped
waitFkt() {
while [ 1 = 1 ]
do
dokill=0
if [ "$MPID" != "" ] ; then
kill -0 $MPID >/dev/null 2>&1 || dokill=1
fi
if [ "$FPID" != "" ] ; then
kill -0 $FPID >/dev/null 2>&1 || dokill=1
fi
if [ $dokill = 1 ] ; then
log "killing MPID=$MPID FPID=$FPID"
kill -9 $MPID > /dev/null 2>&1
MPID=""
kill -9 $FPID > /dev/null 2>&1
FPID=""
fi
if [ "$FPID" = "" -a "$MPID" = "" ] ; then
log leaving waitFkt
break
fi
usleep 100000
done
exit 0
}
log started with param "$*"
if [ "$1" = "" ] ; then
echo inavlid call
exit 1
fi
trap trapfkt 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15
case $1 in
check)
exit 0
;;
play)
exts=`echo "$2" | sed 's/.*\.//'`
if [ "$exts" = "" ] ; then
exit 1
fi
fname=`echo "$2" | sed 's/\.[^.]*$//'`
case $exts in
xmpg)
#mpeg2 test
nname="$fname.mpg"
cat "$nname" &
MPID=$!
waitFkt
;;
xjpg)
#jpeg test
nname="$fname.jpg"
[ "$nname" = "" ] && exit 1
[ ! -f "$nname" ] && exit 1
convertPicture "$nname" $3 $4
waitFkt
;;
xmp3)
#mp3 test
nname="$fname.mp3"
cat "$nname" &
MPID=$!
waitFkt
;;
#real converting functions
bmp|BMP|tiff|TIFF|png|PNG)
convertPicture "$2" $3 $4
waitFkt
;;
AVI|avi)
createFifo
convertAVI "$2" $3 $4
waitFkt
;;
WAV|wav)
convertWAV "$2"
waitFkt
;;
xdir)
catData "$2"
waitFkt
;;
m3u|dir)
convertList "$2"
waitFkt
;;
http-audio)
fn=`echo "$2" | sed 's/\.[^.]*$//' | sed 's?^ */??'`
getHTTP "$fn"
waitFkt
;;
*)
exit 1
;;
esac
;;
*)
exit 1
;;
esac