Code Monkey home page Code Monkey logo

Comments (5)

wjs018 avatar wjs018 commented on June 2, 2024

There is the -m, --min-scene-len option you can give to scenedetect (documentation here). This takes a timecode as an argument and will ignore any detected scene transitions that happen less that that amount of time or number of frames since the previous transition.

For example

scenedetect -i video.mp4 -m 5s detect-content

would ignore any detected scene transitions that happen less than 5 seconds from the previous detected scene transition. So, it would just be part of the scene before it.

from pyscenedetect.

yumianhuli1 avatar yumianhuli1 commented on June 2, 2024

There is the -m, --min-scene-len option you can give to scenedetect (documentation here). This takes a timecode as an argument and will ignore any detected scene transitions that happen less that that amount of time or number of frames since the previous transition.

For example

scenedetect -i video.mp4 -m 5s detect-content

would ignore any detected scene transitions that happen less than 5 seconds from the previous detected scene transition. So, it would just be part of the scene before it.

Ok, thank you very much. Could you plz tell me the python call api equivalent to this CLI?

from pyscenedetect.

wjs018 avatar wjs018 commented on June 2, 2024

Using the python api, you would set min_scene_len per detector when you create it (default is 15 frames, see here for definition in the __init__ function of the ContentDetector). So, you would construct your detector while defining min_scene_len like ContentDetector(min_scene_len=30) to set it to 30 frames instead of the default 15. You can see a basic python api example here. In this example, you would define it in the constructor for ContentDetector when you are calling the add_detector function.

One difference between the cli and python api is, I believe, the python api expects min_scene_len to be an int corresponding to a minimum number of frames. By contrast, using the cli, you can either specify the number of frames or a timecode. If you need to programatically find the framerate of your video, you should be able to access that through a property of the VideoStream object. So, let's say you open video.mp4 using

from scenedetect import open_video

video = open_video("video_file.mp4")  # This returns a VideoStream object

you can then access the framerate of the video through video.frame_rate.

@Breakthrough I am just realizing from this conversation how the cli and python api treat min_scene_len differently. Is my understanding of this correct? And, if so, should min_scene_len be made more flexible for the python api in a future version or set at the SceneManager level rather than per detector?

from pyscenedetect.

Breakthrough avatar Breakthrough commented on June 2, 2024

Your understanding is correct! The current API could be updated to use a FrameTimecode for detectors.

The idea I have for the long-term 1.0 API would be something where detectors simply generate a set of events (e.g. Event.CUT, Event.START for fade in, Event.END for fade out), and feed those to a SceneManager. Then, SceneManager could be responsible for actually respecting min_scene_len by dropping CUT events that are too close together when you call get_scene_list(). One benefit of doing this as a post-processing step is the ability to call multiple times with different lengths without needing to run detection again. This would break how callbacks currently work, but perhaps that is okay as doing this kind of filtering online in a callback is relatively easy (e.g. ignore Event.CUTs that are just too close to the last one).

That being said your suggestion is a good idea and might bring us one step closer to that vision. It's certainly possible to deprecate min_scene_len on detectors, and add a new argument for that purpose to SceneManager.get_scene_list(). One downside of this approach though is it will not work correctly with the callback function that detect_scenes() takes, so this may need to be an intrinsic property of a given detection run (e.g. passed to detect_scenes() or made a property of SceneManager) and handled as an online filter.

from pyscenedetect.

yumianhuli1 avatar yumianhuli1 commented on June 2, 2024

thanks!close

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.