2024-02-14 07:54:31 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-12-23 12:39:36 +01:00
|
|
|
# defaults
|
|
|
|
_format="-input_format mjpeg"
|
2024-12-23 12:49:42 +01:00
|
|
|
_dev="/dev/video0"
|
2024-12-23 12:39:36 +01:00
|
|
|
|
|
|
|
# loop through arguments
|
2024-12-23 11:30:16 +01:00
|
|
|
for arg in $@
|
|
|
|
do
|
2024-12-23 12:39:36 +01:00
|
|
|
# set values based of arguments found
|
2024-12-23 11:30:16 +01:00
|
|
|
case $arg in
|
2024-12-23 12:39:36 +01:00
|
|
|
s|start) shift; _start=1 ;;
|
|
|
|
k|kill|stop) shift; _stop=1 ;;
|
|
|
|
l|list) shift; _list=1 ;;
|
2024-12-23 13:03:14 +01:00
|
|
|
30) shift; _fps="-framerate 30" ;;
|
|
|
|
60) shift; _fps="-framerate 60" ;;
|
2024-12-23 11:30:16 +01:00
|
|
|
raw) shift; _format="-input_format yuyv422" ;;
|
|
|
|
fullhd) shift; _res="-video_size 1920x1080" ;;
|
|
|
|
hd) shift; _res="-video_size 1280x720" ;;
|
|
|
|
sd) shift; _res="-video_size 640x360" ;;
|
2024-12-23 12:39:36 +01:00
|
|
|
max) shift; _res="max" ;;
|
2024-12-23 11:45:57 +01:00
|
|
|
[0-9]*x[0-9]*) shift; _res="-video_size $arg" ;;
|
2024-12-23 12:39:36 +01:00
|
|
|
[0-9]) shift; _dev="$arg" ;;
|
|
|
|
*) shift; _unknown="$_unknown $arg" ;;
|
2024-12-23 11:30:16 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-12-23 12:39:36 +01:00
|
|
|
if [ ! -z "$_unknown" ]
|
|
|
|
then
|
|
|
|
echo "unknown parameter(s): $_unknown"
|
|
|
|
fi
|
2024-12-23 11:30:16 +01:00
|
|
|
|
|
|
|
# set resolution
|
|
|
|
if [ x"$_res" == x"max" ]
|
|
|
|
then
|
|
|
|
_res="-video_size $(ffplay -f v4l2 -list_formats all -i $_dev 2>&1 \
|
|
|
|
| grep mjpeg \
|
2024-12-23 12:39:36 +01:00
|
|
|
| xargs \
|
2024-12-23 11:30:16 +01:00
|
|
|
| cut -d":" -f4 \
|
|
|
|
| cut -d " " -f2 \
|
|
|
|
)"
|
|
|
|
_format="-input_format mjpeg"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# list supported formats + resolutions
|
|
|
|
if [ ! -z "$_list" ]
|
|
|
|
then
|
2024-12-23 12:39:36 +01:00
|
|
|
command="$(echo "ffplay -f v4l2 -list_formats all -i $_dev")"
|
|
|
|
echo "starting: $command"
|
|
|
|
$command 2>&1 \
|
2024-12-23 11:30:16 +01:00
|
|
|
| grep '^\[video4linux2' \
|
2024-12-23 12:39:36 +01:00
|
|
|
| cut -d: -f3,4 \
|
|
|
|
| sed -e 's/^[ \t]*//;s/ : /: /'
|
2024-12-23 11:30:16 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$_start" ]
|
|
|
|
then
|
2024-12-23 12:39:36 +01:00
|
|
|
command="ffplay -loglevel quiet -f v4l2 $_fps $_format $_res -i $_dev"
|
|
|
|
echo "starting: $command" | xargs
|
|
|
|
_SWM_WS=-1 $command > /dev/null 2>&1 &
|
|
|
|
[ $? -ne 0 ] \
|
|
|
|
&& echo "ffplay couldn't start"
|
2024-12-23 11:30:16 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
2024-12-23 12:39:36 +01:00
|
|
|
|
2024-12-23 11:30:16 +01:00
|
|
|
if [ ! -z "$_stop" ]
|
|
|
|
then
|
2024-12-23 12:39:36 +01:00
|
|
|
echo "stopping: ffplay -loglevel quiet -f v4l2"
|
|
|
|
pkill -qf "ffplay -loglevel quiet -f v4l2"
|
2024-12-23 11:30:16 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $(( _start + _stop + _list )) -eq 0 ]
|
|
|
|
then
|
2024-12-23 12:39:36 +01:00
|
|
|
echo "usage: cam command [framerate] [format] [resolution] [device]"
|
2024-12-23 11:30:16 +01:00
|
|
|
echo " commands:"
|
|
|
|
echo " start - start camera"
|
|
|
|
echo " stop - stop camera"
|
|
|
|
echo " list - list supported formats and resolutions"
|
|
|
|
echo " formats:"
|
2024-12-23 12:39:36 +01:00
|
|
|
echo " raw - reads the yuyv422 stream (default is mjpeg)"
|
|
|
|
echo " resolutions:"
|
2024-12-23 11:30:16 +01:00
|
|
|
echo " sd - set video size to 640x360"
|
|
|
|
echo " hd - set video size to 1280x720"
|
|
|
|
echo " fullhd - set video size to 1920x1080"
|
|
|
|
echo " max - set maximum video size (implies mjpeg format)"
|
|
|
|
echo " <width>x<height> - manually set resolution (see list command)"
|
2024-12-23 12:39:36 +01:00
|
|
|
echo " framerates:"
|
|
|
|
echo " 30 - set framerate to 30 fps"
|
|
|
|
echo " 60 - set framerate to 60 fps"
|
|
|
|
echo " <device> - set video device number (defaults is 0)"
|
2024-12-23 12:49:42 +01:00
|
|
|
echo
|
|
|
|
echo " Note: ffplay may not start or fall back to internal defaults when options (or combinations thereof) are not supported by the camera."
|
2024-12-23 11:30:16 +01:00
|
|
|
exit 2
|
|
|
|
fi
|