Normalise JSON. Update todo
[PreCom.git] / stream.sh
1 #!/bin/bash
2
3 while getopts "p:s:" opt; do
4 echo "$opt" >> /tmp/someopts
5 echo "$OPTARG" >> /tmp/someopts
6 case $opt in
7 p)
8 obs_profile="$OPTARG"
9 ;;
10 s)
11 obs_scene="$OPTARG"
12 ;;
13 \?)
14 echo "Invalid option: -$OPTARG" >&2
15 exit 1
16 ;;
17 :)
18 echo "Option -$OPTARG requires an argument." >&2
19 exit 1
20 ;;
21 esac
22 done
23 key_re="([a-zA-Z0-9_]+?)[[:space:]]*="
24 value_re="=[[:space:]]*(.+?)"
25
26 while IFS='' read -r line || [[ -n $line ]]; do
27 [[ "$line" =~ $key_re ]] && key=${BASH_REMATCH[1]}
28 [[ "$line" =~ $value_re ]] && value=${BASH_REMATCH[1]}
29
30 if [[ ! -z "$key" ]] && [[ ! "${key}xxx" = "xxx" ]] && [[ ! -z "$value" ]] && [[ ! "${value}xxx" = "xxx" ]]; then
31 eval $key=$value
32 fi
33 done < "/itg/PreCom/stream_parameters.txt"
34
35 dos2unix /mnt/shares/itg-repo/CaptureInfo.txt > /dev/null 2>&1
36
37 line1=$(sed -n "1p" "/mnt/shares/itg-repo/CaptureInfo.txt")
38 line2=$(sed -n "2p" "/mnt/shares/itg-repo/CaptureInfo.txt")
39
40 OLDIFS=$IFS
41 IFS=', ' read -a v1coords <<< "$line1"
42 IFS=', ' read -a v2coords <<< "$line2"
43 IFS=$OLDIFS
44
45 /usr/local/bin/ffmpeg -y -f x11grab -r "$framerate" -i 0:0 -f video4linux2 -i /dev/video0 -itsoffset 0.1 -f alsa -i "plughw:CARD=${device},DEV=0" -filter_complex \
46 "[0:v]setpts=PTS-STARTPTS+${video_offset}/TB,scale=$((v1coords[2])):$((v1coords[3])),pad=1280:720:$((v1coords[0])):$((v1coords[1])):black[v1];[1:v]setpts=PTS-STARTPTS,scale=$((v2coords[2])):$((v2coords[3]))[v2]; [v1][v2]overlay=$((v2coords[0])):$((v2coords[1]))" \
47 -f flv -vcodec libx264 -g "$framerate" -keyint_min "$framerate" -b "$video_bitrate" -minrate "$video_bitrate" -maxrate "$video_bitrate" -pix_fmt yuv420p -preset ultrafast -tune film -threads 2 -s 1280:720 \
48 -strict experimental -bufsize "$video_bitrate" -ar "$audio_bitrate" /itg/stream.mp4 > /dev/null 2>&1 &
49
50 #if [[ -z "$stream" ]]; then
51 # case $stream in
52 # peekingboo)
53 # obs_profile="PeekingBoo-ITG"
54 # obs_scene="PeekingBoo"
55 # ;;
56 # birdymint)
57 # obs_profile="BirdyMint-ITG"
58 # obs_scene="PeekingBoo"
59 # ;;
60 # divinelegy)
61 # obs_profile="DivinElegy-ITG"
62 # obs_scene="PeekingBoo"
63 # ;;
64
65 if [[ -n "$obs_profile" ]] && [[ -n "$obs_scene" ]]; then
66 ssh PeekingBoo@192.168.0.6 'C:\Program Files\PsExec.exe -i -s "C:\Program Files (x86)\OBS\OBS.exe"' -profile "$obs_profile" \
67 -scenecollection "$obs_scene" -start > /dev/null 2>&1 &
68 fi
69
70 #XXX: Loop forever so start-stop-daemon can kill us
71 while :
72 do
73 sleep 1
74 done