jeffpiazza / derbynet

Open-source Pinewood Derby race management, built around a web server and database
MIT License
98 stars 72 forks source link

Replay Kiosk on Raspberry Pi problems #104

Open Blackbird714 opened 4 years ago

Blackbird714 commented 4 years ago

I have a Raspberry Pi 4 configured with a Logitech C615 webcam. After much fiddling I finally was able to get the photostand.sh script to capture photos -- I found that there were two issues:

  1. the resolution sent to fswebcam was higher than the camera could handle (1920x1080p, changed to 1280x720 in fswebcam.conf)
  2. had to add a config parameter to skip frames (skip 20)

Without those adjustments, the camera just captured a black image.

This device will play double duty; once checkins are done, I'm trying to get it act as the Replay Kiosk during the race. I installed guvcview, and the video capture works fine in that X11 app.

I have reviewed the SSL/security notes /wrt the browser, and I think I've followed the guidance there. Using Chromium on the RPI, I (sometimes) see the device name as HD Webcam C615 (xxxx:xxxx) but the preview is always black. Using Firefox, the Device name shows as Default Video Device, but the preview is just cycling colors, no image. The behavior makes me think that the capture is attempting to use bad settings for the camera, like what I was seeing with fswebcam. But I see no way to override the camera settings in the browser.

I have not figured out how to debug this further. I suspect I need to override the settings in the PHP and/or JS code, unless there is some lower level setting that I haven't yet found. Anybody have insight they can share?

jeffpiazza commented 4 years ago

For the replay piece, try working through some of the examples in https://webrtc.github.io/samples/ to see if the browser can interact successfully with the camera at all.

Blackbird714 commented 4 years ago

Awesome resource! Looking at this page, I think it proves my theory. These resolutions result in no image: VGA, 4K, 8K. All of these work: QVGA, HD, Full HD.

So I guess this means a change is needed in js/video-capture.js; am I right?

I probably need something like what this page describes:

async function constrainVideo() {
  const supports = navigator.mediaDevices.getSupportedConstraints();
  if (!supports.width || !supports.height) {
    // Treat like an error.
  }
  const stream = await navigator.mediaDevices.getUserMedia({
    video: {
      width: {min: 640, ideal: 1280, max: 1920},
      height: {min: 480, ideal: 720, max: 1080},
    }
  });
}
Blackbird714 commented 4 years ago

Ok I think I hacked my way through it. The file that needed to change is replay.php. This line:

   navigator.mediaDevices.getUserMedia({ video: { deviceId: device_id } })

I changed it to:

   navigator.mediaDevices.getUserMedia({ video: {
       deviceId: device_id,
       width: {exact: 1280},
       height: {exact: 720}
   } })
nayyerz commented 4 years ago

@Blackbird714 can you please provide instructions on how and where to change the code. I will be running into this same issue very soon. I am planning on using Raspberry pi 4 too for this.

Blackbird714 commented 4 years ago

For the replay feature, it's just the one file: /var/www/html/derbynet/replay.php

   navigator.mediaDevices.getUserMedia({ video: { deviceId: device_id } })

I changed it to:

   navigator.mediaDevices.getUserMedia({ video: {
       deviceId: device_id,
       width: {exact: 1280},
       height: {exact: 720}
   } })

If you have the exact same webcam, then the above should work as-is. If you find some other webcam misbehaving, you'll have to go the link that Jeff provided and mess around from a browser on your RPi. This is the specific page I used: https://webrtc.github.io/samples/src/content/getusermedia/resolution/

The only other tidbit I will offer, Chromium (chromium-browser, part of the Raspbian install) worked, but Firefox did not. Not sure the reason for that...

Blackbird714 commented 4 years ago

Chromium on the RPi has been unstable running as a Replay Kiosk; I can get a couple of tests run, but pretty soon after starting, the browser dies with the "Aw, Snap!" error -- and the underlying terminal shows this message:

==> /var/log/messages <==
Jan 18 21:50:12 wp197dn-02 kernel: [ 1477.552153] mmap: Video encoder t (3611): VmData 2155270144 exceed data ulimit 2147483647. Update limits or use boot option ignore_rlimit_data.

==> /var/log/syslog <==
Jan 18 21:50:13 wp197dn-02 kernel: [ 1478.489745] Unhandled prefetch abort: breakpoint debug exception (0x222) at 0x00000000

As mentioned before, Firefox (the ESR version, which is all that seems to be available for RPi) doesn't work at all. After digging into that, I think the issue is that the WebRTC plugin for Firefox depends on OpenH264 binaries that just aren't available for armhf. (Chromium uses a different library?)

I saw that RPi was not a recommended platform for replays -- but I was under the impression that recommendation was based on performance. RPi 4 has decent CPU and 2GB of RAM -- but at this point I'm thinking RPi is a dead end because of software compatibility issues.

Anybody out there have any success and relevant details they can share?