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.
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.
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.
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.
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.
Tighter means less to send and a rougher picture.
- 00035uploaded
- 00036uploaded
- 00037uploaded
- 00038uploaded
- 00039uploaded
- 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.
| seq | file | status | tries | acct |
|---|---|---|---|---|
| seg_00035.ts | uploaded | 1 | A1 | |
| seg_00036.ts | uploaded | 1 | A1 | |
| seg_00037.ts | uploaded | 1 | A1 | |
| seg_00038.ts | uploaded | 1 | A1 | |
| seg_00039.ts | uploaded | 1 | A1 | |
| seg_00040.ts | uploaded | 1 | A1 |
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.
Queue holding.
- 00029uploaded
- 00030uploaded
- 00031uploaded
- 00032uploaded
- 00033uploaded
- 00034uploaded
- 00035uploaded
- 00036uploaded
- 00037uploaded
- 00038uploaded
- 00039uploaded
- 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.
- 00029uploaded
- 00030uploaded
- 00031uploaded
- 00032uploaded
- 00033uploaded
- 00034uploaded
- 00035uploaded
- 00036uploaded
- 00037uploaded
- 00038uploaded
- 00039uploaded
- 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.
- 00029uploaded
- 00030uploaded
- 00031uploaded
- 00032uploaded
- 00033uploaded
- 00034uploaded
- 00035uploaded
- 00036uploaded
- 00037uploaded
- 00038uploaded
- 00039uploaded
- 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
- 00017uploaded
- 00018uploaded
- 00019uploaded
- 00020uploaded
- 00021uploaded
- 00022uploaded
- 00023uploaded
- 00024uploaded
- 00025uploaded
- 00026uploaded
- 00027uploaded
- 00028uploaded
- 00029uploaded
- 00030uploaded
- 00031uploaded
- 00032uploaded
- 00033uploaded
- 00034uploaded
- 00035uploaded
- 00036uploaded
- 00037uploaded
- 00038uploaded
- 00039uploaded
- 00040uploaded
- 1 Camera
- 2 Router
- 3 My software on an old laptop
- 4 FFmpeg
- 5 The laptop's drive
- 6 PostgreSQL
- 7 Scheduler and uploader
- 8 Google Drive, 2 or 3 merged accounts
- 9 Next.js timeline, cloud or local