From 402a3454995e28a25d130d3afcb74d5ec3ad1b6d Mon Sep 17 00:00:00 2001 From: Stephen Dade Date: Sun, 11 Feb 2024 14:44:05 +1100 Subject: [PATCH] Video: Fix stream saving for CSI cameras --- python/gstcaps.py | 50 +++++++++++++++++++++---------------------- server/videostream.js | 4 ++-- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/python/gstcaps.py b/python/gstcaps.py index dd5526b5..efa0b1c5 100755 --- a/python/gstcaps.py +++ b/python/gstcaps.py @@ -48,21 +48,21 @@ def is_raspberry_pi(): if cam['Model'] == 'imx296': # Raspi global shutter camera has specific modes # https://www.raspberrypi.com/documentation/accessories/camera.html - caps.append({'value': "1456x1088", 'label': "1456x1088", 'height': 1088, 'width': 1456, 'format': 'video/x-raw', 'fpsmax': '60'}) - caps.append({'value': "1440x900", 'label': "1440x900", 'height': 900, 'width': 1440, 'format': 'video/x-raw', 'fpsmax': '60'}) - 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': '60'}) + caps.append({'value': "1456x1088xx-raw", 'label': "1456x1088", 'height': 1088, 'width': 1456, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) + caps.append({'value': "1440x900xx-raw", 'label': "1440x900", 'height': 900, 'width': 1440, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) + caps.append({'value': "1280x720xx-raw", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) + caps.append({'value': "640x480xx-raw", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) elif cam['Model'] == 'imx708': - caps.append({'value': "1920x1200", 'label': "1920x1200", 'height': 1200, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '60'}) - caps.append({'value': "1920x1080", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '60'}) - caps.append({'value': "1640x922", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '60'}) - caps.append({'value': "1280x720", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '120'}) - caps.append({'value': "640x480", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '120'}) + caps.append({'value': "1920x1200xx-raw", 'label': "1920x1200", 'height': 1200, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) + caps.append({'value': "1920x1080xx-raw", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) + caps.append({'value': "1640x922xx-raw", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) + caps.append({'value': "1280x720xx-raw", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '120', 'fps': []}) + caps.append({'value': "640x480xx-raw", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '120', 'fps': []}) else: - 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'}) + caps.append({'value': "1920x1080xx-raw", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '30', 'fps': []}) + caps.append({'value': "1640x922xx-raw", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '40', 'fps': []}) + caps.append({'value': "1280x720xx-raw", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) + caps.append({'value': "640x480xx-raw", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '90', 'fps': []}) name = "CSI Port Camera ({0})".format(cam['Model']) path = cam['Id'] if path.startswith("/base/soc/i2c") or path.startswith("/base/axi/pcie"): @@ -84,19 +84,19 @@ def is_raspberry_pi(): # If Ubuntu and Rpi camera if "Ubuntu" in platform.uname().version and ("mmal service" in name or name == "unicam"): # Ubuntu needs to use the v4l2 driver - 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'}) + caps.append({'value': "1920x1080xx-raw", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '30', 'fps': []}) + caps.append({'value': "1640x922xx-raw", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '40', 'fps': []}) + caps.append({'value': "1280x720xx-raw", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) + caps.append({'value': "640x480xx-raw", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '90', 'fps': []}) path = "/dev/video0" name = "CSI Port Camera" # If legacy camera stack on RasPiOS elif "mmal service" in name: - 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'}) + caps.append({'value': "1920x1080xx-raw", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '30', 'fps': []}) + caps.append({'value': "1640x922xx-raw", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '40', 'fps': []}) + caps.append({'value': "1280x720xx-raw", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) + caps.append({'value': "640x480xx-raw", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '90', 'fps': []}) # Cope with dual CSI too if "/dev/video" in path: @@ -168,10 +168,10 @@ def is_raspberry_pi(): # If we're on a Jetson and /dev/video0 or /dev/video0 exist but not listed, add as CSI ports if 'aarch64' in platform.uname().machine and 'tegra' in platform.uname().release: caps = [] - caps.append({'value': "1920x1080xx-raw", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '30'}) - caps.append({'value': "1640x922xx-raw", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '40'}) - caps.append({'value': "1280x720xx-raw", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '60'}) - caps.append({'value': "640x480xx-raw", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '90'}) + caps.append({'value': "1920x1080xx-raw", 'label': "1920x1080", 'height': 1080, 'width': 1920, 'format': 'video/x-raw', 'fpsmax': '30', 'fps': []}) + caps.append({'value': "1640x922xx-raw", 'label': "1640x922", 'height': 922, 'width': 1640, 'format': 'video/x-raw', 'fpsmax': '40', 'fps': []}) + caps.append({'value': "1280x720xx-raw", 'label': "1280x720", 'height': 720, 'width': 1280, 'format': 'video/x-raw', 'fpsmax': '60', 'fps': []}) + caps.append({'value': "640x480xx-raw", 'label': "640x480", 'height': 480, 'width': 640, 'format': 'video/x-raw', 'fpsmax': '90', 'fps': []}) if os.path.exists('/dev/video0') and '/dev/video0' not in [i['value'] for i in retDevices]: retDevices.append({'value': 'argus0', 'label': 'CSI0', 'caps': caps}) if os.path.exists('/dev/video1') and '/dev/video1' not in [i['value'] for i in retDevices]: diff --git a/server/videostream.js b/server/videostream.js index 42d335ad..8b365ddc 100644 --- a/server/videostream.js +++ b/server/videostream.js @@ -92,7 +92,7 @@ class videoStream { } const selRes = seldevice[0].caps.filter(it => it.value === this.savedDevice.width.toString() + 'x' + this.savedDevice.height.toString() + 'x' + this.savedDevice.format.toString().split('/')[1]) let selFPS = this.savedDevice.fps - if (selRes[0].fpsmax === 0) { + if (selRes.length === 1 && selRes[0].fpsmax !== undefined && selRes[0].fpsmax === 0) { selFPS = selRes[0].fps.filter(it => parseInt(it.value) === this.savedDevice.fps)[0] } if (seldevice.length === 1 && selRes.length === 1) { @@ -106,7 +106,7 @@ class videoStream { } else { // bad settings console.error('Bad video settings. Resetting' + seldevice + ', ' + selRes) - this.winston.error('Bad video settings. Resetting ', { message: this.savedDevice }) + this.winston.error('Bad video settings. Resetting ', { message: JSON.stringify(this.savedDevice) }) this.resetVideo() return callback(null, this.devices, this.active, this.devices[0], this.devices[0].caps[0], { label: '0°', value: 0 }, 1100, fpsSelected, false, '127.0.0.1', 5400, false,