DVR-Scan icon indicating copy to clipboard operation
DVR-Scan copied to clipboard

Windows CUDA build not working

Open sundeepgoel72 opened this issue 1 year ago • 1 comments

Bug/Issue Description: The CUDA windows build not working, throwing errors. What am i doing wrong ?

Required Information: c:\sg-bin\dvr-scan-cuda\dvr-scan.exe -i D:\surveillance\Ch6\2021-09-09\SGNVR_ch6_main_20210909133828_20210909134647.mp4 -b mog2_cuda

Computing Environment: window 10

  • OpenCV installed in python, not in as separate install. DVR scan seems to be looking to opencv in C:\OpenCV\opencv-4.5.5, i tried moving opencv files there manually but the directory structure seems incorrect.

Error Dump: [DVR-Scan] DVR-Scan v1.5 [DVR-Scan] Initializing scan context... [ WARN:[email protected]] global C:\OpenCV\opencv-4.5.5\modules\videoio\src\cap_msmf.cpp (923) CvCapture_MSMF::initStream Failed to set mediaType (stream 1, (1920x1080 @ 25) MFVideoFormat_RGB32(codec not found) [DVR-Scan] Opened video SGNVR_ch6_main_20210909133828_20210909134647.mp4 (1920 x 1080 at 25.000 FPS). [DVR-Scan] Scanning input video for motion events... Detected: 0 | Progress: 0 frames [00:01, ? frames/s] [DVR-Scan] Failed to decode 6 frame(s) from video, timestamps may be incorrect. Try re-encoding or remuxing video (e.g. ffmpeg -i video.mp4 -c:v copy out.mp4). See https://github.com/Breakthrough/DVR-Scan/issues/62 for details. [DVR-Scan] Processed 0 frames read in 1.6 secs (avg 0.0 FPS). [DVR-Scan] No motion events detected in input.

sundeepgoel72 avatar Aug 15 '22 09:08 sundeepgoel72

You're running dvr-scan.exe which will not use OpenCV from your Python installation. That path comes from the version of OpenCV I built for distribution with the CUDA-enabled version of DVR-Scan. If you want to use the OpenCV version from your Python environment, all you need to do is install DVR-Scan via pip and use that instead of the portable .exe builds. Please try that and let me know if that resolves the issue.

Regarding the "Failed to decode X frames" error message could also be improved here, so I'll add some checks to make sure codec detection works correctly (and displays an explicit warning if not). The downside of providing CUDA builds is I need to build OpenCV myself currently, and it's difficult to foresee all the codec support that might be required. I'm also unsure how that might complicate the licensing of the built binaries, so the portable CUDA .exe's might not have support for all (esoteric) video formats. They can be rencoded using ffmpeg pretty easily though.

Breakthrough avatar Aug 15 '22 23:08 Breakthrough

You're running dvr-scan.exe which will not use OpenCV from your Python installation. That path comes from the version of OpenCV I built for distribution with the CUDA-enabled version of DVR-Scan.

Hi, am using the zip from : https://github.com/Breakthrough/DVR-Scan/releases/download/v1.5.1-release/dvr-scan-1.5.1-win64-cuda.zip. I was assuming the correct opencv version with CUDA support was bundled in the zip.

How do i resolve without going the python route?

sundeepgoel72 avatar Aug 17 '22 17:08 sundeepgoel72

I thought from your comment you wanted to use the Python version of OpenCV. If you want to use the CUDA version I built for the .exe, then you are correct that everything you need is in that .zip.

The issue you're facing is this:

> [ WARN:[email protected]] global C:\OpenCV\opencv-4.5.5\modules\videoio\src\cap_msmf.cpp (923) CvCapture_MSMF::initStream Failed to set mediaType (stream 1, (1920x1080 @ 25) MFVideoFormat_RGB32(codec not found)

There's a codec missing from the version of ffmpeg that's used, or you're missing the video codec on Windows (MSMF = MS Media Foundation). The program is working, it just cannot decode the video due to missing codec. That path ("C:\OpenCV\opencv-4.5.5") is the path I compiled OpenCV at on my system. You do not need to put any files there, it is just stating where the error comes from.

If you can provide a sample video, I can try to make sure it works on a future version, but I can't guarantee this. Ultimately, the easiest workaround is to re-encode the input videos with ffmpeg, or see if your cameras can use a more common recording format if that fails.

Can you confirm that you can scan the same video using the non-CUDA version of DVR-Scan? Can you play these video files using the Windows Media Player? And if so, can you share a sample of the video so I can reproduce the issue?

Breakthrough avatar Aug 17 '22 23:08 Breakthrough

Can you confirm that you can scan the same video using the non-CUDA version of DVR-Scan? Can you play these video files using the Windows Media Player? And if so, can you share a sample of the video so I can reproduce the issue?

The non-cuda version of DVR-scan is working fine on the same files. Key issue in this version seems to be "MFVideoFormat_RGB32(codec not found)".

I'll be happy to share a few sample files. Please let me know how to send them over ?

ffprobe output is as follows:- Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'H:\Surveilance\Ch6\2021-02-27\ch6-20210227000718_20210227000757.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 creation_time : 2021-03-12T13:56:04.000000Z Duration: 00:00:42.94, start: 0.000000, bitrate: 1082 kb/s Stream #0:00x1: Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt470bg/bt470bg/smpte170m), 1920x1080, 1048 kb/s, 25 fps, 25 tbr, 1k tbn (default) Metadata: creation_time : 2021-03-12T13:56:04.000000Z handler_name : VideoHandler vendor_id : [0][0][0][0] Stream #0:10x2: Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 31 kb/s (default) Metadata: creation_time : 2021-03-12T13:56:04.000000Z handler_name : SoundHandler vendor_id : [0][0][0][0]

Re-encoding is not really an option, since am dealing with 2 years worth of surveillance videos , which is why I wanted to use the CUDA version to speed up motion discovery and extract.

sundeepgoel72 avatar Aug 18 '22 03:08 sundeepgoel72

Similar (but slightly different issue with another file) c:\sg-bin\dvr-scan-cuda\dvr-scan.exe -i H:\Surveilance\Ch6\BeforeMotionExtract\2022-08-16\SGNVR_ch6_main_20220816001405_20220816001444.dav -b mog2_cuda

[DVR-Scan] DVR-Scan v1.5 [DVR-Scan] Initializing scan context... [DVR-Scan] Error: Couldn't load video SGNVR_ch6_main_20220816001405_20220816001444.dav. [DVR-Scan] Check that the given file is a valid video clip, and ensure all required dependencies are installed and configured properly. [DVR-Scan] Failed to load input: isOpened() returned False for SGNVR_ch6_main_20220816001405_20220816001444.dav!

ffprobe output Input #0, dhav, from 'H:\Surveilance\Ch6\BeforeMotionExtract\2022-08-16\SGNVR_ch6_main_20220816001405_20220816001444.dav': Duration: 00:00:43.00, start: 1660608841.000000, bitrate: 1111 kb/s Stream #0:0: Video: hevc (Main), yuvj420p(pc, bt470bg/bt470bg/smpte170m), 1920x1080, 25 fps, 25 tbr, 1k tbn Stream #0:1: Audio: aac (LC), 16000 Hz, mono, fltp

Non-cuda DVR-scan working fine on this file as well.

sundeepgoel72 avatar Aug 18 '22 03:08 sundeepgoel72

How large are the samples? Can you use ffmpeg to trim them down to just a few seconds and upload them here? If you use codec copying mode that should be sufficient, e.g.:

ffmpeg -i video.mp4 -t 30.0 -map 0 -c:v copy -c:a copy -sn out.mp4

I'll need to add them to the repo so they can be used for unit tests.

Are you able to play the files with Windows Media Player?

In the meantime, you can also try using -b CNT with DVR-Scan to speed up processing speed (on my system, I get around 100 FPS with -b CNT and 120 with -b MOG2_CUDA). Any feedback you have on the parameters you're using with CNT, if you go that route, would be useful too, thanks.

Breakthrough avatar Aug 19 '22 01:08 Breakthrough

I'll need to add them to the repo so they can be used for unit tests.

Are you able to play the files with Windows Media Player?

In the meantime, you can also try using -b CNT with DVR-Scan to speed up processing speed (on my system, I get around 100 FPS with -b CNT and 120 with -b MOG2_CUDA). Any feedback you have on the parameters you're using with CNT, if you go that route, would be useful too, thanks.

Hi, have uploaded two 500Kb sample file, hope they help

  1. https://user-images.githubusercontent.com/16491150/185632319-31664a23-0a3b-4bc6-bbb8-527a1bef9bed.mp4
  2. sample2.zip

#1 does not play video on Windows Media Player, only audio. Works fine on VLC #2 is a rar file, renamed to zip. It contains a dav file - not playable on either Window media player or VLC. But on an app called Smart Player from CPPLUS as part of their NVR series for surveillance recorders.

both these file process fine on the non cuda version on DVR-Scan

The config file is use is :-

  • output-mode = ffmpeg
  • ffmpeg-input-args = -v error -hwaccel dxva2
  • ffmpeg-output-args = -map 0 -c:v libx265 -preset fast -crf 28 -c:a aac -sn
  • min-event-length = 2
  • time-before-event = 0.25s
  • time-post-event = 0.5s
  • bg-subtractor = MOG2
  • threshold = 4
  • frame-skip = 5

Using above am getting fps for around 250-300 on a

  • i5-4570 3.2Ghx 4 core CPU
  • NVIDIA GTX 750 Ti (this seems to be getting used in ffmeg output extraction and encoding to x265)

sundeepgoel72 avatar Aug 19 '22 13:08 sundeepgoel72

@sundeepgoel72 thank you for providing the samples and requested information. I think I narrowed down the issue, there may be some missing DLL files in the CUDA release.

You can download these files here and put them in the same place as dvr-scan.exe: missing_dll_files_dvr_scan_issue_94.zip

Can you let me know if this fixes the issue?

Edit: I've also re-uploaded the v1.5/v1.5.1 CUDA .zip files to include these DLLs.

Breakthrough avatar Aug 20 '22 01:08 Breakthrough

Can you let me know if this fixes the issue?

@Breakthrough , thanks. its moved beyond that initial error, but now throwing following

c:\sg-bin\dvr-scan-cuda\dvr-scan.exe -i Sample1.mp4 -b mog2_cuda

[DVR-Scan] DVR-Scan v1.5 [DVR-Scan] Initializing scan context... [DVR-Scan] Opened video Sample1.mp4 (1920 x 1080 at 25.000 FPS). [DVR-Scan] Scanning input video for motion events... Detected: 0 | Progress: 0%| | 0/103 [00:00<?, ? frames/s]Traceback (most recent call last): File "dvr_scan_main_.py", line 28, in File "dvr_scan_main_.py", line 24, in main File "dvr_scan\cli\controller.py", line 285, in run_dvr_scan File "dvr_scan\scanner.py", line 623, in scan_motion File "dvr_scan\motion_detector.py", line 121, in apply cv2.error: OpenCV(4.5.5) C:\OpenCV\opencv_contrib-4.5.5\modules\cudev\include\opencv2\cudev\grid\detail/transform.hpp:264: error: (-217:Gpu API call) no kernel image is available for execution on the device in function 'cv::cudev::grid_transform_detail::TransformDispatcher<false, Policy>::call'

[5520] Failed to execute script 'main' due to unhandled exception! Detected: 0 | Progress: 0%|

H:\Surveilance\samplestoDVRscan>c:\sg-bin\dvr-scan-cuda\dvr-scan.exe -i sample2.dav 0b mog2_cuda [DVR-Scan] DVR-Scan v1.5 [DVR-Scan] Error: Input file does not exist: 0b

H:\Surveilance\samplestoDVRscan>c:\sg-bin\dvr-scan-cuda\dvr-scan.exe -i sample2.dav -b mog2_cuda [DVR-Scan] DVR-Scan v1.5 [DVR-Scan] Initializing scan context... [DVR-Scan] Opened video sample2.dav (1920 x 1080 at 25.000 FPS). [DVR-Scan] Scanning input video for motion events... Detected: 0 | Progress: 0 frames [00:00, ? frames/s]Traceback (most recent call last): File "dvr_scan_main_.py", line 28, in File "dvr_scan_main_.py", line 24, in main File "dvr_scan\cli\controller.py", line 285, in run_dvr_scan File "dvr_scan\scanner.py", line 623, in scan_motion File "dvr_scan\motion_detector.py", line 121, in apply cv2.error: OpenCV(4.5.5) C:\OpenCV\opencv_contrib-4.5.5\modules\cudev\include\opencv2\cudev\grid\detail/transform.hpp:264: error: (-217:Gpu API call) no kernel image is available for execution on the device in function 'cv::cudev::grid_transform_detail::TransformDispatcher<false, Policy>::call'

[7504] Failed to execute script 'main' due to unhandled exception! Detected: 0 | Progress: 0 frames [00:00, ? frames/s]

sundeepgoel72 avatar Aug 20 '22 03:08 sundeepgoel72

Hey @sundeepgoel72;

Sorry I just re-read your hardware specs and see you have a 750 Ti. When building the CUDA version of OpenCV, I did not include deprecated architectures, so the .exe only has support for GTX 900-series and above.

You may submit a feature request ("Support deprecated PTX architectures in CUDA builds") and I can consider providing a CUDA build for older GPUs when the next version of DVR-Scan is released. It may be possible to include a different .dll for these older GPUs which can be downloaded separately. In the meantime, if another member of the community is willing to help out and can build + share a version of OpenCV+CUDA for these older GPU models, that would be greatly appreciated.

If you are so inclined, you may also compile OpenCV + CUDA with support for your GPU model and use the Python version instead of the portable .ZIP. I found this guide by James Bowley to be useful when I was building OpenCV on my system.

Sorry for not making the supported GPU models clear on the download page, I will add some text to make that clear. Thank you for your help with resolving the video loading issue, and my sincere apologies that the CUDA version does not support older GPUs currently.


Closing issue as original bug has been resolved. You are more than welcome to create a new issue for following up with support of older Nvidia 700 and 800-series GPUs. Thank you for the report.

Breakthrough avatar Aug 20 '22 04:08 Breakthrough

if another member of the community is willing to help out and can build + share a version of OpenCV+CUDA for these older GPU models, that would be greatly appreciated.

I'll be happy to give this a shot, can you point me in the right direction to get started

sundeepgoel72 avatar Aug 20 '22 04:08 sundeepgoel72

In the meantime, you can also try using -b CNT with DVR-Scan to speed up processing speed (on my system, I get around 100 FPS with -b CNT and 120 with -b MOG2_CUDA). Any feedback you have on the parameters you're using with CNT, if you go that route, would be useful too, thanks.

I tried using CNT, there is a 10% uplift over MOG2 but a lot of false positives. Is there some material I can read on how to eliminate false positives using CNT or MOG (mainly things like light variation, or small item movement like rustling of tree leaves).

Another Q : have you considered an implementation of YOLO for person / motion detection. If yes, how does that compare performance / accuracy wise against CNT or MOG?

sundeepgoel72 avatar Aug 20 '22 11:08 sundeepgoel72

I tried using CNT, there is a 10% uplift over MOG2 but a lot of false positives. Is there some material I can read on how to eliminate false positives using CNT or MOG (mainly things like light variation, or small item movement like rustling of tree leaves).

This just came up in #100 - see my response there. I want to create a guide on how to tune motion detection parameters. In your case, if there is small movements you want to filter out, you should increase -k/--kernel-size (e.g. raise it to 9, 15, or even 21 if you have HD videos), and also limit the detection area with -roi if possible.

You may also find the -mo parameter useful here, as it generates a video showing what DVR-Scan "sees" internally (allowing you to see what effect changing parameters has). Addressing light variation is a more difficult challenge which is still an open issue, see #53 for details. I'll be adding the option to enable shadow detection in DVR-Scan v1.6, so hopefully that helps somewhat with this case.

If you can share any videos that show brightness changes which result in a false detection, if you could post those in #53, that would be very helpful for me to use when trying to improve how DVR-Scan handles these cases.

Another Q : have you considered an implementation of YOLO for person / motion detection. If yes, how does that compare performance / accuracy wise against CNT or MOG?

This has also come up before, but I'm not convinced feature/object detection is the right solution for DVR-Scan. It might help identify things once a motion event is detected, but it might not work correctly when objects are obscured or only partially visible in the frame. There are also cases where one might want to detect motion events which don't appear to even be objects.

Another point of consideration is that these methods are typically much slower than background subtraction (they're much more expensive computationally speaking).

Breakthrough avatar Aug 21 '22 23:08 Breakthrough