Skip to content

Don't seek in VideoManager start() unless required#212

Merged
Breakthrough merged 1 commit intoBreakthrough:masterfrom
dadus33:master
Apr 12, 2021
Merged

Don't seek in VideoManager start() unless required#212
Breakthrough merged 1 commit intoBreakthrough:masterfrom
dadus33:master

Conversation

@dadus33
Copy link
Contributor

@dadus33 dadus33 commented Apr 7, 2021

Seeking the video by using cv2's CAP_PROP_POS_FRAMES property 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 the CAP_PROP_POS_FRAMES property, so maybe making accurate seeking optional (via a parameter to seek() or the VideoManager itself 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.

@Breakthrough Breakthrough merged commit 26cf7c9 into Breakthrough:master Apr 12, 2021
@Breakthrough
Copy link
Owner

Breakthrough commented Apr 12, 2021

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.

@Breakthrough Breakthrough added this to the v0.5.6 milestone Apr 12, 2021
@dadus33
Copy link
Contributor Author

dadus33 commented Apr 13, 2021

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).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants