#!/usr/bin/bash # EDIT THESE FIRST: video device and its resolution, and display (output) resolution vdev=/dev/video0; rx=2592; ry=1944; dx=1920; dy=1080 # THEN EDIT THESE TO YOUR LIKING: rotation, zoom, crosshairs thickness and color r=0; z=1; t=5; c=red x=$((dx/2)); y=$((dy/2)); # Crosshairs start at center of screen rot=$r if [ $(echo "($r*100)/1"|bc) == 157 ]; then rot=PI/2; fi # The rotation is given in radians. if [ $(echo "($r*100)/1"|bc) == 314 ]; then rot=PI; fi # Use exact values at 90/180/270 degrees. if [ $(echo "($r*100)/1"|bc) == 471 ]; then rot=3*PI/2; fi # Yes, FFplay understands these character expressions # Start the video player in the background, and continue executing the script ffplay -loglevel quiet -input_format mjpeg -video_size "$rx"x"$ry" -i $vdev -vf zmq,rotate=$rot,crop=$(echo "($rx/$z)/1"|bc):$(echo "($ry/$z)/1"|bc),scale=$dx:$dy,drawgrid=x=$x:y=$y:w=10000:h=10000:t=$t:c=$c & while [ "$k" != "q" ]; do read -s -n1 k; if [ "$k" == "Q" ]; then k=q; fi # Quit if [ "$k" == "l" ]; then r=$(echo "$r-0.01"|bc); k="rot"; fi # Rotation if [ "$k" == "L" ]; then r=$(echo "$r-0.1"|bc); k="rot"; fi if [ "$k" == "r" ]; then r=$(echo "$r+0.01"|bc); k="rot"; fi if [ "$k" == "R" ]; then r=$(echo "$r+0.1"|bc); k="rot"; fi if [ "$k" == `printf "\u1b"` ]; then read -s -n1 k read -s -n1 k if [ "$k" == "A" ]; then y=$((y-2)); k="ydir" # Arrow keys for crosshairs elif [ "$k" == "B" ]; then y=$((y+2)); k="ydir" elif [ "$k" == "C" ]; then x=$((x+2)); k="xdir" elif [ "$k" == "D" ]; then x=$((x-2)); k="xdir" elif [ "$k" == "1" ]; then read -s -n1 k; read -s -n1 k; read -s -n1 k; if [ "$k" == "A" ]; then y=$((y-20)); k="ydir" # Shift + arrow keys for crosshairs elif [ "$k" == "B" ]; then y=$((y+20)); k="ydir" elif [ "$k" == "C" ]; then x=$((x+20)); k="xdir" elif [ "$k" == "D" ]; then x=$((x-20)); k="xdir"; fi fi; fi if [ $(echo "($r*100)/1"|bc) -lt 0 ]; then r=$(echo "$r+6.28"|bc); fi; # Rotation min/max if [ $(echo "($r*100)/1"|bc) -ge 628 ]; then r=$(echo "$r-6.28"|bc); fi; rot=$r if [ $(echo "($r*100)/1"|bc) == 157 ]; then rot=PI/2; fi # Exact values at 90/180/270 degrees if [ $(echo "($r*100)/1"|bc) == 314 ]; then rot=PI; fi if [ $(echo "($r*100)/1"|bc) == 471 ]; then rot=3*PI/2; fi if [ $x -lt 0 ]; then x=0; fi; if [ $x -ge $dx ]; then x=$((vx-1)); fi # Crosshairs min/max if [ $y -lt 0 ]; then y=0; fi; if [ $y -ge $dy ]; then y=$((vy-1)); fi if [ $k == "rot" ]; then echo "Parsed_rotate_1 a $r" | zmqsend &>/dev/null; echo "Rotation: r=$r"; fi if [ $k == "xdir" ]; then echo "Parsed_drawgrid_4 x $x" | zmqsend &>/dev/null; fi if [ $k == "ydir" ]; then echo "Parsed_drawgrid_4 y $y" | zmqsend &>/dev/null; fi done killall ffplay