Open zoinkydoink opened 1 year ago
Hey, thanks for the issue.
In regards to the application hanging, from what I understand, when we get to this point:
using (var collection = new MagickImageCollection(video, MagickFormat.Mp4))
{
collection.Coalesce();
the Magick library converts the video into individual frames which get saved to a temp folder which only runs against the CPU, as last I checked they didn't have GPU support. This is not a quick process. For a 10 minute video at 24 frames per second, that would be over 14000 frames. I did a quick test on my laptop and a 180 frame video took about a minute to process. For 14000, that could take an hour. From other tests I've done, NsfwSpy's classification is pretty fast, with 10,000 images not taking more than a few minutes, so I'm pretty sure the video frame extraction is the bulk of the processing.
I'm sure this process could be faster, but I don't really have the time to look into other methods of extracting the frames at the moment. Because the extraction process is the time consuming part, the UpdateVideoProgress you added won't really provide an accurate idea of how quickly the frames are being processed as the extraction process takes so long before it.
Regarding the depedency updates, if I find the time, I can try working that in to an update 😊
This thread talks about some of the memory usage requirements for extracting the frames from a 521 frame GIF - https://stackoverflow.com/questions/69059486/imagemagick-convert-ultra-slow
If you can find a better way to extract the frames from a longer video, I'd be keen to hear and then we could work that into NsfwSpy 👍
I poked around a bit and it seems that direct ffmpeg extraction is probably the fastest/best way and it uses GPU
I ran the following command ffmpeg -c:v h264_cuvid -i "D:\movies for checking\The.Godfather.1972.1080p.BrRip.x264.BOKUTOX.YIFY.mp4" -vf fps=2 "c:\temp\gf1\output-%04d.png"
which took few minutes to extrct 21k frames (2 f rames per second) of a almost 3 hour movie. Given the nature of the detection this library is doing, I dont think more than 2 frame per second is needed, even 1 is enough.
This thread talks about ffmpeg and breaking into images, i found the second command (one above) to be faster https://stackoverflow.com/questions/64485121/extracting-frames-with-nvidia-gpu
I would think the next step in this library is to remove MagickImage completely and rely on ffmpeg (since it seems to be using it anyways since its a required install according to your docs).
Next Steps
Created a dumb console app (.NET 6) with the following static void Main(string[] args) {
It seems that the code execution never comes out of
using (var collection = new MagickImageCollection(video, MagickFormat.Mp4))
No exceptions or anything, i even left it running overnight thinking it might be taking long (the Edit.mp4 is first 10 minute clip of God Father Part 2), I cut it only to 10 min thinking it might be the size/time of all the movie being at (3h:22m run time and 1.4GB). Here is what my console looks like as the program is running.I have a 3070 running, with all the libraries installed properly (I think)
I think u should be upgrading to .NET 6 at least (preferably 8 as 2.0 is deprecated), also note the time in bold in the above, it took a while for it to get to
var collection = new MagickImageCollection(video, MagickFormat.Mp4)
Seems like the SciSharp, Magick, and Microsoft.ML can also be upgraded to later versions
I also wanted to do a PR where I add a progress event to the video processing so one can know how its going, below is the code if u wanna incorporate.
Also how long does it take to process a 10 min vid in general.