VideoCapture is skipping frames (Bug #1690)


Added by Julien Rebetez almost 13 years ago. Updated about 12 years ago.


Status:Done Start date:2012-03-15
Priority:Normal Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:highgui-video
Target version:2.4.4
Affected version:2.4.0 Operating System:
Difficulty: HW Platform:
Pull request:

Description

Hello,

I am using OpenCV (python bindings - awesome btw, kudos !) to play an AVI file. By comparing the output of my program with another video playing program (VLC), I came to the conclusion that OpenCV is skipping frames at the beginning of the video. (see attached images for Opencv/VLC first frame comparison).

The sample video can be found in this zip1. It's the videos/out6510211.avi file.

The video sequence begins with someone turning a light on and off. In VLC, the video correctly starts with the light being turned on and off, while in OpenCV, the first image is when the light has already being turned off, which is around 2 seconds later (~60 frames).

In my original code, I simply create a VideoCapture and start reading frames from it. It turns out that by calling capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 0), the problem gets fixed. It seems to also work with any other CV_CAP_PROP.

To summarize, it looks like after creating a VideoCapture, you need to set a capture property for the video capture to start at the correct frame.

This doesn't seem to be normal behaviour as I haven't seen any indication in the docs that capture.set() needs to be called before reading frames.

[1] http://kitchen.cs.cmu.edu/Pilot/Sub1Brownies/videos.zip


13.png - OpenCV first frame (78.3 kB) Julien Rebetez, 2012-03-15 02:45 pm

26.png - VLC first frame (100.2 kB) Julien Rebetez, 2012-03-15 02:45 pm

not_working.py - Original code showcasing the bug (395 Bytes) Julien Rebetez, 2012-03-15 02:45 pm

cv_play_video.py - Code with fix (setting a video property) (1 kB) Julien Rebetez, 2012-03-15 02:45 pm


Related issues

related to Bug #1938: Python cv2.VideoCapture.read() does not read all frames Open 2012-05-15

Associated revisions

Revision 90f8906e
Added by Roman Donchenko over 11 years ago

Merge pull request #1690 from SpecLad:cmake-2.8.12

History

Updated by Alexander Shishkov almost 13 years ago

  • Category changed from python bindings to highgui-images
  • Assignee set to Alexander Reshetnikov

Updated by Alexander Shishkov almost 13 years ago

  • Target version deleted ()

Updated by Alexander Shishkov almost 13 years ago

  • Assignee deleted (Alexander Reshetnikov)

Updated by Alexander Shishkov almost 13 years ago

  • Target version deleted ()

Updated by Andrey Kamaev over 12 years ago

  • Category changed from highgui-images to highgui-video

Updated by Vadim Pisarevsky about 12 years ago

probably, the problem has been fixed already; need to check. the videos are still available for download

  • Affected version set to 2.4.0
  • Target version deleted ()

Updated by Vadim Pisarevsky about 12 years ago

  • Assignee set to Vadim Pisarevsky

Updated by Vadim Pisarevsky about 12 years ago

ok. It looks like without capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 0) all the frames are read well. If you call capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, 0), it indeed skips a few first frames. Why it happens - we can not say.

I think, we have a feature request regarding implementing frame-accurate video seeking. So we will appreciate a patch that does that.
The problem in the ticket, as it stated, has been solved in 2.4.2 or 2.4.3.

  • Status changed from Open to Done

Updated by Kirill Kornyakov about 12 years ago

  • Target version set to 2.4.4

Also available in: Atom PDF