Complete webcam script

From MyWiki
Revision as of 11:35, 23 February 2016 by George2 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#!/bin/sh
cd /var/www/html/cam
 
# If the temp.html file exists then the prog is already running
# Take it as a lock file
 
if [ -f temp.html ]
then
exit
fi
 
 
echo "<html>" > temp.html
echo "<body>"  >> temp.html
for i in `ls -t *.avi`
do
echo "Found file $i"
 
ROOTNAME=`echo $i | awk 'BEGIN{FS="."} {print $1}'`
 
if [ ! -f ${ROOTNAME}.html ]
then
 
        ## Make sure the file is not being written
        SUM1=`sum $i | sed 's/ *//g'`
        sleep 5
 
 
 
        SUM2=`sum $i | sed 's/ *//g'`
        if [ $SUM1 -ne $SUM2 ]
        then
        echo "File $i is being written, we shall ignore"
        continue
        fi
else
 echo "No need for checksum on $i"
fi
 
echo "Checking for a still imag for file  $i"
echo "The rootname is $ROOTNAME"
 
if [ -f "${ROOTNAME}.png" ]
then
echo "The thumbnail ${ROOTNAME}.png exists"
else
echo "Creating thumbnail ${ROOTNAME}.png"
ffmpeg -i $i -ss 00:00:01.000 -s 160x90 -vframes 1  ${ROOTNAME}.png
fi
 
 
if [ -f "${ROOTNAME}.mp4" ]
then
echo "The video file ${ROOTNAME}.mp4 exists"
else
echo "Creating mp4 ${ROOTNAME}.mp4"
ffmpeg -i $i   ${ROOTNAME}.mp4
fi
 
if [ -f "${ROOTNAME}.ogg" ]
then
echo "The video file ${ROOTNAME}.ogg exists"
else
echo "Creating ogg ${ROOTNAME}.ogg"
ffmpeg -i $i   ${ROOTNAME}.ogg
fi
 
if [ -f "${ROOTNAME}.html" ]
then
echo "The html file ${ROOTNAME}.html exists"
else
echo "Creating html ${ROOTNAME}.html"
 
cat << EOF > ${ROOTNAME}.html
 
<HTML>
<BODY>
<video width="1200" controls>
 
      <source src="${ROOTNAME}.mp4" type="video/mp4">
 
      <source src="${ROOTNAME}.ogg" type="video/ogg">
 
  Your browser does not support HTML5 video.
 
</video>
 
</BODY>
</HTML>
 
 
EOF
 
fi
echo "<a  href=${ROOTNAME}.html><img src=${ROOTNAME}.png  /></a>"  >> temp.html
 
 
 
done
 echo "</body>" >> temp.html
 echo "</html>" >> temp.html
 
 
mv temp.html index.html