-
Notifications
You must be signed in to change notification settings - Fork 4
/
gsttwich.sh
executable file
·204 lines (183 loc) · 6.96 KB
/
gsttwich.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
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
## Run with any argument to enable sound recording /rec.sh s
#SAVE Twich stream key to ~/.twitch.key or twitch.key
OPTIND=1
DNUM=0
BELAGIOBIN="/usr/bin/omxregister-bellagio"
GST="gst-launch-1.0"
GSTIN="gst-inspect-1.0"
VAENC="vaapiencode_h264"
if [[ "$GSTIN | grep vaapih264enc >/dev/null" ]]
then VAENC="vaapih264enc"
else
VAENC="vaapiencode_h264"
fi
##FPS
FPS="25/1"
MONITOR_H=$(xrandr | grep '*'|head -1| awk '{print $1}' | awk -Fx '{print $1}')
MONITOR_W=$(xrandr | grep '*'|head -1| awk '{print $1}' | awk -Fx '{print $2}')
M_H=$(($MONITOR_H - 1))
M_W=$(($MONITOR_W - 1))
URL="rtmp://live.justin.tv/app/"
FOUT=" flvmux streamable=true name="muxer" "
REC=""
#FORMAT I420 or NV12
FORMAT="I420"
VIDEOCONV="! videoconvert "
##Software
ENCODER="! x264enc speed-preset=faster qp-min=30 tune=zerolatency ! video/x-h264,stream-format=byte-stream,profile=main ! h264parse "
##OMX
OMX="! omxh264enc ! video/x-h264,stream-format=byte-stream,profile=main ! h264parse "
##VAAPI
VAAPI="! $VAENC dct8x8=true ! video/x-h264,stream-format=byte-stream,profile=high ! vaapiparse_h264 config-interval=2 "
SENC="! voaacenc bitrate=128000 ! aacparse"
#SOUND SOURCE
##pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2
##alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
##alsa_input.usb-Sonix_Technology_Co.__Ltd._Trust_Webcam-02-Webcam.analog-mono
SINPUT=$(pacmd list | sed -n "s/.*<\(.*\\.monitor\)>/\\1/p" | head -1)
# Find stream key
if [ -f ~/.twitch.key ]; then
ECHO_LOG=$ECHO_LOG"\nUsing global twitch key located in home directory"
TKEY=$(cat ~/.twitch.key)
else
if [ -f ./twitch.key ]; then
ECHO_LOG=$ECHO_LOG"\nUsing twitch key located in current running directory"
TKEY=$(cat ./twitch.key)
else
echo "Could not locate ~/.twitch.key or twitch.key"
exit 1
fi
fi
function show_help {
echo "Run with
-n for nogui mode /rec.sh -n=v for vaapi; -n=o for omx; -n=x for x264enc
-x nubmer of x-server /rec.sh -x 0
-h show help message"
}
while getopts "h?n:x:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
x) DNUM="$OPTARG"
echo "X-server nubmer $DNUM"
;;
n) NOGUI=$OPTARG
echo "Nogui mode"
case "$NOGUI" in
=v)
if [[ "$GSTIN | grep $VAENC >/dev/null" ]]
then ENCODER="$VAAPI "
VIDEOCONV="! vaapipostproc format=i420"
echo "Using $VAENC encoder"
REC="$GST -e ximagesrc display-name=:$DNUM use-damage=0 startx=0 starty=0 endx=$M_H endy=$M_W ! video/x-raw,format=BGRx,framerate=$FPS $VIDEOCONV ! video/x-raw,format=$FORMAT,framerate=$FPS $ENCODER ! multiqueue ! $FOUT pulsesrc device-name=$SINPUT ! audio/x-raw,channels=2 ! multiqueue $SENC ! multiqueue ! muxer. muxer. ! progressreport name="Rec_time" ! queue leaky=downstream ! rtmpsink location=$URL$TKEY"
#echo $REC
eval $REC
exit 0
else echo "Gstreamer $VAENC not found"
exit 0
fi
;;
=o)
if [ -f $BELAGIOBIN ];
then
$BELAGIOBIN
else
echo "omxregister-bellagio not found"
fi
if [[ '$GSTIN | grep omxh264enc >/dev/null' ]]
then ENCODER="$OMX"
FORMAT="NV12"
echo "Using omxh264enc encoder"
REC="$GST -e ximagesrc display-name=:$DNUM use-damage=0 startx=0 starty=0 endx=$M_H endy=$M_W ! video/x-raw,format=BGRx,framerate=$FPS $VIDEOCONV ! video/x-raw,format=$FORMAT,framerate=$FPS $ENCODER ! multiqueue ! $FOUT pulsesrc device-name=$SINPUT ! audio/x-raw,channels=2 ! multiqueue $SENC ! multiqueue ! muxer. muxer. ! progressreport name="Rec_time" ! queue leaky=downstream ! rtmpsink location=$URL$TKEY"
#echo $REC
eval $REC
exit 0
else echo "Gstreamer omxh264enc not found"
exit 0
fi
;;
=x)
ENCODER="! x264enc speed-preset=faster qp-min=30 tune=zerolatency "
REC="$GST -e ximagesrc use-damage=0 startx=0 starty=0 endx=$M_H endy=$M_W ! video/x-raw,format=BGRx,framerate=$FPS $VIDEOCONV ! video/x-raw,format=$FORMAT,framerate=$FPS $ENCODER ! multiqueue ! $FOUT pulsesrc device-name=$SINPUT ! audio/x-raw,channels=2 ! multiqueue $SENC ! multiqueue ! muxer. muxer. ! progressreport name="Rec_time" ! queue leaky=downstream ! rtmpsink location=$URL$TKEY"
#echo $REC
eval $REC
exit 0
;;
*)
echo "Use n=v for vaapi; n=o for omx; n=x for x264enc"
exit 0
;;
esac
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
function ENC {
#DI=`kdialog --menu "CHOOSE ENCODER:" 1 "Radeon OMX" 2 "Intel VAAPI" 3 "SOFTWARE";`
DI=`zenity --list --title="CHOOSE ENCODER" \
--text="CHOOSE ENCODER:" \
--column="#" --column="Encoder" --column="" \
1 Amd "omx(vce) encoder" \
2 Intel "vaapi encoder" \
3 Software "Software x264 edcoder" `
if [ "$?" = 0 ]; then
case "$DI" in
1)
if [ -f $BELAGIOBIN ];
then
$BELAGIOBIN
else
echo "omxregister-bellagio not found"
fi
if [[ '$GSTIN | grep omxh264enc >/dev/null' ]]
then ENCODER="$OMX"
FORMAT="NV12"
echo "Using omxh264enc encoder"
else echo "Gstreamer omxh264enc not found"
fi;;
2)
if [[ "$GSTIN | grep $VAENC >/dev/null" ]]
then ENCODER="$VAAPI "
VIDEOCONV="! vaapipostproc format=i420"
echo "Using $VAENC encoder"
else echo "Gstreamer $VAENC not found"
fi;;
3)
ENCODER="! x264enc speed-preset=faster qp-min=30 tune=zerolatency"
echo "Using software encoder";;
*)
#ENCODER="! x264enc speed-preset=superfast"
echo "Using software encoder"
;;
esac
fi
}
function DIAL {
#VID=`kdialog --menu "CHOOSE RECORD MODE:" A "FULL SCREEN REC" B "WINDOW REC";`
VID=`zenity --list --title="CHOOSE RECORD MODE" \
--text="Mode:" \
--column="#" --column=""\
Fullscreen "Fullscreen recording" \
Window "Windows recording"`
if [ "$?" = 0 ]; then
if [ "$VID" = A ]; then
REC="$GST -e ximagesrc display-name=:$DNUM use-damage=0 startx=0 starty=0 endx=$M_H endy=$M_W ! video/x-raw,format=BGRx $VIDEOCONV ! video/x-raw,format=$FORMAT,framerate=$FPS $ENCODER ! multiqueue ! $FOUT pulsesrc device-name=$SINPUT ! audio/x-raw,channels=2 ! multiqueue $SENC ! multiqueue ! muxer. muxer. ! progressreport name="Rec_time" ! queue leaky=downstream ! rtmpsink location=$URL$TKEY"
elif [ "$VID" = B ]; then
if which xwininfo >/dev/null; then
XID=`xwininfo |grep 'Window id' | awk '{print $4;}'`
REC="$GST -e ximagesrc display-name=:$DNUM xid=$XID use-damage=0 ! video/x-raw,format=BGRx $VIDEOCONV ! video/x-raw,format=$FORMAT,framerate=$FPS $ENCODER ! multiqueue ! $FOUT pulsesrc device-name=$SINPUT ! audio/x-raw,channels=2 ! multiqueue $SENC ! multiqueue ! muxer. muxer. ! progressreport name="Rec_time" ! queue leaky=downstream ! rtmpsink location=$URL$TKEY"
else
echo "install xwininfo";
fi
else
echo "ERROR";
fi;
fi;
}
ENC
DIAL
echo $REC
eval $REC