Breakthrough / DVR-Scan

:vhs: Tool for extracting scenes with motion from videos (e.g. security camera or DVR footage). Written in Python, uses OpenCV.
http://www.dvr-scan.com/
Other
362 stars 47 forks source link

AttributeError: 'VideoJoiner' object has no attribute '_get_next_frame' - on globbing files in directory #95

Closed millerthegorilla closed 1 year ago

millerthegorilla commented 1 year ago

Hi, I am getting the following error : AttributeError: 'VideoJoiner' object has no attribute '_get_next_frame'

the error is:

[DVR-Scan] Warning: framerate does not match first input. Timecodes may be incorrect.
[DVR-Scan] Scanning 6932 input videos for motion events...
[DVR-Scan] Fatal error: Exception raised in decode thread.                      
Detected: 0 | Progress: 1194 frames [02:37,  7.57 frames/s]
Traceback (most recent call last):
  File "/var/home/super/Documents/venv/bin/dvr-scan", line 8, in <module>
    sys.exit(main())
  File "/var/home/super/Documents/venv/lib64/python3.10/site-packages/dvr_scan/__main__.py", line 24, in main
    sys.exit(run_dvr_scan())
  File "/var/home/super/Documents/venv/lib64/python3.10/site-packages/dvr_scan/cli/controller.py", line 285, in run_dvr_scan
    sctx.scan_motion(detector_type=bg_subtractor)
  File "/var/home/super/Documents/venv/lib64/python3.10/site-packages/dvr_scan/scanner.py", line 731, in scan_motion
    raise self._decode_thread_exception[1].with_traceback(
  File "/var/home/super/Documents/venv/lib64/python3.10/site-packages/dvr_scan/scanner.py", line 815, in _decode_thread
    frame_rgb = self._input.read()
  File "/var/home/super/Documents/venv/lib64/python3.10/site-packages/dvr_scan/video_joiner.py", line 107, in read
    return self._get_next_frame()
AttributeError: 'VideoJoiner' object has no attribute '_get_next_frame'

I am using Fedora 36 silverblue and ffmpeg -version:

ffmpeg version 5.0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 12 (GCC)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 ' --extra-cflags=' -I/usr/include/rav1e' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --enable-chromaprint --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libbs2b --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libilbc --enable-libmp3lame --enable-libmysofa --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librav1e --enable-librtmp --enable-librubberband --enable-libsmbclient --enable-version3 --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-vulkan --enable-libglslang --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-avfilter --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-lto --enable-libmfx --enable-runtime-cpudetect
libavutil      57. 17.100 / 57. 17.100
libavcodec     59. 18.100 / 59. 18.100
libavformat    59. 16.100 / 59. 16.100
libavdevice    59.  4.100 / 59.  4.100
libavfilter     8. 24.100 /  8. 24.100
libswscale      6.  4.100 /  6.  4.100
libswresample   4.  3.100 /  4.  3.100
libpostproc    56.  3.100 / 56.  3.100

I am selecting multiple files using globbing. I note that some of the files are reported as 19 FPS and others are 10 FPS, so perhaps this might be the issue? If FPS incompatibility is an issue is there any chance that an option might be introduced so that when selecting multiple files through globbing or otherwise, only files of a given FPS are processed. This would allow me to run two scans, one on the 19FPS and one on the 10FPS.

MTia...

millerthegorilla commented 1 year ago

I forgot to mention that I am using a glob of ...dir/*/.mp4

millerthegorilla commented 1 year ago

I have just tried with a smaller amount of files, that are all the same FPS and I still get the same issue.

millerthegorilla commented 1 year ago

I am using a bash for loop to find files that are at 10fps using ffprobe, and then running dvr-scan on them.

FPS=10
for file in $(find . -type f -name "*mp4"); do   if [[ $(ffprobe $file 2>&1| grep ",* fps" | cut -d "," -f 5 | cut -d " " -f 2) == $FPS ]]; then     dvr-scan -bb --threshold 1.5 -i $file -d ../output/ ; fi; done

I have guestimated the motion detection threshold at 1.5, in order to only capture people in the frame, rather than just shadows moving. I don't know if this is too high a value, but it is just above what stops shadows from being detected.

Breakthrough commented 1 year ago

Hey @millerthegorilla;

Sorry about that, indeed this is a bug and will happen anytime you are using multiple input videos. Indeed it seems like multiple file inputs are broken in the v1.5 release, my apologies. I'll try to get a fix out for this ASAP, and mark this as a known issue on the releases page / changelog.

Regarding shadows, currently shadow detection is disabled, but I'm working on adding an option to enable it for v1.6. Thanks for sharing the parameters that work best for your use case. Could you also share the resolution of videos you're processing?

Thanks!

P.S. Sorry again about this bug - it seems that I forgot to add a test case to verify multiple videos work correctly, so I'll also make sure to add a test case for that to ensure this doesn't crop up again. Thanks for the report.

TODOs to close this out:

Breakthrough commented 1 year ago

Fixed and re-released v1.5.1. This should now work as intended. Thanks for the report!

P.S. Please do let me know if you run into any more issues!

millerthegorilla commented 1 year ago

Many thanks for your help. I don't have the machine to hand at the moment, but videos are 1080p at 25fps. I don't know what you mean by shadow detection, but any lower than 1.5 and a shadow on the wall was being recorded as moving. I am guessing that you mean to add an option to detect a difference between people and shadows. In any case, thanks a lot for your effort, great app!

Breakthrough commented 1 year ago

I am guessing that you mean to add an option to detect a difference between people and shadows

@millerthegorilla correct, some background subtraction methods have shadow detection which should help reduce false positives in cases like this. That will probably be part of DVR-Scan v1.6, so stay tuned 👍

millerthegorilla commented 1 year ago

Cool. But it would definitely be of use if one could specify a target framerate for input files, so that only input files of that framerate would be appended when globbing....