Merge pull request #13 from matteodelabre/specify-output

Allow choosing the video output
This commit is contained in:
Rien 2020-04-07 11:34:50 +02:00 committed by GitHub
commit 48a7ed84c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 10 deletions

View File

@ -20,7 +20,9 @@ reMarkable screen sharing over SSH.
### Options
- `-p --portrait`: shows the reMarkable screen in portrait mode (the default is landscape mode, 90 degrees rotated tot the right)
- `-d --destination`: the ssh destination of the reMarkable (default: `root@10.11.99.1`)
- `-s --source`: the ssh destination of the reMarkable (default: `root@10.11.99.1`)
- `-o --output`: path of the output where the video should be recorded, as understood by `ffmpeg`; if this is `-`, the video is displayed in a new window and not recorded anywhere (default: `-`)
- `-f --format`: when recording to an output, this option is used to force the encoding format; if this is `-`, `ffmpeg`s auto format detection based on the file extension is used (default: `-`).
If you have problems, don't hesitate to [open an issue](https://github.com/rien/reStream/issues/new) or [send me an email](mailto:rien.maertens@posteo.be).

View File

@ -1,8 +1,10 @@
#!/bin/sh
# default values for arguments
ssh_host="root@10.11.99.1" # remarkable connected trough USB
ssh_host="root@10.11.99.1" # remarkable connected through USB
landscape=true # rotate 90 degrees to the right
output_path=- # display output through ffplay
format=- # automatic output format
# loop through arguments and process them
while [ $# -gt 0 ]; do
@ -11,13 +13,23 @@ while [ $# -gt 0 ]; do
landscape=false
shift
;;
-d | --destination)
-s | --source)
ssh_host="$2"
shift
shift
;;
-o | --output)
output_path="$2"
shift
shift
;;
-f | --format)
format="$2"
shift
shift
;;
*)
echo "Usage: $0 [-p] [-d <destination>]"
echo "Usage: $0 [-p] [-s <source>] [-o <output>] [-f <format>]"
exit 1
;;
esac
@ -59,18 +71,27 @@ fi
if [ -z "$compress" ]; then
echo "Your remarkable does not have lz4."
fallback_to_gzip
elif ! which lz4; then
elif ! lz4 -V; then
echo "Your host does not have lz4."
fallback_to_gzip
else
decompress="lz4 -d"
fi
# calculte how much bytes the window is
# list of ffmpeg filters to apply
video_filters=""
# store extra ffmpeg arguments in $@
set --
# calculate how much bytes the window is
window_bytes="$((width * height * bytes_per_pixel))"
# rotate 90 degrees if landscape=true
landscape_param="$($landscape && echo '-vf transpose=1')"
$landscape && video_filters="$video_filters,transpose=1"
# set each frame presentation time to the time it is received
video_filters="$video_filters,setpts=(RTCTIME - RTCSTART) / (TB * 1000000)"
# read the first $window_bytes of the framebuffer
head_fb0="dd if=/dev/fb0 count=1 bs=$window_bytes 2>/dev/null"
@ -78,16 +99,30 @@ head_fb0="dd if=/dev/fb0 count=1 bs=$window_bytes 2>/dev/null"
# loop that keeps on reading and compressing, to be executed remotely
read_loop="while $head_fb0; do $loop_wait; done | $compress"
set -- "$@" -vf "${video_filters#,}"
if [ "$output_path" = - ]; then
output_cmd=ffplay
else
output_cmd=ffmpeg
if [ "$format" != - ]; then
set -- "$@" -f "$format"
fi
set -- "$@" "$output_path"
fi
set -e # stop if an error occurs
# shellcheck disable=SC2086
ssh_cmd "$read_loop" \
| $decompress \
| ffplay \
| "$output_cmd" \
-vcodec rawvideo \
-loglevel "$loglevel" \
-f rawvideo \
-pixel_format gray16le \
-video_size "$width,$height" \
$landscape_param \
-i -
-i - \
"$@"