Loading

AV

One door at night

CCTV PIPELINE / CUSTOM NVR TO GOOGLE DRIVE

One door at night

A camera watches this door. Install my software on an old laptop and it keeps everything the camera sees, on the laptop and on free Google Drive storage. Open the door, then scroll and follow what it sees.

Code, addresses, file names, table rows and footage here are illustrative. The architecture is real. The simulator runs in your browser and sends nothing.

64CAM 01 23:41:00

CAMERA

Light becomes frames

The camera turns the door into a live video stream. From here on, the job is to keep every second of it.

64CAM 01 23:41:00
The sensor, drawn at 256 x 144. It follows your door button.

THE WIRE

Follow the wire

The stream leaves the camera as IP packets on a physical cable. I draw them as slices of the frame so you can see what they carry.

camerarouter

ROUTER

The camera has an address

On the network, the camera is an IP address. The router passes its packets toward the laptop.

192.168.1.64

CAM 01   192.168.1.64   streaming

CUSTOM NVR SOFTWARE

Install it on an old laptop

No vendor NVR sits in this chain. Install my software on an old laptop and connect the camera over RTSP or HTTP. The footage and the backend live on the laptop's own drive, and that cuts the dependency on vendor storage.

Ingest over
cameraRTSPCUSTOM NVRrecordingOLD LAPTOPfootage and backend on its drive

FFMPEG AND HLS

FFmpeg cuts the night

Footage is taken using HLS and FFmpeg. FFmpeg handles the real-time stream processing, segmentation and compression. Each short segment lands on the laptop's drive first, and it can fail alone and go again.

Compression

Tighter means less to send and a rougher picture.

  1. 00035uploaded
  2. 00036uploaded
  3. 00037uploaded
  4. 00038uploaded
  5. 00039uploaded
  6. 00040uploaded

POSTGRESQL

Every segment gets a row

PostgreSQL metadata tracks each video segment, and which Google account holds it. That is what keeps uploads in order and carries them across interruptions.

seqfilestatustriesacct
seg_00035.tsuploaded1A1
seg_00036.tsuploaded1A1
seg_00037.tsuploaded1A1
seg_00038.tsuploaded1A1
seg_00039.tsuploaded1A1
seg_00040.tsuploaded1A1
Compression

SCHEDULER AND GOOGLE DRIVE API

Up the line in order

The same data then goes up in sequence through the Google Drive API, with scheduling, retries and failure handling. The queue on this rail is the latency you can see: its length is how far the cloud sits behind the laptop.

Compression

Queue holding.

  1. 00029uploaded
  2. 00030uploaded
  3. 00031uploaded
  4. 00032uploaded
  5. 00033uploaded
  6. 00034uploaded
  7. 00035uploaded
  8. 00036uploaded
  9. 00037uploaded
  10. 00038uploaded
  11. 00039uploaded
  12. 00040uploaded

Line up

BREAK IT

Cut the line

Connections drop. Press the button, or keep scrolling and the line drops anyway. FFmpeg keeps cutting, retries keep failing, and every segment still gets its row.

Compression
  1. 00029uploaded
  2. 00030uploaded
  3. 00031uploaded
  4. 00032uploaded
  5. 00033uploaded
  6. 00034uploaded
  7. 00035uploaded
  8. 00036uploaded
  9. 00037uploaded
  10. 00038uploaded
  11. 00039uploaded
  12. 00040uploaded

Line up

RECOVERY

Postgres remembers

The uploader asks one question: what is the next segment that has not reached Drive? The metadata answers. Uploads carry on from that row, in order.

Compression
  1. 00029uploaded
  2. 00030uploaded
  3. 00031uploaded
  4. 00032uploaded
  5. 00033uploaded
  6. 00034uploaded
  7. 00035uploaded
  8. 00036uploaded
  9. 00037uploaded
  10. 00038uploaded
  11. 00039uploaded
  12. 00040uploaded

2 OR 3 GOOGLE ACCOUNTS

Merge the free storage

The software merges 2 or 3 Google accounts into one large cloud drive, for free. When one fills up, the next segment goes to the next account, and PostgreSQL records where each one went.

  • Account 140/60
  • Account 20/60
  • Account 3not added

WHY THE CLOUD COPY MATTERS

Kill the local drive

It is an old laptop, and drives die. Press the button, or keep scrolling and it dies anyway. Everything that reached Google Drive is safe. Only the segments still waiting in the queue go with it, which is why the queue is the number to watch.

Laptop drive
Recording
Google Drive
40 segments safe

NEXT.JS FRONTEND

Open the timeline

Whenever you want, open the frontend, built on Next.js, and see all footage and its timeline, from cloud or local. Scrub across the second the line went down and watch the moth: every segment that reached Drive is here, in order.

Custom NVR software on an old laptop. RTSP and HTTP ingest. FFmpeg for segmentation and compression. PostgreSQL metadata. Google Drive API uploads with retry, scheduling and failure handling, across 2 or 3 merged accounts. A Next.js timeline from cloud or local. Free cloud storage, and less dependence on vendor storage.

I used generative AI tools to speed up debugging, reverse-engineering of APIs and system optimization.

Still recording

The camera never stopped. You can open the door again.

23:40:39seg_00036.ts

Watch from
64CAM 01 23:40:3900036
  1. 00017uploaded
  2. 00018uploaded
  3. 00019uploaded
  4. 00020uploaded
  5. 00021uploaded
  6. 00022uploaded
  7. 00023uploaded
  8. 00024uploaded
  9. 00025uploaded
  10. 00026uploaded
  11. 00027uploaded
  12. 00028uploaded
  13. 00029uploaded
  14. 00030uploaded
  15. 00031uploaded
  16. 00032uploaded
  17. 00033uploaded
  18. 00034uploaded
  19. 00035uploaded
  20. 00036uploaded
  21. 00037uploaded
  22. 00038uploaded
  23. 00039uploaded
  24. 00040uploaded
  1. 1 Camera
  2. 2 Router
  3. 3 My software on an old laptop
  4. 4 FFmpeg
  5. 5 The laptop's drive
  6. 6 PostgreSQL
  7. 7 Scheduler and uploader
  8. 8 Google Drive, 2 or 3 merged accounts
  9. 9 Next.js timeline, cloud or local