Skip to content

Commit

Permalink
Video: Limit to 1080p on Rpi
Browse files Browse the repository at this point in the history
  • Loading branch information
stephendade committed Nov 29, 2023
1 parent efa0b5f commit e5a263e
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions python/gstcaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,34 @@ def getcapval(caps):
return allval


# Return true if running on RPi
def is_raspberry_pi():
try:
with open('/proc/cpuinfo', 'r') as f:
cpuinfo = f.read()
return 'Raspberry Pi' in cpuinfo
except FileNotFoundError:
return False


retDevices = []

# Libcamera check, if installed
try:
from picamera2 import Picamera2
for cam in Picamera2.global_camera_info():
caps = []
caps.append({'value': "1920x1080", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '30'})
caps.append({'value': "1640x922", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '40'})
caps.append({'value': "1280x720", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '60'})
caps.append({'value': "640x480", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '90'})
name = "CSI Port Camera ({0})".format(cam['Model'])
path = cam['Id']
if path.startswith("/base/soc/i2c"):
retDevices.append({'value': path, 'label': name, 'caps': caps})
except:
pass
if is_raspberry_pi():
try:
from picamera2 import Picamera2
for cam in Picamera2.global_camera_info():
caps = []
caps.append({'value': "1920x1080", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '30'})
caps.append({'value': "1640x922", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '40'})
caps.append({'value': "1280x720", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '60'})
caps.append({'value': "640x480", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '90'})
name = "CSI Port Camera ({0})".format(cam['Model'])
path = cam['Id']
if path.startswith("/base/soc/i2c"):
retDevices.append({'value': path, 'label': name, 'caps': caps})
except:
pass

legacycamint = 0

Expand Down Expand Up @@ -103,6 +114,11 @@ def getcapval(caps):
if structure.get_name() in ['video/x-raw', 'video/x-h264', 'image/jpeg'] :
width = structure.get_int('width').value
height = structure.get_int('height').value

# if on Rpi, don't return anything greater than 1080p on raw or jpg, as
# Rpi's x264 hardware encoder doesn't support >1080p
if is_raspberry_pi() and (height > 1080 or width > 1920) and structure.get_name() in ['video/x-raw', 'image/jpeg']:
continue
#print(structure.get_list('framerate')[1].get_nth(0).fps_numerator)
#(_, fps_numerator, fps_denominator) = structure.get_fraction('framerate')
#single fpsmax, or list of available fps'
Expand Down

0 comments on commit e5a263e

Please sign in to comment.