Breakthrough / PySceneDetect

:movie_camera: Python and OpenCV-based scene cut/transition detection program & library.
https://www.scenedetect.com/
BSD 3-Clause "New" or "Revised" License
3.12k stars 386 forks source link

Find start and end of black frame sequences #409

Open tormento opened 1 month ago

tormento commented 1 month ago

I have a episodic series that has wrong chapters for the end of openings and the start of endings.

I'd like to recreate the correct OP and ED chapters, finding the ranges of the start and the end of the black frames sequences, that are after a OP and before the ED.

Is it possibile with your useful tool? If not, would you please add that feature?

There are 1000+ episodes, so finding them by hand is a big no.

Thank you!

Breakthrough commented 1 month ago

Right now it would be a bit verbose but it is possible. With the threshold detector, you can find ranges where there are black frame sequences. However, by default, the output of this detector is a cut placed in the middle of the range.

This can be controlled by the fade bias parameter. With that, you can run detection twice: once with fade bias at -1.0, and another at +1.0. The first run would place the cuts at the start of the black frame sequence, and the second run would place them at the end. The downside is you need to run detection twice and process multiple output files, but it is possible.


That being said, we are working on API improvements to support these kinds of use cases. I don't know how long it will take for those to get to the CLI tool however, but you could hack this into a custom build pretty easily even as-is by logging timecodes at each fade-in/fade-out event in ThresholdDetector.

The fade-out trigger is here: https://github.com/Breakthrough/PySceneDetect/blob/df85d7ddb3ff9532ec74e06ac4c1edf639425713/scenedetect/detectors/threshold_detector.py#L160-L162

And the fade-in trigger: https://github.com/Breakthrough/PySceneDetect/blob/df85d7ddb3ff9532ec74e06ac4c1edf639425713/scenedetect/detectors/threshold_detector.py#L164-L177

In both cases, you could just print frame_num before any other processing happens there to quickly log the frames when the in/out events occur.


Thanks for posting this by the way, I'll need to investigate more about how we would handle outputting this information for the command line tool. Do you have any suggestions? #323 has been open for a while to expand the output formats of PySceneDetect, but I haven't had the time to make any meaningful progress yet. If someone is willing to help out with that it would be greatly appreciated.