Don't seek in VideoManager start() unless required#212
Merged
Breakthrough merged 1 commit intoBreakthrough:masterfrom Apr 12, 2021
Merged
Don't seek in VideoManager start() unless required#212Breakthrough merged 1 commit intoBreakthrough:masterfrom
Breakthrough merged 1 commit intoBreakthrough:masterfrom
Conversation
Owner
|
This is likely related to #213, so feel free to provide your input there as well (the suggestion is to use PyAV instead of OpenCV to do the video seeking). Thank you for the PR, this will be included in v0.5.6. |
Contributor
Author
|
Thank you for accepting the PR! Unfortunately I have very little experience with PyAV, but I think it would be worth looking into. Also, another library that might be helpful is Decord. It offers accurate seeking that is also very fast, even compared to PyAV (from their stats at least, didn't try PyAV's seeking). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Seeking the video by using cv2's
CAP_PROP_POS_FRAMESproperty is not guaranteed to be accurate, and has caused issues for me numerous times. One such example is trying to seek to a certain frame within a video resulted from the concatenation of several transport stream files, when the first video is small (eg. 1.ts - 5 frames, 2.ts - 500 frames -> seeking to frame 0, 1, 2, 3, or 4 would in fact seek to frame 5 - which corresponds to frame 0 from 2.ts and thus entirely skip all the frames in 1.ts).In my case, seeking is simply not necessary, and not doing it ensures the whole video is processed, so I suggest simply not seeking the video if the start timecode is 0.
However, to really fix this, a new way to seek is necessary. If using OpenCV, simply calling
VideoCapture.read()(grab()might work too, and would definitely be faster) until the desired frame number is reached should work. This would however be slower than setting theCAP_PROP_POS_FRAMESproperty, so maybe making accurate seeking optional (via a parameter toseek()or theVideoManageritself perhaps?) would work best.For now though, simply not seeking at all when the start timecode is 0 would be an improvement, at least in my situation.