diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..a2bb98a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM frolvlad/alpine-glibc:alpine-3.9_glibc-2.29 + +RUN apk update \ + && apk add --no-cache \ + ca-certificates \ + ffmpeg \ + bash + +RUN mkdir -p /var/log +WORKDIR /main + +COPY . . + +ENV GOPATH="" +ENV MNT="/mnt/" +ENTRYPOINT ["bash", "/main/entrypoint.sh"] +CMD [] + diff --git a/ffmpeg/run.sh b/ffmpeg/run.sh deleted file mode 100644 index c3cdecc..0000000 --- a/ffmpeg/run.sh +++ /dev/null @@ -1,41 +0,0 @@ -#! /bin/bash - -echo to start: ${@:-83} - -for i in "${@:-83}"; do - echo starting $i... - ffmpeg \ - -threads 0 \ - -nostdin \ - -nostats \ - -loglevel error \ - -i rtsp://192.168.0.$i:8554/unicast \ - -an \ - -map 0 \ - -force_key_frames "expr:gte(t,n_forced*9)" \ - -f segment \ - -segment_time ${SEG:-10} \ - -segment_format mp4 \ - -strftime 1 \ - -minrate .05k \ - -vcodec copy \ - "/tmp/ffmpeg_cap/ffmpeg_capture-$i-%Y%m%d_%H%M%S.mp4" \ - -vf "select=gt(scene\,0.003),setpts=N/(15*TB)" \ - 2>&1 \ - < /dev/null \ - | grep -vE 'RTP: missed|max delay reached. need to consume packet|decode_slice_header|no.frame|non.existing.PPS|Last.message.repeated' \ - >> ./ffmpegs.log & -done - -clean() { - kill -9 $(jobs -p) -} -trap clean EXIT ERR - -for i in "${@:-83}"; do - if ! wait -n 1; then - echo "Something died" >&2 - exit 1 - fi - exit 0 -done diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..48d4b66 --- /dev/null +++ b/run.sh @@ -0,0 +1,60 @@ +#! /bin/bash + +function main() { + if [ "$#" -eq 0 ]; then + echo "USAGE: $0 ip ip ip..." >&2 + return 1 + fi + + function clean() { + kill -9 $(jobs -p) + } + trap clean EXIT ERR + for ip in "$@"; do + echo recording from $ip... + record "$ip" & + done + + for i in "$@"; do + if ! wait -n 1; then + echo "Something died: $?" >&2 + return 1 + fi + return 0 + done +} + +function record() { + while true; do + _record "$@" + sleep 10 + done +} + +function _record() { + ffmpeg \ + -threads 0 \ + -nostdin \ + -nostats \ + -loglevel error \ + -i rtsp://192.168.0.$1:8554/unicast \ + -an \ + -map 0 \ + -force_key_frames "expr:gte(t,n_forced*9)" \ + -f segment \ + -segment_time ${SEG:-300} \ + -segment_format mp4 \ + -strftime 1 \ + -minrate .05k \ + -vcodec copy \ + "${OUT_DIR:-/tmp/ffmpeg_cap}/cap-$1-%Y%m%d_%H%M%S.mp4" \ + -vf "select=gt(scene\,0.003),setpts=N/(15*TB)" \ + < /dev/null \ + >> /tmp/ffmpegs.log \ + 2>&1 +} + +if [ "$0" == "$BASH_SOURCE" ]; then + main "$@" +fi + diff --git a/ffmpeg/ffmpegs.log b/testdata/ffmpeg/ffmpegs.log similarity index 100% rename from ffmpeg/ffmpegs.log rename to testdata/ffmpeg/ffmpegs.log diff --git a/ffmpeg/log b/testdata/ffmpeg/log similarity index 100% rename from ffmpeg/log rename to testdata/ffmpeg/log diff --git a/testdata/ffmpeg/run.sh b/testdata/ffmpeg/run.sh new file mode 100644 index 0000000..13b0489 --- /dev/null +++ b/testdata/ffmpeg/run.sh @@ -0,0 +1,45 @@ +#! /bin/bash + +echo to start: ${@:-83} + +for i in "${@:-83}"; do + echo starting $i... + ( + while true; do + ffmpeg \ + -threads 0 \ + -nostdin \ + -nostats \ + -loglevel error \ + -i rtsp://192.168.0.$i:8554/unicast \ + -an \ + -map 0 \ + -force_key_frames "expr:gte(t,n_forced*9)" \ + -f segment \ + -segment_time ${SEG:-10} \ + -segment_format mp4 \ + -strftime 1 \ + -minrate .05k \ + -vcodec copy \ + "/tmp/ffmpeg_cap/ffmpeg_capture-$i-%Y%m%d_%H%M%S.mp4" \ + -vf "select=gt(scene\,0.003),setpts=N/(15*TB)" \ + < /dev/null \ + >> ./ffmpegs.log \ + 2>&1 + sleep 30 + done + ) & +done + +clean() { + kill -9 $(jobs -p) +} +trap clean EXIT ERR + +for i in "${@:-83}"; do + if ! wait -n 1; then + echo "Something died" >&2 + exit 1 + fi + exit 0 +done diff --git a/motion/cameras/wyze0.conf b/testdata/motion/cameras/wyze0.conf similarity index 100% rename from motion/cameras/wyze0.conf rename to testdata/motion/cameras/wyze0.conf diff --git a/motion/cameras/wyze1.conf b/testdata/motion/cameras/wyze1.conf similarity index 100% rename from motion/cameras/wyze1.conf rename to testdata/motion/cameras/wyze1.conf diff --git a/motion/cameras/wyze2.conf b/testdata/motion/cameras/wyze2.conf similarity index 100% rename from motion/cameras/wyze2.conf rename to testdata/motion/cameras/wyze2.conf diff --git a/motion/cameras/wyze3.conf b/testdata/motion/cameras/wyze3.conf similarity index 100% rename from motion/cameras/wyze3.conf rename to testdata/motion/cameras/wyze3.conf diff --git a/motion/motion.conf b/testdata/motion/motion.conf similarity index 100% rename from motion/motion.conf rename to testdata/motion/motion.conf diff --git a/motion/run.sh b/testdata/motion/run.sh similarity index 100% rename from motion/run.sh rename to testdata/motion/run.sh diff --git a/openrtsp/install.sh b/testdata/openrtsp/install.sh similarity index 100% rename from openrtsp/install.sh rename to testdata/openrtsp/install.sh diff --git a/openrtsp/run.sh b/testdata/openrtsp/run.sh similarity index 100% rename from openrtsp/run.sh rename to testdata/openrtsp/run.sh