-
-
Notifications
You must be signed in to change notification settings - Fork 56.3k
Closed
Labels
Description
System information (version)
- OpenCV => 4.5.2
- Operating System / Platform => Ubuntu 20.04
- Tested with Python 3.8.5
Detailed description
I have been working with VideoCapture, everything working fine until I tested my code with an older video in .mpg format. In that video occurs the following:
- When doing cap.set(cv2.CAP_PROP_POS_FRAMES, 0), the frame is not set to the first frame, but rather to a posterior frame. The same happens for other intermediate frames, where it seems to be skipping some frames.
- When doing cap.read() it works properly (beginning from the frame 0 and reading all the intermediate frames).
- When re-encoding the video with ffmpeg, doing cap.set(cv2.CAP_PROP_POS_FRAMES, 0) works properly (i.e. doesn't skip initial frames). If the video codec is copied (-c:v copy), it follows the same wrong behaviour.
I think it might be related to the IBP frame encoding, positioning to the closes "I" frame, but I believe it should be considered a bug if the intention of cap.set() is to position specifically to the frame of interest.
EDIT: Link to the video was in the middle of the text.
Steps to reproduce
cap = cv2.VideoCapture('2001_10_20_19_00_trim.mpg')
# Works as expected
_, frame = cap.read()
cv2.imwrite('0_read.jpg', frame)
# Returns a posterior frame
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
_, frame = cap.read()
cv2.imwrite('0_set.jpg', frame)
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found solution - I updated to latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc