Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/ac_training_lab/picam/device.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import json
import subprocess
import shutil
Expand Down Expand Up @@ -27,7 +28,7 @@ def get_camera_command():
)


def start_stream(ffmpeg_url):
def start_stream(ffmpeg_url, width=854, height=480):
"""
Starts the libcamera -> ffmpeg pipeline and returns two Popen objects:
p1: camera process (rpicam-vid or libcamera-vid)
Expand All @@ -46,9 +47,9 @@ def start_stream(ffmpeg_url):
"--mode",
"1536:864", # A known 16:9 sensor mode
"--width",
"854", # Scale width
str(width), # Scale width
"--height",
"480", # Scale height
str(height), # Scale height
"--framerate",
"15", # Frame rate
"--codec",
Expand Down Expand Up @@ -150,6 +151,24 @@ def call_lambda(action, CAM_NAME, WORKFLOW_NAME, privacy_status="private"):


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Stream camera feed via Lambda")
parser.add_argument(
"--resolution",
type=str,
default="854x480",
help="Camera resolution as WIDTHxHEIGHT (default: 854x480)"
)
args = parser.parse_args()

# Parse resolution
try:
width, height = map(int, args.resolution.split('x'))
Comment on lines +164 to +165
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resolution parsing logic doesn't validate that the parsed width and height values are positive integers or within reasonable bounds. Negative values or zero could be passed to start_stream(), which may cause unexpected behavior in the camera command. Consider adding validation such as if width <= 0 or height <= 0: ... after parsing.

Copilot uses AI. Check for mistakes.
except ValueError:
print(f"Invalid resolution format: {args.resolution}. Use WIDTHxHEIGHT format.")
exit(1)

print(f"Using resolution: {width}x{height}")

# End previous broadcast and start a new one via Lambda
call_lambda("end", CAM_NAME, WORKFLOW_NAME)
raw_body = call_lambda(
Expand All @@ -167,7 +186,7 @@ def call_lambda(action, CAM_NAME, WORKFLOW_NAME, privacy_status="private"):

while True:
print("Starting stream..")
p1, p2 = start_stream(ffmpeg_url)
p1, p2 = start_stream(ffmpeg_url, width, height)
print("Stream started")
interrupted = False
try:
Expand Down
Loading