summaryrefslogtreecommitdiff
path: root/freenect-server.sh
blob: 27d3fd38694dff15ddb6b567a59398fd8e3a4d7b (plain)
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
#!/usr/bin/env bash
# Copyright 2016 Luke Shumaker

PATH="$PATH:$(dirname -- "$0")"

t="$(mktemp -d --tmpdir "${0##*/}.XXXXXXXXXX")"

mkfifo $t/video.rgb24
mkfifo $t/depth.rgb24
mkfifo $t/video.mjpg
mkfifo $t/depth.mjpg

( freenect-server--kinect -v $t/video.rgb24 -d $t/depth.rgb24; echo "EXITED: freenect-server--kinect: $?") & pids+=($!)
( freenect-server--http 5800 $t/video.mjpg $t/depth.mjpg; echo "EXITED: freenect-server--http: $?") & pids+=($!)
rm -f {depth,video}.{avi,mjpg}
( ffmpeg -loglevel warning -pixel_format rgb24 -s 640x480 -f rawvideo -i $t/video.rgb24 -q:v 1 -f mpjpeg - > $t/video.mjpg; echo "EXITED: ffmpeg video: $?") & pids+=($!)
( ffmpeg -loglevel warning -pixel_format rgb24 -s 640x480 -f rawvideo -i $t/depth.rgb24 -q:v 1 -f mpjpeg - > $t/depth.mjpg; echo "EXITED: ffmpeg depth: $?") & pids+=($!)

cleanup() {
	kill -- "${pids[@]}" 2>/dev/null
	rm -rf -- "$t"
}
trap cleanup EXIT

wait