mirror of
https://github.com/opencv/opencv.git
synced 2026-07-21 19:33:03 +04:00
Merge pull request #27523 from inventshah:fix-set-then-get-pos
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
This commit is contained in:
@@ -1030,4 +1030,31 @@ inline static std::string videoio_ffmpeg_mismatch_name_printer(const testing::Te
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/**/, videoio_ffmpeg_channel_mismatch, testing::ValuesIn(mismatch_cases), videoio_ffmpeg_mismatch_name_printer);
|
||||
|
||||
// PR: https://github.com/opencv/opencv/pull/27523
|
||||
// TODO: Enable the tests back on Windows after FFmpeg plugin rebuild
|
||||
#ifndef _WIN32
|
||||
|
||||
// related issue: https://github.com/opencv/opencv/issues/23088
|
||||
TEST(ffmpeg_cap_properties, set_pos_get_msec)
|
||||
{
|
||||
if (!videoio_registry::hasBackend(CAP_FFMPEG))
|
||||
throw SkipTestException("FFmpeg backend was not found");
|
||||
|
||||
string video_file = findDataFile("video/big_buck_bunny.mp4");
|
||||
VideoCapture cap;
|
||||
EXPECT_NO_THROW(cap.open(video_file, CAP_FFMPEG));
|
||||
ASSERT_TRUE(cap.isOpened()) << "Can't open the video";
|
||||
|
||||
cap.set(CAP_PROP_POS_FRAMES, 25);
|
||||
EXPECT_EQ(cap.get(CAP_PROP_POS_MSEC), 1000.0);
|
||||
|
||||
cap.set(CAP_PROP_POS_MSEC, 525);
|
||||
EXPECT_EQ(cap.get(CAP_PROP_POS_MSEC), 500.0);
|
||||
|
||||
cap.set(CAP_PROP_POS_AVI_RATIO, 0);
|
||||
EXPECT_EQ(cap.get(CAP_PROP_POS_MSEC), 0.0);
|
||||
}
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user