Skip to content

Commit

Permalink
mpfs-video-kit: multimedia v4l2 scripts
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
shravanI35088 committed Aug 16, 2023
1 parent 60d8d8b commit aebf541
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 0 deletions.
8 changes: 8 additions & 0 deletions multimedia/v4l2/LICENSE
Original file line number Diff line number Diff line change
@@ -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.

192 changes: 192 additions & 0 deletions multimedia/v4l2/README.md
Original file line number Diff line number Diff line change
@@ -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:~#
9 changes: 9 additions & 0 deletions multimedia/v4l2/fswebcam_1280x720.sh
Original file line number Diff line number Diff line change
@@ -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

10 changes: 10 additions & 0 deletions multimedia/v4l2/fswebcam_1920x1080.sh
Original file line number Diff line number Diff line change
@@ -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

8 changes: 8 additions & 0 deletions multimedia/v4l2/imx334_1280x720.sh
Original file line number Diff line number Diff line change
@@ -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

8 changes: 8 additions & 0 deletions multimedia/v4l2/imx334_1920x1080.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit aebf541

Please sign in to comment.