From 49f20074f0ff09229b21370b4a52741a10cd583e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Thu, 2 Apr 2020 19:32:59 +0200 Subject: [PATCH] Allow choosing the video output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of simply playing back the frames through `ffplay`, I thought it might be interesting to be able to record the sequence to a video file or to use it as part of a stream. I have in mind the use case of making educational videos/live streams where the tablet can be used as a kind of remote blackboard by teachers, which is especially relevant currently. But there are certainly other use cases! Changes ======= This commit adds two new options to that effect: * `-o --output`: Path of the output as understood by `ffmpeg` (usually a file name). If this is `-` (as it is by default), the existing behavior of playing the stream through `ffplay` is restored. * `-f --format`: When recording to an output, this option can be used to force the encoding format. If this is `-` (again, the default), `ffmpeg`’s auto format detection is used (based on the file extension). Because of the possible confusion between the newly added `--output` option and the existing `--destination` option for specifying the source address, I suggest renaming the `--destination` option to `--source` (this is implemented in this commit). Examples ======== Record to a file ---------------- ```sh ./reStream.sh -o remarkable.mp4 ``` Caveat: The recorded file plays back too fast. I am not sure how to fix this. Create an UDP MPEG-TS stream ---------------------------- ```sh ./reStream.sh -o "udp://127.0.0.1:1234" -f "mpegts" ``` This sends frames over UDP to the specified port using the MPEG-TS format (see ). This stream can then be connected, for example, to OBS for live streaming (see in French). --- README.md | 4 +++- reStream.sh | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d28ab54..a9aabd2 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/reStream.sh b/reStream.sh index efafff6..6e5e138 100755 --- a/reStream.sh +++ b/reStream.sh @@ -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 ]" + echo "Usage: $0 [-p] [-s ] [-o ] [-f ]" exit 1 esac done @@ -66,11 +78,13 @@ fi -# calculte how much bytes the window is +output_args=() + +# 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 && output_args+=('-vf' 'transpose=1') # read the first $window_bytes of the framebuffer head_fb0="dd if=/dev/fb0 count=1 bs=$window_bytes 2>/dev/null" @@ -78,14 +92,27 @@ 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" +if [ "$output_path" = - ]; then + output_command=ffplay +else + output_command=ffmpeg + + if [ "$format" != - ]; then + output_args+=('-f' "$format") + fi + + output_args+=("$output_path") +fi + set -e # stop if an error occurs $ssh_cmd "$read_loop" \ | $decompress \ - | ffplay -vcodec rawvideo \ + | "$output_command" \ + -vcodec rawvideo \ -loglevel "$loglevel" \ -f rawvideo \ -pixel_format gray16le \ -video_size "$width,$height" \ - $landscape_param \ - -i - + -i - \ + "${output_args[@]}"