- #!/bin/bash
- # licence GPLv2 ; this scripts designed by IZAMUKARERA 2013.10.12 update 2020.7.27
- # pepomp4ctl ; get video or jpeg
- # pepomp4ctl dev image pid
- #VIDEOPG=ffmpeg
- RASPICAMERA=/dev/vchiq
- RASPIVID=raspivid
- RASPISTILL=raspistill
- VIDEOPG=avconv
- if [ $# != 3 ];then
- echo "$0 video-dev xxx.jpg|xxx.mp4 ppid"
- exit -1
- fi
- WORKDIR=/www/remote-hand/tmp
- PATH=$PATH:/usr/local/bin:/usr/local/sbin
- MP4=`echo $2 | awk 'BEGIN{FS="."};{if($2=="mp4"){printf "YES"} else {printf "NO"}}'`
- DEV=$1
- IMAGE=$2
- ppid=$3
- if [ $MP4 = "YES" ];then
- OPT="-ss 3 -s 320x240 -r 5 -vcodec mpeg4 -t 10"
- else
- OPT="-ss 3 -s 640x480"
- fi
- prog=pepomp4ctl
- pidfile=/var/run/${prog}.pid
- pprog=pepogmail4pic
- ppidfile=/var/run/${pprog}.pid
- WORKIMAGE=${WORKDIR}/${IMAGE}
- error(){
- [ -e ${WORKIMAGE} ] && rm -f ${WORKIMAGE}
- [ -e ${pidfile} ] && rm -f ${pidfile}
- [ -e ${ppidfile} ] && rm -f ${ppidfile}
- exit 0
- }
- trap error SIGINT SIGTERM SIGHUP SIGKILL SIGCHLD
- while [ -e ${pidfile} ];do
- VIDEOPGTIME=`ps ax | grep -v grep|grep ${VIDEOPG} | awk '{split($4,I,":");printf("%2d",I[2])}'`
- if [ "${VIDEOPGTIME}" -gt 10 ];then
- pid=`cat ${pidfile}`
- kill -HUP ${pid}
- pkill -HUP ${VIDEOPG}
- msleep 100
- rm -f ${pidfile}
- rm -f ${ppidfile}
- fi
- done
- while [ ! -z `pgrep ${VIDEOPG}` ];do
- TIMEOUT=`ps ax | grep -v grep|grep avconv | awk '{split($4,I,":");if (I[2] > 10){printf $1}}'`
- if [ ! -z "${TIMEOUT}" ];then
- kill -HUP ${TIMEOUT}
- msleep 100
- break
- fi
- done
- if [ -e ${DEV} ];then
- echo -n $$ >${pidfile}
- echo -n ${ppid} >${ppidfile}
- if [ $DEV != $RASPICAMERA ];then
- ${VIDEOPG} -f video4linux2 -i ${DEV} ${OPT} -y ${WORKIMAGE} >/dev/null 2>&1
- else
- if [ $MP4 != "YES" ];then
- $RASPISTILL -t 1000 -vf -hf -w 1920 -h 1080 -o ${WORKIMAGE} >/dev/null 2>&1
- else
- # $RASPIVID -vf -hf -o - -w 640 -h 480 -t 10000 -fps 5 |${VIDEOPG} -f h264 -r 5 -i - -vcodec mpeg4 -y ${WORKIMAGE} >/dev/null 2>&1
- $RASPIVID -vf -hf -o ${WORKIMAGE}.tmp -w 640 -h 480 -t 10000 -fps 5
- cat ${WORKIMAGE}.tmp |${VIDEOPG} -f h264 -r 5 -i - -vcodec mpeg4 -y ${WORKIMAGE} >/dev/null 2>&1
- rm ${WORKIMAGE}.tmp
- fi
- fi
- rm -f $pidfile
- rm -f ${ppidfile}
- else
- echo "Video device is not connected -> $DEV"
- fi
[PageInfo]
LastUpdate: 2020-07-27 16:12:29, ModifiedBy: pepolinux
[License]
GNU Free Documentation License
[Permissions]
view:all, edit:doc editors, delete/config:doc editors