Update 2024-12-23 12:39 OpenBSD/amd64-t14
This commit is contained in:
parent
b3b69a682a
commit
1ecd621a69
57
.bin/cam
57
.bin/cam
@ -1,27 +1,40 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# defaults
|
||||||
|
_format="-input_format mjpeg"
|
||||||
|
|
||||||
|
# loop through arguments
|
||||||
for arg in $@
|
for arg in $@
|
||||||
do
|
do
|
||||||
|
# set values based of arguments found
|
||||||
case $arg in
|
case $arg in
|
||||||
start) shift; _start=1 ;;
|
s|start) shift; _start=1 ;;
|
||||||
stop) shift; _stop=1 ;;
|
k|kill|stop) shift; _stop=1 ;;
|
||||||
list) shift; _list=1 ;;
|
l|list) shift; _list=1 ;;
|
||||||
mjpeg) shift; _format="-input_format mjpeg" ;;
|
|
||||||
raw) shift; _format="-input_format yuyv422" ;;
|
raw) shift; _format="-input_format yuyv422" ;;
|
||||||
fullhd) shift; _res="-video_size 1920x1080" ;;
|
fullhd) shift; _res="-video_size 1920x1080" ;;
|
||||||
hd) shift; _res="-video_size 1280x720" ;;
|
hd) shift; _res="-video_size 1280x720" ;;
|
||||||
sd) shift; _res="-video_size 640x360" ;;
|
sd) shift; _res="-video_size 640x360" ;;
|
||||||
max) shift; _res=max ;;
|
30) shift; _fps="-framerate 30" ;;
|
||||||
|
60) shift; _fps="-framerate 60" ;;
|
||||||
|
max) shift; _res="max" ;;
|
||||||
[0-9]*x[0-9]*) shift; _res="-video_size $arg" ;;
|
[0-9]*x[0-9]*) shift; _res="-video_size $arg" ;;
|
||||||
*) _dev="$arg" ;;
|
[0-9]) shift; _dev="$arg" ;;
|
||||||
|
*) shift; _unknown="$_unknown $arg" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ ! -z "$_unknown" ]
|
||||||
|
then
|
||||||
|
echo "unknown parameter(s): $_unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
# set device
|
# set device
|
||||||
if [ -z "$_dev" ]
|
if [ -z "$_dev" ]
|
||||||
then
|
then
|
||||||
_dev="/dev/video0"
|
_dev="/dev/video0"
|
||||||
|
else
|
||||||
|
_dev="/dev/video$_dev"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set resolution
|
# set resolution
|
||||||
@ -29,9 +42,9 @@ if [ x"$_res" == x"max" ]
|
|||||||
then
|
then
|
||||||
_res="-video_size $(ffplay -f v4l2 -list_formats all -i $_dev 2>&1 \
|
_res="-video_size $(ffplay -f v4l2 -list_formats all -i $_dev 2>&1 \
|
||||||
| grep mjpeg \
|
| grep mjpeg \
|
||||||
|
| xargs \
|
||||||
| cut -d":" -f4 \
|
| cut -d":" -f4 \
|
||||||
| cut -d " " -f2 \
|
| cut -d " " -f2 \
|
||||||
| tr-d " " \
|
|
||||||
)"
|
)"
|
||||||
_format="-input_format mjpeg"
|
_format="-input_format mjpeg"
|
||||||
fi
|
fi
|
||||||
@ -39,40 +52,50 @@ fi
|
|||||||
# list supported formats + resolutions
|
# list supported formats + resolutions
|
||||||
if [ ! -z "$_list" ]
|
if [ ! -z "$_list" ]
|
||||||
then
|
then
|
||||||
ffplay -f v4l2 -list_formats all -i $_dev 2>&1 \
|
command="$(echo "ffplay -f v4l2 -list_formats all -i $_dev")"
|
||||||
|
echo "starting: $command"
|
||||||
|
$command 2>&1 \
|
||||||
| grep '^\[video4linux2' \
|
| grep '^\[video4linux2' \
|
||||||
| cut -d: -f3,4
|
| cut -d: -f3,4 \
|
||||||
|
| sed -e 's/^[ \t]*//;s/ : /: /'
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
command="$(echo "ffplay -loglevel quiet -f v4l2 $_format $_res -i $_dev" | xargs)"
|
|
||||||
|
|
||||||
if [ ! -z "$_start" ]
|
if [ ! -z "$_start" ]
|
||||||
then
|
then
|
||||||
echo "starting: $command"
|
command="ffplay -loglevel quiet -f v4l2 $_fps $_format $_res -i $_dev"
|
||||||
$command > /dev/null 2>&1 &
|
echo "starting: $command" | xargs
|
||||||
|
_SWM_WS=-1 $command > /dev/null 2>&1 &
|
||||||
|
[ $? -ne 0 ] \
|
||||||
|
&& echo "ffplay couldn't start"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "$_stop" ]
|
if [ ! -z "$_stop" ]
|
||||||
then
|
then
|
||||||
echo "stopping: $command"
|
echo "stopping: ffplay -loglevel quiet -f v4l2"
|
||||||
pkill -qf "$command"
|
pkill -qf "ffplay -loglevel quiet -f v4l2"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $(( _start + _stop + _list )) -eq 0 ]
|
if [ $(( _start + _stop + _list )) -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "usage: cam command [format] [resolution] [device]"
|
echo "usage: cam command [framerate] [format] [resolution] [device]"
|
||||||
echo " commands:"
|
echo " commands:"
|
||||||
echo " start - start camera"
|
echo " start - start camera"
|
||||||
echo " stop - stop camera"
|
echo " stop - stop camera"
|
||||||
echo " list - list supported formats and resolutions"
|
echo " list - list supported formats and resolutions"
|
||||||
echo " formats:"
|
echo " formats:"
|
||||||
|
echo " raw - reads the yuyv422 stream (default is mjpeg)"
|
||||||
|
echo " resolutions:"
|
||||||
echo " sd - set video size to 640x360"
|
echo " sd - set video size to 640x360"
|
||||||
echo " hd - set video size to 1280x720"
|
echo " hd - set video size to 1280x720"
|
||||||
echo " fullhd - set video size to 1920x1080"
|
echo " fullhd - set video size to 1920x1080"
|
||||||
echo " max - set maximum video size (implies mjpeg format)"
|
echo " max - set maximum video size (implies mjpeg format)"
|
||||||
echo " <width>x<height> - manually set resolution (see list command)"
|
echo " <width>x<height> - manually set resolution (see list command)"
|
||||||
echo " <device> - set video device (defaults to /dev/video0)"
|
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)"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user