2020-02-12 13:13:14 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-04-02 14:14:36 +02:00
|
|
|
# default values for arguments
|
2023-11-14 07:14:09 -05:00
|
|
|
remarkable="${REMARKABLE_IP:-10.11.99.1}" # remarkable IP address
|
2025-01-25 21:23:52 -08:00
|
|
|
#remarkable="${REMARKABLE_IP:-10.143.0.112}" # remarkable IP address
|
2025-01-25 22:05:42 -08:00
|
|
|
landscape=true # rotate 90 degrees to the right
|
|
|
|
output_path=/dev/video5 # display output through ffplay
|
|
|
|
format=- # automatic output format
|
|
|
|
webcam=true # not to a webcam
|
|
|
|
hflip=false # horizontal flip webcam
|
|
|
|
window_title=reStream # stream window title is reStream
|
2020-03-12 00:17:13 +01:00
|
|
|
|
2020-04-03 12:15:53 +02:00
|
|
|
ssh_cmd() {
|
2020-11-01 19:21:28 +01:00
|
|
|
echo "[SSH]" "$@" >&2
|
2021-11-04 09:21:14 +01:00
|
|
|
ssh -o ConnectTimeout=1 \
|
|
|
|
-o PasswordAuthentication=no \
|
|
|
|
-o PubkeyAcceptedKeyTypes=+ssh-rsa \
|
|
|
|
-o HostKeyAlgorithms=+ssh-rsa \
|
|
|
|
"root@$remarkable" "$@"
|
2020-04-03 12:15:53 +02:00
|
|
|
}
|
2020-02-12 14:47:47 +01:00
|
|
|
|
2021-06-30 22:42:51 +02:00
|
|
|
# kill reStream on remarkable at the end.
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
exit_rm() {
|
|
|
|
ssh_cmd 'kill $(pidof restream)'
|
|
|
|
}
|
|
|
|
trap exit_rm EXIT INT HUP
|
|
|
|
|
2020-03-17 23:44:55 +01:00
|
|
|
# check if we are able to reach the remarkable
|
2020-04-03 12:15:53 +02:00
|
|
|
if ! ssh_cmd true; then
|
2021-01-28 23:11:07 +01:00
|
|
|
echo "$remarkable unreachable or you have not set up an ssh key."
|
2021-02-14 22:34:06 +01:00
|
|
|
echo "If you see a 'Permission denied' error, please visit"
|
2021-01-05 20:08:03 +01:00
|
|
|
echo "https://github.com/rien/reStream/#installation for instructions."
|
2024-01-09 17:40:41 +01:00
|
|
|
trap - EXIT
|
2020-02-12 13:13:14 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-01-04 20:54:20 -05:00
|
|
|
if ssh_cmd "[ ! -f ~/restream ] && [ ! -f /opt/bin/restream ]"; then
|
2020-12-31 14:57:33 +01:00
|
|
|
echo "The restream binary is not installed on your reMarkable."
|
|
|
|
echo "Please install it using the instruction in the README:"
|
|
|
|
echo "https://github.com/rien/reStream/#installation"
|
|
|
|
exit 1
|
2020-03-12 00:17:13 +01:00
|
|
|
fi
|
|
|
|
|
2020-04-07 11:17:45 +02:00
|
|
|
# store extra ffmpeg arguments in $@
|
|
|
|
set --
|
|
|
|
|
2025-01-25 21:23:52 -08:00
|
|
|
video_filters="colorlevels=rimin=0:rimax=29/255:gimin=0:gimax=29/255:bimin=0:bimax=29/255,transpose=3"
|
2020-03-12 00:17:13 +01:00
|
|
|
# rotate 90 degrees if landscape=true
|
2020-12-31 17:51:23 +01:00
|
|
|
$landscape && video_filters="$video_filters,transpose=1"
|
2020-03-12 00:17:13 +01:00
|
|
|
|
2020-04-14 10:46:07 +02:00
|
|
|
if $webcam; then
|
|
|
|
video_filters="$video_filters,format=pix_fmts=yuv420p"
|
2025-01-25 22:05:42 -08:00
|
|
|
format="v4l2"
|
|
|
|
|
|
|
|
# check if there is a modprobed v4l2 loopback device
|
|
|
|
# use the first cam as default if there is no output_path already
|
|
|
|
cam_path=$(v4l2-ctl --list-devices |
|
|
|
|
sed -n '/^[^\s]\+platform:v4l2loopback/{n;s/\s*//g;p;q}')
|
|
|
|
|
|
|
|
# fail if there is no such device
|
|
|
|
if [ -e "$cam_path" ]; then
|
|
|
|
if [ "$output_path" = "-" ]; then
|
|
|
|
output_path="$cam_path"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Could not find a video loopback device, did you"
|
|
|
|
echo "sudo modprobe v4l2loopback"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-30 10:25:21 +01:00
|
|
|
|
2020-04-14 10:46:07 +02:00
|
|
|
fi
|
|
|
|
|
2020-04-07 11:17:45 +02:00
|
|
|
# set each frame presentation time to the time it is received
|
|
|
|
video_filters="$video_filters,setpts=(RTCTIME - RTCSTART) / (TB * 1000000)"
|
|
|
|
|
|
|
|
set -- "$@" -vf "${video_filters#,}"
|
|
|
|
|
2020-04-02 19:32:59 +02:00
|
|
|
if [ "$output_path" = - ]; then
|
2020-04-07 10:55:20 +02:00
|
|
|
output_cmd=ffplay
|
2020-11-20 12:23:15 +01:00
|
|
|
|
|
|
|
window_title_option="-window_title $window_title"
|
2020-04-02 19:32:59 +02:00
|
|
|
else
|
2020-04-07 10:55:20 +02:00
|
|
|
output_cmd=ffmpeg
|
2020-04-02 19:32:59 +02:00
|
|
|
|
|
|
|
if [ "$format" != - ]; then
|
2020-04-07 11:17:45 +02:00
|
|
|
set -- "$@" -f "$format"
|
2020-04-02 19:32:59 +02:00
|
|
|
fi
|
|
|
|
|
2020-04-07 11:17:45 +02:00
|
|
|
set -- "$@" "$output_path"
|
2020-04-02 19:32:59 +02:00
|
|
|
fi
|
|
|
|
|
2020-03-12 00:17:13 +01:00
|
|
|
set -e # stop if an error occurs
|
2020-02-12 13:13:14 +01:00
|
|
|
|
2021-01-29 00:12:13 +01:00
|
|
|
# shellcheck disable=SC2089
|
2025-01-25 21:23:52 -08:00
|
|
|
restream_rs="PATH=\"\$PATH:/opt/bin/:.\" restream"
|
|
|
|
listen_port=16789
|
2025-01-26 10:33:13 -08:00
|
|
|
ssh_cmd "$restream_rs --port $listen_port --format mono" &
|
2025-01-25 21:23:52 -08:00
|
|
|
sleep 1 # give some time to restream.rs to start listening
|
2025-01-25 21:24:13 -08:00
|
|
|
receive_cmd="nc $remarkable $listen_port"
|
2025-01-25 21:23:52 -08:00
|
|
|
|
|
|
|
# TODO: return this from stdout
|
|
|
|
width=1872
|
|
|
|
height=1404
|
2025-01-26 10:33:13 -08:00
|
|
|
pixel_format="monob"
|
2021-01-09 00:04:22 +01:00
|
|
|
|
2021-01-29 00:12:13 +01:00
|
|
|
# shellcheck disable=SC2086,SC2090
|
2025-01-25 15:27:53 -08:00
|
|
|
$receive_cmd |
|
|
|
|
(
|
2021-06-30 11:08:05 +02:00
|
|
|
"$output_cmd" \
|
|
|
|
-vcodec rawvideo \
|
2025-01-25 21:23:52 -08:00
|
|
|
-loglevel "error" \
|
2021-06-30 11:08:05 +02:00
|
|
|
-f rawvideo \
|
|
|
|
-pixel_format "$pixel_format" \
|
|
|
|
-video_size "$width,$height" \
|
|
|
|
$window_title_option \
|
|
|
|
-i - \
|
|
|
|
"$@" \
|
|
|
|
;
|
|
|
|
kill $$
|
2021-01-08 11:05:06 +01:00
|
|
|
)
|