스크립트를 사용하여 검은색/어두운 타임랩스 사진 삭제

스크립트를 사용하여 검은색/어두운 타임랩스 사진 삭제

저는 ffmpeg를 사용하여 매분(수중) rtsp 스트림을 캡처하고 빛의 10% 미만을 캡처하는 사진을 삭제하고 싶습니다. 이것은 제가 보강하고 싶은 매우 간단한 cron 스크립트입니다.

#!/bin/bash
ffmpeg -loglevel panic -rtsp_transport tcp -y -i "rtsp://user:pass@ipaddress/stream" -frames:v 1 -strftime 1 "/dir/%Y-%m-%d_%H-%M-%S_underwater_cam.jpg"

답변1

방법을 찾았지만 처리 관점에서 볼 때 가장 우아한 솔루션은 아닙니다. 에서 적응이 imagemagick 토론.

#!/bin/bash

set -ea
DIRECTORY=/camera/$(date +%Y-%m-%d)

[ $test -d $DIRECTORY ] && : || mkdir -p $DIRECTORY;

#Loglevel panic is to ignore the transform errors this camera is putting out.  
#Forcing the RTSP transport as TCP to reduce corrupt images. 
#Using date with strftime, however this could probably be done as a variable.
ffmpeg -loglevel panic -rtsp_transport tcp -y -i "rtsp://user:pass@ipaddress/stream" -frames:v 1 -strftime 1 "$DIRECTORY/%Y-%m-%d_%H-%M-%S_underwater_cam.jpg"

cd $DIRECTORY
#Find the most recent image, as it's assumed to be the picture above.
image=`ls -t $DIRECTORY | head -n1`

#threshold in percentage of light using imagemagick
thresh=10
mean=`convert $image -format "%[mean]" info:`
mean=`convert xc: -format "%[fx:100*$mean/quantumrange]" info:`
test=`convert xc: -format "%[fx: ($mean<$thresh)?1:0]" info:`

#example statement[ $test -eq 1 ] && echo "mean=$mean; too dark" || echo "mean=$mean; not too dark"
[ $test -eq 1 ] && rm $DIRECTORY/$image || :

관련 정보