每当两个MD5校验和($ SUMCHK1& $ SUMCHK2)在这个脚本中匹配时,我就会卡在最里面的while循环中,所以脚本永远不会结束。当两个日志文件匹配时,我会在屏幕上得到两个md5sums的无尽回声。
#!/bin/bash
FULLPATH=$1
FPS=$2
AVI=$(basename $1)
AVIDIR=$HOME/q7video/$AVI
TMPFILE=$AVIDIR/tmp.txt
TMPFILE2=$AVIDIR/tmp2.txt
NEWFILES=$AVIDIR/tmp3.txt
FFLOG=$AVIDIR/ffmpeg.log
LOGFILE=$AVIDIR/log.log
FACESDIR=$AVIDIR/faces
# CREATE FOLDER STRUCTURE, NO ERROR IF DIR PRE-EXISTS
mkdir --parents $AVIDIR
mkdir --parents $FACESDIR
touch $TMPFILE $TMPFILE2 $NEWFILES $LOGFILE
echo $AVI > $LOGFILE
# DUMP THUMBNAILS FROM SPECIFIED AVI FILE
ffmpeg -i $FULLPATH -f image2 -vf fps=fps=$FPS $AVIDIR/$AVI%03d.jpg </dev/null >/dev/null 2>$FFLOG &
# DELAY TO ALLOW LOOP A WORKING DIRECTORY BEFORE START
sleep 2
#TOUCH FILES TO PREVENT NO FILE ERROR
touch $TMPFILE $TMPFILE2
# INITIALIZE VARIABLE FOR LOOP
CHECK=`pgrep ffmpeg`
I=0
SUMCHK1=`md5sum $TMPFILE`
SUMCHK2=`md5sum $TMPFILE2`
while [[ "$CHECK" -gt "$I" ]]; do
sleep 2
echo FFMPEG RUNNING
ls $AVIDIR/*.jpg > $TMPFILE
while [[ "$SUMCHK1" != "$SUMCHK2" ]]; do
comm -23 $TMPFILE $TMPFILE2 > $NEWFILES
while read F ; do
echo $F
echo $F >> $TMPFILE2
echo $F >> $LOGFILE
python opencvtest.py $F >> $LOGFILE
done < $NEWFILES
ls $AVIDIR/*.jpg > $TMPFILE
SUMCHK1=`md5sum $TMPFILE`
SUMCHK2=`md5sum $TMPFILE2`
echo $SUMCHK1
echo $SUMCHK2
done
CHECK=`pgrep ffmpeg`
echo $CHECK
done
# COPY IMAGES WITH A FACE TO FACESDIR
# CLEANUP LOGS
#rm $TMPFILE $TMPFILE2 $NEWFILES
答案 0 :(得分:0)
这可以在不需要校验和的情况下完成。
# INITIALIZE VARIABLE FOR LOOP
CHECK=`pgrep ffmpeg`
I=0
while [[ "$CHECK" -gt "$I" ]]; do
sleep 2
echo FFMPEG RUNNING
# get the current file list
ls -1 $AVIDIR/*.jpg | sort > $TMPFILE
# compare current file list with previous list and extract new file list
comm -23 $TMPFILE $TMPFILE2 > $NEWFILES
# process new files
while read F ; do
echo $F
echo $F >> $LOGFILE
python opencvtest.py $F >> $LOGFILE
done < $NEWFILES
# save the current file list to be used as previous list in next run
cp $TMPFILE $TMPFILE2
CHECK=`pgrep ffmpeg`
echo $CHECK
done
另外,ffmpeg
完成后应再次执行循环体,以确保不会从处理中跳过最后一组图像。