From aebf5417932011de5974c6c4bab45591a177fde4 Mon Sep 17 00:00:00 2001 From: Shravan Chippa Date: Tue, 1 Aug 2023 21:21:24 +0530 Subject: [PATCH] mpfs-video-kit: multimedia v4l2 scripts add script "fswebcam_1280x720.sh" to capture jpg image add script "fswebcam_1920x1080.sh" to capture jpg image add script "imx334_1280x720.sh" to capture 10 raw frames add script "imx334_1920x1080.sh" to capture 10 raw frames Signed-off-by: Shravan Chippa --- multimedia/v4l2/LICENSE | 8 ++ multimedia/v4l2/README.md | 192 ++++++++++++++++++++++++++ multimedia/v4l2/fswebcam_1280x720.sh | 9 ++ multimedia/v4l2/fswebcam_1920x1080.sh | 10 ++ multimedia/v4l2/imx334_1280x720.sh | 8 ++ multimedia/v4l2/imx334_1920x1080.sh | 8 ++ 6 files changed, 235 insertions(+) create mode 100644 multimedia/v4l2/LICENSE create mode 100644 multimedia/v4l2/README.md create mode 100755 multimedia/v4l2/fswebcam_1280x720.sh create mode 100755 multimedia/v4l2/fswebcam_1920x1080.sh create mode 100755 multimedia/v4l2/imx334_1280x720.sh create mode 100755 multimedia/v4l2/imx334_1920x1080.sh diff --git a/multimedia/v4l2/LICENSE b/multimedia/v4l2/LICENSE new file mode 100644 index 0000000..c65ffe6 --- /dev/null +++ b/multimedia/v4l2/LICENSE @@ -0,0 +1,8 @@ +Copyright 2023 MICROCHIP TECHNOLOGY INC + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/multimedia/v4l2/README.md b/multimedia/v4l2/README.md new file mode 100644 index 0000000..51363f7 --- /dev/null +++ b/multimedia/v4l2/README.md @@ -0,0 +1,192 @@ +# PolarFire SoC Video Kit Frame Capture Examples Scripts + +These example scripts show how to capture frames in raw Bayer format and stream them to a file in raw or jpg format. + +## Bayer Pipeline + +The bayer pipeline consists of the following IP's (exposing the nodes from the corresponding drivers): + +`Imx334 camera (SRGGB10 format /dev/v4l-subdev0)` --> `MIPI CSI2 IP (serial data to parallel data /dev/v4l-subdev1)` --> `Video DMA IP (/dev/video0)` + +## Prerequisites + +- Make sure that the Bayer pipeline design is programmed to the PolarFire SoC Video Kit. A FlashPro Express programming job file can be found in the Video Kit reference design [ref link](https://mi-v-ecosystem.github.io/redirects/releases-video-kit-reference-design). + +- The examples expect following nodes to be present at runtime: + - Video device nodes: + - /dev/video0, + - /dev/v4l-subdev0, + - /dev/v4l-subdev1, + - Media device nodes: + - /dev/media0. + +Where /dev/video0 is responsible for capturing the images and /dev/media0 for changing the resolution and format. + +## Command to load bayer format pipeline + +Stop at U-boot prompt and run the below command to load the bayer pipeline + +```sh +load mmc 0:1 ${scriptaddr} fitImage; +bootm start ${scriptaddr}#conf-microchip_mpfs-video-kit.dtb#conf-mpfs_video_bayer.dtbo; +bootm loados ${scriptaddr}; +bootm ramdisk; +bootm prep; +fdt set /soc/ethernet@20112000 mac-address ${videokit_mac_addr0}; +fdt set /soc/ethernet@20110000 mac-address ${videokit_mac_addr0}; +bootm go; +``` + +## Command to capture JPG image with 1280x720 resolution + +```sh +/opt/microchip/multimedia/v4l2/fswebcam_1280x720.sh +``` + +A successful execution should look like: + +```text +root@mpfs-video-kit:~# /opt/microchip/multimedia/v4l2/fswebcam_1280x720.sh +Opening media device /dev/media0 +Enumerating entities +looking up device: 81:0 +looking up device: 81:1 +looking up device: 81:2 +Found 3 entities +Enumerating pads and links +Setting up format SRGGB10_1X10 1280x720 on pad imx334 0-001a/0 +Format set: SRGGB10_1X10 1280x720 +Setting up format SRGGB10_1X10 1280x720 on pad 60001000.csi2rx/0 +Format set: SRGGB10_1X10 1280x720 +Opening media device /dev/media0 +Enumerating entities +looking up device: 81:0 +looking up device: 81:1 +looking up device: 81:2 +Found 3 entities +Enumerating pads and links +Setting up format SRGGB8_1X8 1280x720 on pad 60001000.csi2rx/1 +Format set: SRGGB8_1X8 1280x720 +--- Opening /dev/video0... +Trying source module v4l2... +/dev/video0 opened. +No input was specified, using the first. +--- Capturing frame... +Captured frame in 0.00 seconds. +--- Processing captured image... +Disabling banner. +Writing JPEG image to '/home/root/2022-04-29_0039.jpg'. +root@mpfs-video-kit:~# + +``` + +## Command to capture JPG image with 1920x1080 resolution + +```sh +/opt/microchip/multimedia/v4l2/fswebcam_1920x1080.sh +``` + +A successful execution should look like: + +```text +root@mpfs-video-kit:~# /opt/microchip/multimedia/v4l2/fswebcam_1920x1080.sh +Opening media device /dev/media0 +Enumerating entities +looking up device: 81:0 +looking up device: 81:1 +looking up device: 81:2 +Found 3 entities +Enumerating pads and links +Setting up format SRGGB10_1X10 1920x1080 on pad imx334 0-001a/0 +Format set: SRGGB10_1X10 1920x1080 +Setting up format SRGGB10_1X10 1920x1080 on pad 60001000.csi2rx/0 +Format set: SRGGB10_1X10 1920x1080 +Opening media device /dev/media0 +Enumerating entities +looking up device: 81:0 +looking up device: 81:1 +looking up device: 81:2 +Found 3 entities +Enumerating pads and links +Setting up format SRGGB10_1X10 1920x1080 on pad 60001000.csi2rx/1 +Format set: SRGGB8_1X8 1920x1080 +--- Opening /dev/video0... +Trying source module v4l2... +/dev/video0 opened. +No input was specified, using the first. +--- Capturing frame... +Captured frame in 0.00 seconds. +--- Processing captured image... +Disabling banner. +Writing JPEG image to '/home/root/2022-04-29_0041.jpg'. +root@mpfs-video-kit:~# + +``` + +## Save 10 raw frames from the camera with 1280x720 resolution + +```sh +/opt/microchip/multimedia/v4l2/imx334_1280x720.sh +``` + +A successful execution should look like: + +```text +root@mpfs-video-kit:~# /opt/microchip/multimedia/v4l2/imx334_1280x720.sh +Opening media device /dev/media0 +Enumerating entities +looking up device: 81:0 +looking up device: 81:1 +looking up device: 81:2 +Found 3 entities +Enumerating pads and links +Setting up format SRGGB10_1X10 1280x720 on pad imx334 0-001a/0 +Format set: SRGGB10_1X10 1280x720 +Setting up format SRGGB10_1X10 1280x720 on pad 60001000.csi2rx/0 +Format set: SRGGB10_1X10 1280x720 +Opening media device /dev/media0 +Enumerating entities +looking up device: 81:0 +looking up device: 81:1 +looking up device: 81:2 +Found 3 entities +Enumerating pads and links +Setting up format SRGGB8_1X8 1280x720 on pad 60001000.csi2rx/1 +Format set: SRGGB8_1X8 1280x720 +<<<<<<<<<<<<<<<<<<<< +root@mpfs-video-kit:~# +``` + +## Save 10 raw frames from the camera with 1920x1080 resolution + +```sh +/opt/microchip/multimedia/v4l2/imx334_1920x1080.sh +``` + +A successful execution should look like: + +```text +root@mpfs-video-kit:~# /opt/microchip/multimedia/v4l2/imx334_1920x1080.sh +Opening media device /dev/media0 +Enumerating entities +looking up device: 81:0 +looking up device: 81:1 +looking up device: 81:2 +Found 3 entities +Enumerating pads and links +Setting up format SRGGB10_1X10 1920x1080 on pad imx334 0-001a/0 +Format set: SRGGB10_1X10 1920x1080 +Setting up format SRGGB10_1X10 1920x1080 on pad 60001000.csi2rx/0 +Format set: SRGGB10_1X10 1920x1080 +Opening media device /dev/media0 +Enumerating entities +looking up device: 81:0 +looking up device: 81:1 +looking up device: 81:2 +Found 3 entities +Enumerating pads and links +Setting up format SRGGB10_1X10 1920x1080 on pad 60001000.csi2rx/1 +Format set: SRGGB8_1X8 1920x1080 +<<<<<<<<<< +root@mpfs-video-kit:~# + diff --git a/multimedia/v4l2/fswebcam_1280x720.sh b/multimedia/v4l2/fswebcam_1280x720.sh new file mode 100755 index 0000000..953631c --- /dev/null +++ b/multimedia/v4l2/fswebcam_1280x720.sh @@ -0,0 +1,9 @@ +media-ctl -v -V '"imx334 0-001a":0 [fmt:SRGGB10_1X10/1280x720 field:none colorspace:srgb xfer:none]' -d /dev/media0 +media-ctl -v -V '"60001000.csi2rx":1 [fmt:SRGGB8_1X8/1280x720 field:none colorspace:srgb xfer:none]' -d /dev/media0 + +v4l2-ctl -d /dev/v4l-subdev1 --set-ctrl=analogue_gain=80 +v4l2-ctl -d /dev/v4l-subdev1 --set-ctrl=vertical_blanking=1170 + +DATE=$(date +"%Y-%m-%d_%H%M") +fswebcam -r 1280x720 --no-banner ~/$DATE.jpg + diff --git a/multimedia/v4l2/fswebcam_1920x1080.sh b/multimedia/v4l2/fswebcam_1920x1080.sh new file mode 100755 index 0000000..ac3839d --- /dev/null +++ b/multimedia/v4l2/fswebcam_1920x1080.sh @@ -0,0 +1,10 @@ + +media-ctl -v -V '"imx334 0-001a":0 [fmt:SRGGB10_1X10/1920x1080 field:none colorspace:srgb xfer:none]' -d /dev/media0 +media-ctl -v -V '"60001000.csi2rx":1 [fmt:SRGGB10_1X10/1920x1080 field:none colorspace:srgb xfer:none]' -d /dev/media0 + +v4l2-ctl -d /dev/v4l-subdev1 --set-ctrl=analogue_gain=80 +v4l2-ctl -d /dev/v4l-subdev1 --set-ctrl=vertical_blanking=1170 + +DATE=$(date +"%Y-%m-%d_%H%M") +fswebcam -r 1920x1080 --no-banner ~/$DATE.jpg + diff --git a/multimedia/v4l2/imx334_1280x720.sh b/multimedia/v4l2/imx334_1280x720.sh new file mode 100755 index 0000000..6332ca8 --- /dev/null +++ b/multimedia/v4l2/imx334_1280x720.sh @@ -0,0 +1,8 @@ +media-ctl -v -V '"imx334 0-001a":0 [fmt:SRGGB10_1X10/1280x720 field:none colorspace:srgb xfer:none]' -d /dev/media0 +media-ctl -v -V '"60001000.csi2rx":1 [fmt:SRGGB8_1X8/1280x720 field:none colorspace:srgb xfer:none]' -d /dev/media0 + +v4l2-ctl -d /dev/v4l-subdev1 --set-ctrl=analogue_gain=80 +v4l2-ctl -d /dev/v4l-subdev1 --set-ctrl=vertical_blanking=1170 + +v4l2-ctl --device /dev/video0 --set-fmt-video=width=1280,height=720,pixelformat=RGGB --stream-mmap --stream-count=10 --stream-to=file.raw + diff --git a/multimedia/v4l2/imx334_1920x1080.sh b/multimedia/v4l2/imx334_1920x1080.sh new file mode 100755 index 0000000..9c12774 --- /dev/null +++ b/multimedia/v4l2/imx334_1920x1080.sh @@ -0,0 +1,8 @@ +media-ctl -v -V '"imx334 0-001a":0 [fmt:SRGGB10_1X10/1920x1080 field:none colorspace:srgb xfer:none]' -d /dev/media0 +media-ctl -v -V '"60001000.csi2rx":1 [fmt:SRGGB10_1X10/1920x1080 field:none colorspace:srgb xfer:none]' -d /dev/media0 + +v4l2-ctl -d /dev/v4l-subdev1 --set-ctrl=analogue_gain=80 +v4l2-ctl -d /dev/v4l-subdev1 --set-ctrl=vertical_blanking=1170 + +v4l2-ctl --device /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=RGGB --stream-mmap --stream-count=10 --stream-to=file.raw +