How can I reduce TinyPilot's latency?

On a well-provisioned local network, TinyPilot achieves 100-200 milliseconds of latency on its video stream. On slower networks or across the Internet, you may experience higher latency. This article includes steps you can take to reduce TinyPilot's latency.

Why does latency increase?

To stream video, TinyPilot uses the MJPEG streaming format. This protocol achieves low latency, but it consumes significant bandwidth.

Reducing TinyPilot's bandwidth and latency

To reduce TinyPilot's bandwidth usage, you can tune its video streaming settings.

To begin, open the ustreamer.service file:

nano /lib/systemd/system/ustreamer.service

You'll see an ExecStart line that begins like this:

ExecStart=/opt/ustreamer/ustreamer \
  --host \
  --port 8001

At the end of the ExecStart section, add these lines and save the file:

  --quality 50 \
  --desired-fps 10 \
  --resolution 800x600 \

To apply the changes to the video stream, run this command after saving the ustreamer.service file:

sudo systemctl daemon-reload && sudo service ustreamer restart

I recommend experimenting with different settings until you find the right balance of performance and latency.

Make settings permanent

The TinyPilot updater will overwrite the settings in your ustreamer.service file on the next update. To make the settings permanent, you'll need to add the following to your /home/tinypilot/settings.yml file:

ustreamer_quality: 50           # Reduce JPEG quality to 50%
ustreamer_desired_fps: 10       # Reduce to 10 frames per second
ustreamer_resolution: "800x600" # Use 800x600 resolution

Adjust these values as necessary for the particular settings that work best on your connection.