Allow selection of which scenes images and video clips are made with save-images and spit-video
Description of Problem & Solution
I've had some situations where I have a large number of video files with a similar structure where I'd like to select (or omit) a certain number of scenes from the output, either at the beginning or end of the file. These are generally Youtube downloads where the channel has a bunch of content at the beginning (title sequence) or end ("please like and subscribe!") that I'd rather not waste time saving and deleting.
It would be nice of scenedetect had a way to select these to avoid extra files being created.
Proposed Implementation:
My proposal is to add a --scenes (-S) option that takes a string in the form of a comma-separated list of array indexes or slices. These indexes and slices would be used to generate a list of array indexes for the detected scene list, and only those indexes would be output when running save-images or split-video.
For example:
scenedetect -i input.mp4 --scenes 0,-3:
would save the first scene and the last three scenes, while
scenedetect -i input.mp4 --scenes 5:-5
would omit the first five and last 5 scenes.
In the case where the scene indexes are all positive (i.e. none of them depend on knowing how long the list is) my implementation of this also short-circuits the detect-scenes process, stopping after it knows that there are no more scenes that will be kept. So -S 0 runs extremely fast, breaking out of scene detection once it gets to the first cut, and just saving the images / video from the first scene.
Knowing a priori what scenes are to be kept is a bit of a unique situation, so I don't know if this is anything anyone else would care to have, but I've already implemented it and it works for me (tm), so I'd be happy to submit a PR if there's any interest. Would just need to tidy it up and add docs.
I still think there's value in saying "give me the first X scenes" or "give me the last X scenes", or a combination thereof. I just want to make sure the command-line syntax is correct or intuitive (I'm not sure I follow what the slice operator means in the first example?).
I like the idea of breaking early as well, but am curious as to how you did it - feel free to post a pull request if you would like and link it to this issue.
I just want to make sure the command-line syntax is correct or intuitive
Understandable. If you think that this will be a significant speedbump for users, I'm open to other suggestions on how to accomplish the same thing with a more intuitive syntax.
(I'm not sure I follow what the slice operator means in the first example?).
I assume your confusion results from the -3: bit. The command-line option is a comma-separated list of either integers or slices in [start[:stop[:step]]] notation, depending on whether you want to select a single scene (with an integer) or a number of them (with a slice).
In this case,-3: translates to the Python slice object slice(-3, None, None), which means start at the third to last scene and include the rest of them from that point. Including the trailing : denotes that this is a slice and not an integer. Any unspecified stop or step arguments are assumed to be None.
Does that clear things up?
Yes sorry @tonycpsu, I initially misunderstood your original post. Just wanted to make sure I fully understood the idea, looks good to me though.
Only other comment I have is it would be nice to have a single-letter argument in addition to --scenes. Thoughts on calling it --scene-range (or -r) instead, or any other names which would allow a single-letter alternative to --scenes?
(Only because -s is already for the statsfile...)
I used -S for the short argument, but I can change it to -r if you think that will create confusion with -s.
I'm not a huge fan of using capitalization to distinguish single-letter arguments, but if anyone feels strongly otherwise feel free to voice your opinion here.
As @tonycpsu submitted the PR it uses -r which I do actually prefer (thanks again for the PR, looking forward to getting it merged soon!)
Hopefully this use case can be covered in v0.6.2 with the use of the load-scenes command, which should work for both the split-video and save-images use case.
Happy to reopen this in the future if anyone needs this feature or load-scenes is not sufficient for this purpose.