mirror of
https://github.com/opencv/opencv.git
synced 2026-11-22 17:33:41 -06:00
FIX: CvCapture_FFMPEG::setProperty(CAP_PROP_POS_*) followed by getProperty #27523 Partially fixes #23088 and #23472. This PR fixes `get(CAP_PROP_POS_MSEC)` calls after a `set(CAP_PROP_POS_*)` without calling `read` first. Since `seek` calls `grabFrame` which already sets `picture_pts`, manually setting `picture_pts` anywhere else in the call stack should not be necessary (except for the special case of seeking to frame 0). Minimal example from #23088 ```cpp for(int i = 0; i < 3; i++) cap.read(img); printf("at: %f frames, %f msec\n", cap.get(CAP_PROP_POS_FRAMES), cap.get(CAP_PROP_POS_MSEC)); cap.set(CAP_PROP_POS_FRAMES, 3); printf("at: %f frames, %f msec\n", cap.get(CAP_PROP_POS_FRAMES), cap.get(CAP_PROP_POS_MSEC)); ``` Current ```txt at: 3.000000 frames, 80.000000 msec at: 3.000000 frames, 0.234375 msec ``` PR ```txt at: 3.000000 frames, 80.000000 msec at: 3.000000 frames, 80.000000 msec ``` It similarly helps with `CAP_PROP_POS_MSEC`: Current ```txt at: 3.000000 frames, 80.000000 msec at: 2.000000 frames, 6.250000 msec ``` PR ```txt at: 3.000000 frames, 80.000000 msec at: 2.000000 frames, 40.000000 msec ``` Note the seek operation is still inconsistent between the `CAP_PROP_POS_*` options as mentioned by #23088, and VFR video seeking has issues discussed in #9053. For fixed-frame rate video, we could change 0.5 to 1 in `void CvCapture_FFMPEG::seek(double sec);` to align `CAP_PROP_POS_MSEC` with `CAP_PROP_POS_FRAMES`, but `CAP_POS_AVI_RATIO` and VFR video would still be broken. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake