Giter Site home page Giter Site logo

[Bug] memory leak about pyscenedetect HOT 9 CLOSED

HuaZheLei avatar HuaZheLei commented on June 15, 2024
[Bug] memory leak

from pyscenedetect.

Comments (9)

Breakthrough avatar Breakthrough commented on June 15, 2024

How many videos are you processing roughly? Does it occur if all of the paths in video_lists are the same video? What OS/environment are you running this under, and how are you running the script?

Thank you.

Edit: I was able to verify on Windows x64 at least on my system there is no memory leak with the code pattern you outlined above, this may be something due to the environment.

from pyscenedetect.

HuaZheLei avatar HuaZheLei commented on June 15, 2024

How many videos are you processing roughly? Does it occur if all of the paths in video_lists are the same video? What OS/environment are you running this under, and how are you running the script?

Thank you

Thanks for your reply.

  1. I use the script to process 30k videos.
  2. If all of the paths in video_lists are the same video, it still occurs.
  3. I find this situation on Ubuntu and MacOS.
  4. I just use 'python3 xxx.py' in a single thread.

from pyscenedetect.

Breakthrough avatar Breakthrough commented on June 15, 2024

Could you install and try another backend like 'pyav' or 'moviepy'? e.g. run pip install av and open video with video = open_video(video_path, 'pyav')

PySceneDetect is a pure Python library and offloads all video processing to either OpenCV, PyAV, or MoviePy. The next steps would be to narrow down if the memory leak, so trying a different backend will help greatly with that. In the meantime I will setup a VM to test this with locally on Ubuntu.

Can you create and upload a small script that causes the issue? A video clip as well would be helpful to ensure we are testing the same things and I want to see if we can use the exact same script/video. Thanks.

from pyscenedetect.

Breakthrough avatar Breakthrough commented on June 15, 2024

Using the same package versions as you outlined above, on Ubuntu 22.04, I'm running all 3 different backends in a loop the same way you described above. From what I can see memory usage for PySceneDetect+OpenCV and PySceneDetect+MoviePy are steady. As for PyAV, the memory does seem to climb at first, but it is eventually reclaimed and drops again. I don't think PySceneDetect and most of the backends in use have any memory leaks, but am happy to look further into this if you can provide a reproduction.

from pyscenedetect.

wjs018 avatar wjs018 commented on June 15, 2024

I have previously had this issue with moviepy, but that was a couple years ago and I haven't run things in a loop like this since then. I fixed it by writing things out to file occasionally and invoking the del function on a bunch of variables every X number of iterations.

from pyscenedetect.

HuaZheLei avatar HuaZheLei commented on June 15, 2024

Using the same package versions as you outlined above, on Ubuntu 22.04, I'm running all 3 different backends in a loop the same way you described above. From what I can see memory usage for PySceneDetect+OpenCV and PySceneDetect+MoviePy are steady. As for PyAV, the memory does seem to climb at first, but it is eventually reclaimed and drops again. I don't think PySceneDetect and most of the backends in use have any memory leaks, but am happy to look further into this if you can provide a reproduction.

Hi, I find that the code uses cv2.VideoCapture to open a video, but without to release it. When I run a for loop, it may cause the memory raising?

from pyscenedetect.

Breakthrough avatar Breakthrough commented on June 15, 2024

Hi, I find that the code uses cv2.VideoCapture to open a video, but without to release it. When I run a for loop, it may cause the memory raising?

The destructor of a VideoCapture object will call release() which applies to Python as well. That will happen automatically at the end of each loop iteration. Are you able to reproduce this with a different versions of OpenCV?

I recently came across https://github.com/bloomberg/memray which might be useful to find the cause. A memory flame graph would be really helpful to identify what part of code is using the memory.

from pyscenedetect.

babyta avatar babyta commented on June 15, 2024

Hello, I recently wrote a synchronous stripping service, and I also have this problem. The free memory keeps decreasing.

from pyscenedetect.

babyta avatar babyta commented on June 15, 2024

‘ scene_manager.detect_scenes ’ Immediately following the previous answer, the execution of splitting will become slower and slower.

from pyscenedetect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.