Pi Zero Dashcam

I’m neither the first nor the last to make a dash cam with God’s gift to Linux SBCs, but I think this implementation is marginally different. What I have now is more proof-of-concept than anything else. It still needs to be refined to be considered competent (or even functional).

With a Raspberry Pi Zero W, Camera, Case, and some industrial strength double sided tape, I put together this dash cam that blends well with the car’s interior and stays out of the way. It’s mounted on the back of the rear view mirror with a great view over the hood. I have power going directly to GPIO instead of hacking together some micro-usb solution, and the power wires are shoved inside the right A pillar and are then routed into the glovebox/dashboard.

The software running this is fairly simple as well. I have MJPEG Streamer spitting out whatever the camera sees as fast as possible. I made the entire SD card read-only [guide], to prevent corruption when power is inevitably cut without a proper shutdown.

This Pi Zero boots and immediately connects to the car’s always-on WiFi network. This Zero is named Varian. Hooked straight into the LAN port of the router is a Pi 3 called Lucio, who records Varian’s stream onto an external 500GB SSD. Right now this drive just fills up with video, about 7GB/hour by the way, and I manually empty it when it starts to get full. This is dumb and inefficient and I have other plans to smooth this out (see below).

The FFMPEG command used to copy the stream on Lucio’s external SSD:

ffmpeg -err_detect ignore_err -i "${source_stream}" -c copy -map 0 -f segment -c:v copy -segment_time 60 -use_wallclock_as_timestamps 1 -reset_timestamps 1 -strftime 1 "${destination_directory}/varian-%Y-%m-%d_%H-%M-%S.mp4" > "/home/pi/le/video/logs/varian-$(date +"%Y-%m-%d_%I-%M").log

I manage around 24fps at 720p, which isn’t stellar but for a networked solution it’s more than fine.

Some things that still need to be worked on:

  1. Unsolved race conditions. Sometimes Lucio will beat Varian in boot time (likely because of its direct ethernet), and then will try and fail to record the stream before Varian is connected. This is complete. Lucio will continuously try to connect and record. This helps if the stream is interrupted mid-drive as well.
  2. File size is massive. Doing the FFMPEG copy stream above does not do any encoding, and naturally takes little to no CPU. In Lucio’s downtime I’d like to be encoding these in H264.
  3. Storing Dashcam Footage. I want to leave Lucio on for a few minutes when the car is connected to my home WiFi, as opposed to my data plan. This GLI.net router thankfully has WISP mode which solves that. But with those few extra minutes I’d like to send any video (encoded or not) to my desktop computer with both a beefy HD and i7 8700k, to finish encoding and uploading to a private YouTube channel.
  4. MORE! Once this pipeline is ironed out my goal is to add 2 cameras to the front fog light area and one in the rear. The latter stream can be shown on the Nexus 7 when I’m in reverse, backing up.

I think for a dash cam this blends nicely and is unobtrusive to the look of the cabin. It’s amazing what black spray paint can do. Progress pics: