-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
live callbacks for live-streams. #151
Conversation
EDIT FROM @Breakthrough : This example is outdated as of v0.6. See #273 for an updated example until one gets added to the official documentation. A usage example: cam = cv2.VideoCapture(0)
scene_manager.add_detector(ContentDetector())
scene_manager.detect_scenes(frame_source=cam, callback=lambda frame: print("a new scene: ", len(frame))) |
scenedetect/scene_manager.py
Outdated
# type(int, numpy.ndarray) -> None | ||
""" Adds any cuts detected with the current frame to the cutting list. """ | ||
for detector in self._detector_list: | ||
self._cutting_list += detector.process_frame(frame_num, frame_im) | ||
cuts = detector.process_frame(frame_num, frame_im) | ||
if len(cuts) and callback: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be if cuts and callback:
?
scenedetect/scene_manager.py
Outdated
for detector in self._sparse_detector_list: | ||
self._event_list += detector.process_frame(frame_num, frame_im) | ||
events = detector.process_frame(frame_num, frame_im) | ||
if len(events) and callback: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. I think PyLint will flag this line is why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, suggest using PyLint or something similar though.
Very minor changes requested for code style/quality, but overall great PR!
scenedetect/scene_manager.py
Outdated
# type: (VideoManager, Union[int, FrameTimecode], | ||
# Optional[Union[int, FrameTimecode]], Optional[bool]) -> int | ||
# Optional[Union[int, FrameTimecode]], Optional[bool], optional[callable]) -> int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional[callable] should be Optional[Callable[numpy.ndarray]]
scenedetect/scene_manager.py
Outdated
self._cutting_list += detector.process_frame(frame_num, frame_im) | ||
cuts = detector.process_frame(frame_num, frame_im) | ||
if len(cuts) and callback: | ||
callback(frame_im) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the frame number or timecode be passed to the callback as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do the frame number, but where do I obtain the timecode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I forgot the scene manager only deals with frame numbers. Just the frame number should be sufficient. Sorry for the delay in getting back to you on this one, will definitely be trying to get this in for the next release though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem at all. I pushed a commit with frame_num
.
Thanks! I installed PyLint in PyCharm and pushed some changes. |
I may retarget this for the v0.6.x branch before merging it, and have to update the documentation with some examples, but this will definitely make it in for the next release. Thank you so much for this! |
This is great! You are welcome! |
@mhashim6 you are most welcome! Would it be okay if I referenced your paper on the following page: (If not, no worries!) Thank you so much! |
Oh not at all, I'd actually be glad! Thank you! |
live callbacks for live-streams. Resolves #5.
when i tried this on a live video input, it throws error,
|
@research-boy The API has changed slightly in v0.6, you need to use a
Hope this helps! |
@research-boy I also filed #273 to track adding an official example for this use case to the API documentation. Hopefully that will clear up any inconsistencies, since this example is outdated. |
@Breakthrough Thanks for the example. # in opencv how i read
cap = cv2.VideoCapture("videotestsrc ! appsink")
# As per the example you shared
cam = VideoStreamCv2("videotestsrc ! appsink") when i tried the example with this it throws error cam = VideoStreamCv2(source)
File "/usr/local/lib/python3.6/dist-packages/scenedetect/backends/opencv.py", line 92, in __init__
self._open_capture(framerate)
File "/usr/local/lib/python3.6/dist-packages/scenedetect/backends/opencv.py", line 297, in _open_capture
raise OSError('Video file not found.')
|
Ah thanks for sharing, that definitely needs to be fixed. This check needs to also see if there is a In the meantime, I've filed #276 and will make sure to include a fix for this in the next release (v0.6.1.). Thanks for bringing this to my attention, and sorry for the inconvenience. |
@research-boy do you also need to set Thanks! |
Ya , the video feed is getting initialized right now after commenting out those lines.
cv2.CAP_GSTREAMER is not necessary , opencv by default recognizes the argument accordingly After the video is initialized i am getting another error:
|
Would you be able to file a new bug report for this in the issue tracker? I would like to get some more information from you about how to reproduce this, but would rather start a new issue specifically for this case (and keep the discussion there). Thanks! If possible, in the bug report, could you include some steps for how I can reproduce the issue? I am not familiar with gstreamer or pipes (do they work with the It would also be useful to know if this issue exists on v0.5 as well, or if this is something that fails only in v0.6. I can certainly investigate further into that if you can point me in the right direction, or provide some steps for how to set this up. Edit: Also, if I am reading the error correctly, it seems like the stream somehow returned two frames of different sizes. Are you using any kind of filters or anything which might change or crop the frame? |
I've updated #276 as well for the next v0.6.1 release so this should work more smoothly by letting people pass their own |
Do you know why those frames are smaller than the rest of the video, and is it always the same number of frames? Is there an easy way I can reproduce this on my end? PySceneDetect requires each frame to be the same size, so you may want to skip over the first few frames until you start getting frames with the correct size. In v0.6.1 there will be a new adapter that lets you use a In the meantime, if you are still using a Hope this helps! |
@Breakthrough as of now i am not sure why this is happening, i tried getting the frame directly in gstreamer itself , still it's same, it's look like that how the plugin is initializing the frame |
With this, we can use continuous camera feed (eg, cv2::VideoCapture) and have live detection of scenes/events. Basically, issue #5