Skip to content

Add close() and context manager support to VideoStream - #587

Open
vishal-tambi wants to merge 2 commits into
Breakthrough:mainfrom
vishal-tambi:feature/videostream-close-568
Open

vishal-tambi wants to merge 2 commits into
Breakthrough:mainfrom
vishal-tambi:feature/videostream-close-568

Conversation

@vishal-tambi

Copy link
Copy Markdown
Contributor

This adds a public close() method and with support to VideoStream, so callers can release file handles and decoders right away instead of waiting for garbage collection (fixes #568). The base method does nothing, so existing subclasses keep working, while the OpenCV, PyAV, MoviePy and concat backends release their resources and raise ValueError if used after closing. Properties like path, frame_rate, duration and frame_size still work after closing, because each backend records them in close() just before it releases the handle. VideoStreamConcat now also closes each input once it is done with it, including when construction fails, which used to leave every input open.

stream = auto_close(vs_type(get_absolute_path("resources/testvideo.mp4")))
with pytest.raises(RuntimeError, match="raised in with block"), stream:
raise RuntimeError("raised in with block")
with pytest.raises(ValueError):

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add close() to VideoStream API; VideoStreamConcat leaks child streams

2 participants