From 764f94ba44ded2fd58a27073d27d9af812f35d22 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Sat, 5 Nov 2022 15:39:03 +0100 Subject: [PATCH] Add various tools --- README.md | 36 +++++++++---------- imx519_camera.sh => tools/csi_camera.sh | 2 +- tools/dump_cameras.sh | 11 ++++++ .../libcamera_camera.sh | 2 +- tools/rpi_measure.sh | 22 ++++++++++++ usb_camera.sh => tools/usb_camera.sh | 2 +- 6 files changed, 54 insertions(+), 21 deletions(-) rename imx519_camera.sh => tools/csi_camera.sh (99%) create mode 100755 tools/dump_cameras.sh rename libcamera_camera.sh => tools/libcamera_camera.sh (92%) create mode 100755 tools/rpi_measure.sh rename usb_camera.sh => tools/usb_camera.sh (91%) diff --git a/README.md b/README.md index b476d97..5d004f4 100644 --- a/README.md +++ b/README.md @@ -82,8 +82,8 @@ This due to extra overhead has worse latency than direct decoding via ISP. ```bash -./libcamera_camera.sh -help -./libcamera_camera.sh -camera-format=YUYV +tools/libcamera_camera.sh -help +tools/libcamera_camera.sh -camera-format=YUYV ``` ### High-performance mode via ISP for CSI @@ -96,8 +96,8 @@ As such it does not implement brightness control similarly to `libcamera`. # This script uses dumped IMX519 parametrs that are feed into bcm2385 ISP module # This does not provide automatic brightness control # Other sensors can be supported the same way as long as ISP parameters are adapted -./imx519_camera.sh -help -./imx519_camera.sh -camera-format=RG10 ... +tools/imx519_camera.sh -help +tools/imx519_camera.sh -camera-format=RG10 ... ``` This mode allows to provide significantly better performance for camera sensors @@ -117,9 +117,9 @@ This script uses direct decoding or passthrough of MJPEG or H264 streams from UV re-encoded stream provided over web-interface. ```bash -./usb_camera.sh -help -./usb_camera.sh -camera-format=H264 ... -./usb_camera.sh -camera-format=MJPEG ... +tools/usb_camera.sh -help +tools/usb_camera.sh -camera-format=H264 ... +tools/usb_camera.sh -camera-format=MJPEG ... ``` ## HTTP web server @@ -158,7 +158,7 @@ You can view all available configuration parameters by adding `-log-verbose` to one of the above commands, like: ```bash -./libcamera_camera.sh -log-verbose ... +tools/libcamera_camera.sh -log-verbose ... ``` Depending on control they have to be used for camera, ISP, or JPEG or H264 codec: @@ -188,10 +188,10 @@ v4l2-ctl -d /dev/video0 --list-formats-ext Some of them might be specified to streamer: ```bash -./*_camera.sh -camera-format=RG10 # Bayer 10 packet -./*_camera.sh -camera-format=YUYV -./*_camera.sh -camera-format=MJPEG -./*_camera.sh -camera-format=H264 # This is unstable due to h264 key frames support +tools/*_camera.sh -camera-format=RG10 # Bayer 10 packet +tools/*_camera.sh -camera-format=YUYV +tools/*_camera.sh -camera-format=MJPEG +tools/*_camera.sh -camera-format=H264 # This is unstable due to h264 key frames support ``` ## Camera support @@ -223,13 +223,13 @@ Latency according to my tests is due to the way how buffers are enqueued and pro ```shell # libcamera -$ ./camera_stream -camera-path=/base/soc/i2c0mux/i2c@1/imx519@1a -camera-type=libcamera -camera-format=YUYV -camera-fps=120 -camera-width=2328 -camera-height=1748 -camera-high_res_factor=1.5 -log-filter=buffer_lock +$ ./camera_streamer -camera-path=/base/soc/i2c0mux/i2c@1/imx519@1a -camera-type=libcamera -camera-format=YUYV -camera-fps=120 -camera-width=2328 -camera-height=1748 -camera-high_res_factor=1.5 -log-filter=buffer_lock device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf2 (refs=2), frame=63/0, processing_ms=101.1, frame_ms=33.1 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf0 (refs=2), frame=64/0, processing_ms=99.2, frame_ms=31.9 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf1 (refs=2), frame=65/0, processing_ms=99.6, frame_ms=34.8 # direct ISP-mode -$ ./camera_stream -camera-path=/dev/video0 -camera-format=RG10 -camera-fps=30 -camera-width=2328 -camera-height=1748 -camera-high_res_factor=1.5 -log-filter=buffer_lock +$ ./camera_streamer -camera-path=/dev/video0 -camera-format=RG10 -camera-fps=30 -camera-width=2328 -camera-height=1748 -camera-high_res_factor=1.5 -log-filter=buffer_lock device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf1 (refs=2), frame=32/0, processing_ms=49.7, frame_ms=33.3 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf2 (refs=2), frame=33/0, processing_ms=49.7, frame_ms=33.3 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf0 (refs=2), frame=34/0, processing_ms=49.7, frame_ms=33.4 @@ -239,12 +239,12 @@ device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf0 (refs= ```shell # libcamera -$ ./camera_stream -camera-path=/base/soc/i2c0mux/i2c@1/imx519@1a -camera-type=libcamera -camera-format=YUYV -camera-fps=10 -camera-width=2328 -camera-height=1748 -camera-high_res_factor=1.5 -log-filter=buffer_lock +$ ./camera_streamer -camera-path=/base/soc/i2c0mux/i2c@1/imx519@1a -camera-type=libcamera -camera-format=YUYV -camera-fps=10 -camera-width=2328 -camera-height=1748 -camera-high_res_factor=1.5 -log-filter=buffer_lock device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf2 (refs=2), frame=585/0, processing_ms=155.3, frame_ms=100.0 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf0 (refs=2), frame=586/0, processing_ms=155.5, frame_ms=100.2 # direct ISP-mode -$ ./camera_stream -camera-path=/dev/video0 -camera-format=RG10 -camera-fps=10 -camera-width=2328 -camera-height=1748 -camera-high_res_factor=1.5 -log-filter=buffer_lock +$ ./camera_streamer -camera-path=/dev/video0 -camera-format=RG10 -camera-fps=10 -camera-width=2328 -camera-height=1748 -camera-high_res_factor=1.5 -log-filter=buffer_lock device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf1 (refs=2), frame=260/0, processing_ms=57.5, frame_ms=99.7 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf2 (refs=2), frame=261/0, processing_ms=57.6, frame_ms=100.0 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf0 (refs=2), frame=262/0, processing_ms=58.0, frame_ms=100.4 @@ -254,13 +254,13 @@ device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf0 (refs= ```shell # libcamera -$ ./camera_stream -camera-path=/base/soc/i2c0mux/i2c@1/imx519@1a -camera-type=libcamera -camera-format=YUYV -camera-fps=120 -camera-width=1280 -camera-height=720 -log-filter=buffer_lock +$ ./camera_streamer -camera-path=/base/soc/i2c0mux/i2c@1/imx519@1a -camera-type=libcamera -camera-format=YUYV -camera-fps=120 -camera-width=1280 -camera-height=720 -log-filter=buffer_lock device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf0 (refs=2), frame=139/0, processing_ms=20.1, frame_ms=7.9 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf1 (refs=2), frame=140/0, processing_ms=20.6, frame_ms=8.8 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf2 (refs=2), frame=141/0, processing_ms=19.8, frame_ms=8.1 # direct ISP-mode -$ ./camera_stream -camera-path=/dev/video0 -camera-format=RG10 -camera-fps=120 -camera-width=1280 -camera-height=720 -log-filter=buffer_lock +$ ./camera_streamer -camera-path=/dev/video0 -camera-format=RG10 -camera-fps=120 -camera-width=1280 -camera-height=720 -log-filter=buffer_lock device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf0 (refs=2), frame=157/0, processing_ms=18.5, frame_ms=8.4 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf1 (refs=2), frame=158/0, processing_ms=18.5, frame_ms=8.3 device/buffer_lock.c: http_jpeg: Captured buffer JPEG:capture:mplane:buf2 (refs=2), frame=159/0, processing_ms=18.5, frame_ms=8.3 diff --git a/imx519_camera.sh b/tools/csi_camera.sh similarity index 99% rename from imx519_camera.sh rename to tools/csi_camera.sh index 501df22..3c9b8fc 100755 --- a/imx519_camera.sh +++ b/tools/csi_camera.sh @@ -1,7 +1,7 @@ #!/bin/bash SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -cd "$SCRIPT_DIR" +cd "$SCRIPT_DIR/.." CAMERA_PATH=$(echo /dev/v4l/by-path/*.csi-video-index0) diff --git a/tools/dump_cameras.sh b/tools/dump_cameras.sh new file mode 100755 index 0000000..22339bc --- /dev/null +++ b/tools/dump_cameras.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -x + +v4l2-ctl --list-devices + +for device in /dev/video*; do + v4l2-ctl -d "$device" -L + v4l2-ctl -d "$device" --list-formats-out + v4l2-ctl -d "$device" --list-formats-ext +done diff --git a/libcamera_camera.sh b/tools/libcamera_camera.sh similarity index 92% rename from libcamera_camera.sh rename to tools/libcamera_camera.sh index 2018892..1ec5ddf 100755 --- a/libcamera_camera.sh +++ b/tools/libcamera_camera.sh @@ -1,7 +1,7 @@ #!/bin/bash SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -cd "$SCRIPT_DIR" +cd "$SCRIPT_DIR/.." set -xeo pipefail make -j$(nproc) diff --git a/tools/rpi_measure.sh b/tools/rpi_measure.sh new file mode 100755 index 0000000..65747bc --- /dev/null +++ b/tools/rpi_measure.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Taken from: https://gist.github.com/TheRemote/10bda1ac790f959210db5789f5241436 + +# Output current configuration +#vcgencmd get_config int | egrep "(arm|core|gpu|sdram)_freq|over_volt" + +# Measure clock speeds +for src in arm core h264 isp v3d; do echo -e "$src:\t$(vcgencmd measure_clock $src)"; done + +# Measure Volts +for id in core sdram_c sdram_i sdram_p ; do echo -e "$id:\t$(vcgencmd measure_volts $id)"; done + +# Measure Temperature +vcgencmd measure_temp + +# See if we are being throttled +throttled="$(vcgencmd get_throttled)" +echo -e "$throttled" +if [[ $throttled != "throttled=0x0" ]]; then + echo "WARNING: You are being throttled. This is likely because you are undervoltage. Please connect your PI to a better power supply!" +fi diff --git a/usb_camera.sh b/tools/usb_camera.sh similarity index 91% rename from usb_camera.sh rename to tools/usb_camera.sh index a8b5856..5119103 100755 --- a/usb_camera.sh +++ b/tools/usb_camera.sh @@ -1,7 +1,7 @@ #!/bin/bash SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -cd "$SCRIPT_DIR" +cd "$SCRIPT_DIR/.." set -xeo pipefail make -j$(nproc)