Skip to content

Instantly share code, notes, and snippets.

@kbingham
Last active August 11, 2020 10:34
Show Gist options
  • Save kbingham/d7346b759bc6ae42f6af14cef0868bd2 to your computer and use it in GitHub Desktop.
Save kbingham/d7346b759bc6ae42f6af14cef0868bd2 to your computer and use it in GitHub Desktop.
Configure and capture multiple streams from VIMC
#!/bin/bash
MEDIA=/dev/$(grep VIMC /sys/bus/media/devices/media*/model | sed 's/.*\(media[0-9]*\).*/\1/g')
function v4l2_dev() {
grep "$1" /sys/class/video4linux/video*/name | sed 's#.*\(video[0-9]*\)/.*#\1#g'
}
RAW0=/dev/$(v4l2_dev "Raw Capture 0")
RAW1=/dev/$(v4l2_dev "Raw Capture 1")
RGBYUV=/dev/$(v4l2_dev "RGB/YUV Capture")
echo "Media: $MEDIA"
echo "Raw Capture 0: $RAW0"
echo "Raw Capture 1: $RAW1"
echo "RGB/YUV Capture: $RGBYUV"
# Reset links
media-ctl -r $MEDIA
media-ctl -d $MEDIA -V '"Sensor A":0[fmt:SBGGR8_1X8/640x480]'
media-ctl -d $MEDIA -V '"Debayer A":0[fmt:SBGGR8_1X8/640x480]'
media-ctl -d $MEDIA -V '"Sensor B":0[fmt:SBGGR8_1X8/640x480]'
media-ctl -d $MEDIA -V '"Debayer B":0[fmt:SBGGR8_1X8/640x480]'
media-ctl -d $MEDIA -V '"Scaler":0[fmt:RGB888_1X24/640x480]'
media-ctl -d $MEDIA -V '"Scaler":1[fmt:RGB888_1X24/1920x1440]'
# Disable link from A, and enable B
media-ctl -d $MEDIA -l "'Debayer A':1 -> 'Scaler':0 [0]"
media-ctl -d $MEDIA -l "'Debayer B':1 -> 'Scaler':0 [1]"
v4l2-ctl -d $RAW0 -v pixelformat=BA81
v4l2-ctl -d $RAW1 -v pixelformat=BA81
v4l2-ctl -d $RGBYUV -v width=1920,height=1440
set -x
pids=()
while [[ $# != 0 ]] ; do
option=$1
shift
case ${option} in
-r|--raw)
yavta -c30 $RAW1 &
pids+=($!)
;;
-y|--yuv)
yavta -c30 $RGBYUV &
pids+=($!)
;;
esac
done;
# wait for all pids
for pid in ${pids[*]}; do
wait $pid
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment