Just like local webcams, you can extract frames from IP cameras.
The example below iterates over the first 100 frames captured by the network camera, resizes it and saves it to a new video file.
from landingai.pipeline.image_source import NetworkedCamera from landingai.pipeline.frameset import FrameSet frameset = FrameSet() # (1)! with NetworkedCamera(stream_url="rtsp://192.168.0.77:8080/h264_opus.sdp", fps=1) as camera: # (2)! for i, frame in enumerate(camera): # (3)! if i >= 100: break frame.resize(width=256) # (4)! frameset.append(frame) # (5)! frameset.save_video("/tmp/resized-video.mp4") # (6)!
- Creates an empty
FrameSet, where we will store the modified frames
- Connects to the IP camera using RTSP protocol, and captures frames at 1 frame per second
- Iterate over each frame of the video file
- Resize the frame to
width=256px(keeping aspect ratio)
- Append the resized frame to the
- Save the resized video to
It is also possible to only yield frames if the camera detects motion. This is useful for reducing the number of frames processed when running inferences, for example: