PySceneDetect
PySceneDetect copied to clipboard
Allow for clips to be split with content outside of start/end timeframe
Description of Problem & Solution When using -start and -end, the tool defines the area of a video to be processed. In some cases, however, you may wish to limit the area to be analyzed, but treat the area outside of that window as part of the split files.
Example, 30 minute file with one scene break at 15 minutes:
0-------------13-15-17--------------30
---------------**|**------------------
In the current tool, a command such as scenedetect -i somevideo.mp4 time -s 00:13:00 -e 00:15:00 detect-threshold split-video -c will produce two clips, each of 2 minute duration.
However, in some cases you may wish to have two 15 minute clips, including the content before and after the processed duration.
Proposed Implementation:
A proposed command line to enable this would be -expand-split-clips
Alternative Solutions:
Using the timecodes generated can be fed into ffmpeg and executed manually / via a script.
This should definitely be possible to add to PySceneDetect, thanks for the suggestion @charlesvestal.
Technical notes for myself (or anyone else who wants to take a crack at this) which may be useful:
- It should be possible to just modify the arguments passed to the
get_scenes_from_cuts()function called by the SceneManager, passing 0 for the start time and the video length for the end time to achieve the desired outcome (the only difficulty being getting the video length) - When creating the VideoManager with this option, only the start time should be modified; the end time must only be set when calling
detect_scenes()to support getting the video length - Surprisingly, the only thing which makes this complicated is reliably getting the total number of frames in a video file; I've found using the OpenCV
getmethod to obtain VideoCapture properties can be somewhat unreliable (thus internally it is only used for estimation of progress, but video streams are processed until exhausted) - Something like
SeekToEnd()needs to be implemented to the VideoManager to manually seek to the end and get this number in the case where-expand-split-clipsis passed - Perhaps an additional option could be added to allow using the estimated total length instead of seeking through the whole video (which is currently somewhat slow), but I would prefer correctness over speed for the first implementation of such a feature regardless