Skip to content

Commit 9d83353

Browse files
committed
Video: Limit to 1080p on Rpi
1 parent c5ffd0f commit 9d83353

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

python/gstcaps.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,34 @@ def getcapval(caps):
2727
return allval
2828

2929

30+
# Return true if running on RPi
31+
def is_raspberry_pi():
32+
try:
33+
with open('/proc/cpuinfo', 'r') as f:
34+
cpuinfo = f.read()
35+
return 'Raspberry Pi' in cpuinfo
36+
except FileNotFoundError:
37+
return False
38+
39+
3040
retDevices = []
3141

3242
# Libcamera check, if installed
33-
try:
34-
from picamera2 import Picamera2
35-
for cam in Picamera2.global_camera_info():
36-
caps = []
37-
caps.append({'value': "1920x1080", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '30'})
38-
caps.append({'value': "1640x922", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '40'})
39-
caps.append({'value': "1280x720", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '60'})
40-
caps.append({'value': "640x480", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '90'})
41-
name = "CSI Port Camera ({0})".format(cam['Model'])
42-
path = cam['Id']
43-
if path.startswith("/base/soc/i2c"):
44-
retDevices.append({'value': path, 'label': name, 'caps': caps})
45-
except:
46-
pass
43+
if is_raspberry_pi():
44+
try:
45+
from picamera2 import Picamera2
46+
for cam in Picamera2.global_camera_info():
47+
caps = []
48+
caps.append({'value': "1920x1080", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '30'})
49+
caps.append({'value': "1640x922", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '40'})
50+
caps.append({'value': "1280x720", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '60'})
51+
caps.append({'value': "640x480", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '90'})
52+
name = "CSI Port Camera ({0})".format(cam['Model'])
53+
path = cam['Id']
54+
if path.startswith("/base/soc/i2c"):
55+
retDevices.append({'value': path, 'label': name, 'caps': caps})
56+
except:
57+
pass
4758

4859
legacycamint = 0
4960

@@ -103,6 +114,11 @@ def getcapval(caps):
103114
if structure.get_name() in ['video/x-raw', 'video/x-h264', 'image/jpeg'] :
104115
width = structure.get_int('width').value
105116
height = structure.get_int('height').value
117+
118+
# if on Rpi, don't return anything greater than 1080p on raw or jpg, as
119+
# Rpi's x264 hardware encoder doesn't support >1080p
120+
if is_raspberry_pi() and (height > 1080 or width > 1920) and structure.get_name() in ['video/x-raw', 'image/jpeg']:
121+
continue
106122
#print(structure.get_list('framerate')[1].get_nth(0).fps_numerator)
107123
#(_, fps_numerator, fps_denominator) = structure.get_fraction('framerate')
108124
#single fpsmax, or list of available fps'

0 commit comments

Comments
 (0)