![스크립트를 사용하여 검은색/어두운 타임랩스 사진 삭제](https://linux55.com/image/183896/%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EA%B2%80%EC%9D%80%EC%83%89%2F%EC%96%B4%EB%91%90%EC%9A%B4%20%ED%83%80%EC%9E%84%EB%9E%A9%EC%8A%A4%20%EC%82%AC%EC%A7%84%20%EC%82%AD%EC%A0%9C.png)
저는 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 || :