Allow choosing the video output

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 <https://trac.ffmpeg.org/wiki/StreamingGuide>). This stream
can then be connected, for example, to OBS for live streaming (see
<https://connect.ed-diamond.com/Linux-Pratique/LP-096/Enrichir-sa-diffusion-de-contenus-multimedias-avec-OBS>
in French).
This commit is contained in:
Mattéo Delabre 2020-04-02 19:32:59 +02:00
parent d1fa399c86
commit 49f20074f0
No known key found for this signature in database
GPG Key ID: AE3FBD02DC583ABB
2 changed files with 38 additions and 9 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
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[@]}"