3. Video Recording

Downloading Recorded Videos on Velovision Rearview

Whenever Velovision Rearview is powered on and blinking, it simultaneously starts:

  • Streaming it via TCP (discussed in previous section)
  • Recording video to its onboard microSD card (discussed in this section)
  • Creating thumbnail images of each saved video (also discussed in this section)

Videos are saved as H.264-encoded .mkv files in 1-minute chunks to /opt/velovision/standalone_videos. If the number of files reaches 900 (corresponding to 15 hours or ~27GB; 30MB/minute), old files will be overwritten. The file names do not reflect this rotation - they will always be named log0000.mp4 to log0899.mp4. Therefore, this server has a GET endpoint that returns both the path and latest update date/time:

Note: The chunks are loaded into memory before transfer, so they should not be large. The chunk time (1 minute) may be adjusted upwards but not by too much due to memory constraints.

Get a list of the videos and their update times:

curl http://velovision-rearview.local:8000/list-local-videos

The returned JSON provides the path and update time of each video. We'll use the path to download the video file, and use both the path and update time to get the thumbnail image.

Downloading Videos

Let's say we want video at /opt/velovision/standalone_videos/log0000.mkv. Make a GET request with the full path to the video in the query string.

Velovision Rearview will find the .mkv video specified in your query string, convert it to .mp4, then send the file. The conversion itself is quite fast (20x realtime) since we're only changing the container and keeping the H.264 encoding, so it should be negligible in most cases. This conversion step exists because iOS does not support .mkv, yet we prefer to record in .mkv due to its resilience (especially in the case of interruption such as power loss). Support for downloading the .mkv directory is pending community feedback.

curl -o log0000.mp4 http://velovision-rearview.local:8000/download-video?/opt/velovision/standalone_videos/log0000.mkv

This will download the video log0000.mp4 to your current directory.

Downloading Thumbnail Images

Velovision Rearview runs a background process that monitors for new videos and creates thumbnail images if they don't already exist. The thumbnail images are saved as .jpg files in the same directory /opt/velovision/standalone_videos. The file names are defined as follows: [video_filename_without_extension]_[datetime_in_unix_seconds].jpg.

Therefore, to get the thumbnail image of log0000.mp4, we need to know the update time of the video. Recall that we already have this information from the previous API call for the list of videos.

curl -o log0000.jpg http://velovision-rearview.local:8000/download-thumbnail?/opt/velovision/standalone_videos/log0000_1713198307.jpg

About Date and Time

The update times are seconds elapsed since UNIX epoch (Jan 1, 1970). It looks something like 1713198307. This time format is used frequently throughout the firmware and also when interacting with the Velovision iOS app.

Velovision Rearview does not have a battery-powered hardware clock, so the system time will stop when powered off, meaning that over time, the system time will drift to be 'in the past' compared to real world time. We don't consider this a big problem as long as the system time is monotonically increasing (never skips backward), which we ensure by calling fake-hwclock save regularly while the system is on. This prevents the system clock from skipping backward in the case of a low-battery induced power cut and non-graceful shutdown. Normally, upon graceful shutdown, fake-hwclock save is called by its daemon.

Summary of Lesson 3: Video Recording

Congrats! You've completed the basic tutorial.

In this lesson, you learned how to view and download the recorded videos from Velovision Rearview.

To get to know Velovision Rearview even better, you can refer to the advanced topics below.

  • Architecture: a high-level overview of the Velovision Rearview system architecture.
  • API Reference: a comprehensive guide to the Velovision Rearview API.
  • Specifications: technical specifications of Velovision Rearview.

If you want to dig deeper and modify/contribute to the Velovision Rearview codebase, refer to Core Development.