Merge pull request #18 from beardhatcode/master

Add video4linux2 support
This commit is contained in:
Rien 2020-04-14 11:57:51 +02:00 committed by GitHub
commit 057e90721d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 1 deletions

View File

@ -24,6 +24,7 @@ reMarkable screen sharing over SSH.
- `-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: `-`).
- `-w --webcam`: record to a video4linux2 web cam device. By default the first found web cam is taken, this can be overwritten with `-o`. The video is scaled to 1280x720 to ensure compatibility with MS Teams, Skype for business and other programs which need this specific format.
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).
@ -33,12 +34,13 @@ On your **host** machine:
- Any POSIX-shell (e.g. bash)
- ffmpeg (with ffplay)
- ssh
- Video4Linux loopback kernel module if you want to use `--webcam`
On your **reMarkable** nothing is needed, unless you want...
### Sub-second latency
To achieve sub-second latency, you'll need [lz4](https://github.com/lz4/lz4)
To achieve sub-second latency, you'll need [lz4](https://github.com/lz4/lz4)
on your host and on your reMarkable.
You can install `lz4` on your host with your usual package manager. On Ubuntu,
@ -53,6 +55,30 @@ Copy the `lz4` program to your reMarkable with
`scp lz4.arm.static root@10.11.99.1:/home/root/lz4`, make it executable with
`ssh root@10.11.99.1 'chmod +x /home/root/lz4'` and you're ready to go.
### Video4Linux Loopback
To set your remarkable as a webcam we need to be able to fake one. This is where the Video4Linux loopback kernel module comes into play. We need both the dkms and util packages. On Ubuntu you need to install:
```
apt install v4l2loopback-utils v4l2loopback-dkms
```
In some package managers `v4l2loopback-utils` is found in `v4l-utils`.
After installing the module you must enable it with
```
modprobe v4l2loopback
```
To verify that this worked, execute:
```
v4l2-ctl --list-devices
```
The result should contain a line with "platform:v4l2loopback".
## Troubleshooting
Steps you can try if the script isn't working:

View File

@ -5,6 +5,7 @@ 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
webcam=false # not to a webcam
# loop through arguments and process them
while [ $# -gt 0 ]; do
@ -28,6 +29,27 @@ while [ $# -gt 0 ]; do
shift
shift
;;
-w | --webcam)
webcam=true
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
shift
;;
-h | --help | *)
echo "Usage: $0 [-p] [-s <source>] [-o <output>] [-f <format>]"
echo "Examples:"
@ -36,6 +58,7 @@ while [ $# -gt 0 ]; do
echo " $0 -s 192.168.0.10 # connect to different IP"
echo " $0 -o remarkable.mp4 # record to a file"
echo " $0 -o udp://dest:1234 -f mpegts # record to a stream"
echo " $0 -w # write to a webcam (yuv420p + resize)"
exit 1
;;
esac
@ -96,6 +119,23 @@ window_bytes="$((width * height * bytes_per_pixel))"
# rotate 90 degrees if landscape=true
$landscape && video_filters="$video_filters,transpose=1"
# Scale and add padding if we are targeting a webcam because a lot of services
# expect a size of exactly 1280x720 (tested in Firefox, MS Teams, and Skype for
# for business). Send a PR is you can get a heigher resolution working.
if $webcam; then
video_filters="$video_filters,format=pix_fmts=yuv420p"
if $landscape; then
render_width=$((720 * height / width))
else
render_width=$((720 * width / height))
fi
# center
offset_left=$(((1280 - render_width) / 2))
video_filters="$video_filters,scale=${render_width}x720"
video_filters="$video_filters,pad=1280:720:$offset_left:0:#eeeeee"
fi
# set each frame presentation time to the time it is received
video_filters="$video_filters,setpts=(RTCTIME - RTCSTART) / (TB * 1000000)"