...useless but hey - bash webcam viewer (intentionally posted on April 2nd because it actually works ;-P)

...one thing i never can remember is the commandline options to view my webcam per mplayer... so i thought about reading the stream directly from v4l to check if everything is up and running:
here's a tiny script that displays the direct 320x240 YUYV 4:2:2 stream of a v4l /dev/video device.
...source of the script:
#!/bin/bash
draw=1;lcnt=0;fcnt=0;str="";N=$[1280*8]
# get 320x240 YUYV 4:2:2 byte srteam -> xxd: convert bytes to hex digits
v4l2-ctl -d /dev/video0 \
--set-fmt-video=width=320,height=240,pixelformat=YUYV \
--stream-mmap --stream-count=0 \
--stream-to=/dev/stdout | xxd -p -c0 \
| while true; do
read -n$N b # read 8 scanlines (640*2*8 chars)
# take every 16th hex-char (=upper bits of every 8th byte)
str+="$(echo -n ${b:0:1264} | sed 's/\(.\).\{15\}/\1/g')"
str+=$'\n'
# line count and print frame when complete
lcnt=$[lcnt+1];
if [ $lcnt = 30 ]; then lcnt=0; echo "$str"; echo; echo; str=""; fcnt=$[fcnt+1]; fi
done \
| tr "0123456789abcdef" " \.\-=:;|lrcoabUAB"
# convert hex digit to brightness-chars
...one could also use the U-V information in every second byte and display colors by escape sequences - but lets not overact ;)