STEPHAN GEISSER

Applied Scientist | Mechanical Engineer | AI & ML Specialist

Back to Projects

MECFcam

Raspberry Pi Video Streaming GStreamer Model Railway Low Latency

Project Overview

The MECFcam is a specialized low-latency video streaming system designed for a model railroad simulator. MECF (Modell Eisenbahn Club Flawil) has an H0 model railway layout with a real driver's cab. This means that a miniature locomotive (which is equipped with a camera) can be controlled remotely from the driver's cab of a real locomotive.

Previously, the system relied on an analog camera, but our goal was to develop a digital solution that provides higher video resolution with less noise while maintaining minimal latency.

In model railway simulation, video latency is critical - any delay between the actual movement and what the operator sees can make controlling the train difficult and unrealistic. The challenge was to implement a high-resolution digital video solution without introducing noticeable lag, creating an immersive and responsive experience for the operator in the driver's cab.

Technology Stack

Raspberry Pi
Camera Module
GStreamer
Python
TCP/UDP

Components

  • Raspberry Pi Zero 2 W - Compact, low-power computing platform
  • Raspberry Pi Camera Module 3 - High-quality digital camera
  • Micro SD card (SanDisk Extreme PRO 32 GB) - Fast, reliable storage
  • Windows/Linux PC - For receiving and displaying the video stream

Technical Implementation

The system uses GStreamer, a powerful multimedia framework, to create a low-latency video pipeline from the Raspberry Pi camera to a PC. We implemented two different approaches:

GStreamer UDP Approach

This method uses User Datagram Protocol for fastest possible transmission:

  • Raspberry Pi captures video using rpicam-vid
  • Video encoded in H264 format
  • Stream packetized with RTP (Real-time Transport Protocol)
  • Transmitted via UDP to the receiver PC
  • PC decodes and displays stream in real-time

TCP Approach

This method ensures reliable packet delivery with slightly higher latency:

  • Raspberry Pi streams directly via TCP
  • Custom Python receiver with OpenCV for advanced processing
  • Optional frame interpolation for smoother video

Challenges & Solutions

Several technical challenges were addressed during development:

  • Latency Management: Optimized the entire pipeline by using efficient encoding settings, minimal buffering, and direct hardware access.
  • Video Quality: Found the optimal balance between resolution, frame rate, and bitrate to maintain clarity without increasing latency.
  • Focus Control: Implemented fixed focus settings to prevent autofocus hunting and maintain a clear view of the model railway.
  • Lighting Adaptation: Added manual exposure and gain controls to handle varying lighting conditions across the model layout.
  • Network Reliability: Created both UDP (lowest latency) and TCP (highest reliability) implementations to adapt to different network conditions.

Configuration Optimizations

To achieve the best possible performance, we implemented several optimizations:

  • Resolution Control: Tuned to 1280x720 (720p) as the optimal balance between detail and performance
  • Fixed Focus: Used the --lens-position parameter to eliminate focus hunting
  • Illumination Management: Implemented fixed shutter speed and gain values for consistent lighting
  • Frame Rate Optimization: Set to 40fps for smooth motion perception
  • Network Optimization: Used wired Ethernet connections where possible to minimize latency

Outcomes & Learnings

The MECFcam project successfully delivers a high-quality, low-latency video stream from the model railway to the driver's cab, significantly enhancing the simulation experience. The system achieves latency as low as 100ms while maintaining HD resolution at 40fps, providing a responsive and clear view for the operator. Nevertheless, the transmission seems to stutter when the train takes a curve, despite the high fps. This still needs to be looked at and improved.

Through this project, I gained valuable experience with multimedia streaming pipelines, real-time video processing, and the challenges of optimizing for latency-sensitive applications. I also deepened my understanding of the Raspberry Pi camera system, GStreamer framework, and network streaming protocols.