Jetson Nano Record short Video when object detected

Hello there!

I’m looking to see if there is any way to record a short video ~5s and save into a folder.
It should auto record when an object is detected. Is it possible? May I know how.
Below is the standard script I’m using. Appreciate your help!

while display.IsOpen():
img, width, height = camera.CaptureRGBA()
detections = net.Detect(img, width, height)
display.RenderOnce(img, width, height)

I haven’t done it, but I think you could use jetson.utils.videoOutput.
There is an example here: jetson-utils/video-viewer.py at master · dusty-nv/jetson-utils · GitHub
Documentation here: jetson-inference/aux-streaming.md at master · dusty-nv/jetson-inference · GitHub

Greetings gdefender!

Thank you for helping in.
After trying it out, that link is more on displaying the video camera rather than recording it and save into some sort of file (mp4 for example). Do you have any other link can share with?
Appreciate your help!

That is the right link. You need to read about videoOutput. When there is a detection, open a videoOutput and write frames for 5 seconds.

Here’s a rudimentary script that worked for me:

import jetson.inference
import jetson.utils
import time

net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)
camera = jetson.utils.videoSource("csi://0")

while True:
    img = camera.Capture()
    detections = net.Detect(img)
    # Check for a detection
    if (len(detections) > 1):
        video = jetson.utils.videoOutput(f"output{time.time()}.mp4")
        start = time.time()
        frame = img
        # Record video for 5 seconds
        while time.time() < start + 5:
            video.Render(frame)
            frame = camera.Capture()
            net.Detect(frame)

Apologise slow response.
Works with me! Thanks for your great support!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.