Tuesday, November 10, 2020

SVL: Fixing CabCam video throughput issues

 

Last Friday I went to the club layout and tested the Web Throttle code. The code worked, but video quality was terrible. As soon as I tried to get two video feeds off the camera to WebThrottle and OBS respectively, the video streams produced only one image every 10 seconds at best. That's clearly not acceptable for what we are trying to do here.

I experimented with camera settings over the weekend at home. My theory was that due to the difficult Wifi conditions in the layout room, we're simply not getting the network throughput we need to get stable video streams. When running two streams at home I found that the PiZero kept a network send queue of more than two Megabyte or more, i.e. mjpg_streamer is stuffing bytes into the network queue, but they are not making it off the device fast enough. Eventually, buffers will overflow, the network code backs off, the queue drains out, and we see skipped video. In tunnel sections on the Welztalbahn, the queue dropped to about one Megabyte. My tunnels are very dark, so the jpgs produced by mjpg_streamer are much smaller and the network can catch up. In addition, the PiZero CPU was only about 30% idle when processing camera data to two streams when a train is moving. Not a lot of headroom. As a consequence, while the video works ok, even at home it was a bit choppy.

So with two streams we are simply pushing too much data into the network layer that can't get drained out fast enough over the network. The solution is to push less data. I reduced the video resolution from 640x480@15fps to 480x360@10fps, which reduces the raw bandwidth need to about one third. Testing on the Welztalbahn yielded a very smooth and stable video stream.

Sunday evening I was back at SVL and tested my theory at the layout. A single WebThrottle stream to my smartphone was smooth and stable, even in the Cavenaugh area that is particularly problematic. Next I pulled out the laptop with OBS and streamed the camera feed to Youtube while working on mounting location signs for the upcoming Open House. While before we often had a lag of a bit less than 5 seconds when watching the camera stream, video now was almost realtime and so smooth that you can see the flat car sway back and forth on the rails.

Towards the end of the evening, I pulled out camera 3 which is known to have reception issues because of how the PiZero sits right next to the large USB power bank. With the adjusted settings, quality is better, but still visibly worse than camera 4. You can see the difference side by side starting around 1:08:00  in the work video. That needs to be get fixed before Saturday.

I used the work video source to make an instructional video for Open House operators showing how to use the WebThrottle and what the location signs look like.

No comments: