mirror of
https://github.com/opencv/opencv.git
synced 2025-07-25 22:57:53 +08:00
Merge pull request #22145 from danopdev:issues-22141
Fixed time value obtained on some frames at the end of the video #22141
This commit is contained in:
commit
a6017ac550
@ -1518,10 +1518,6 @@ bool CvCapture_FFMPEG::grabFrame()
|
|||||||
ret = got_picture ? 0 : -1;
|
ret = got_picture ? 0 : -1;
|
||||||
#endif
|
#endif
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
//picture_pts = picture->best_effort_timestamp;
|
|
||||||
if( picture_pts == AV_NOPTS_VALUE_ )
|
|
||||||
picture_pts = picture->CV_FFMPEG_PTS_FIELD != AV_NOPTS_VALUE_ && picture->CV_FFMPEG_PTS_FIELD != 0 ? picture->CV_FFMPEG_PTS_FIELD : picture->pkt_dts;
|
|
||||||
|
|
||||||
valid = true;
|
valid = true;
|
||||||
} else if (ret == AVERROR(EAGAIN)) {
|
} else if (ret == AVERROR(EAGAIN)) {
|
||||||
continue;
|
continue;
|
||||||
@ -1534,8 +1530,11 @@ bool CvCapture_FFMPEG::grabFrame()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid)
|
if (valid) {
|
||||||
|
if( picture_pts == AV_NOPTS_VALUE_ )
|
||||||
|
picture_pts = picture->CV_FFMPEG_PTS_FIELD != AV_NOPTS_VALUE_ && picture->CV_FFMPEG_PTS_FIELD != 0 ? picture->CV_FFMPEG_PTS_FIELD : picture->pkt_dts;
|
||||||
frame_number++;
|
frame_number++;
|
||||||
|
}
|
||||||
|
|
||||||
if (!rawMode && valid && first_frame_number < 0)
|
if (!rawMode && valid && first_frame_number < 0)
|
||||||
first_frame_number = dts_to_frame_number(picture_pts);
|
first_frame_number = dts_to_frame_number(picture_pts);
|
||||||
|
@ -215,8 +215,28 @@ public:
|
|||||||
throw SkipTestException(cv::String("Backend ") + cv::videoio_registry::getBackendName(apiPref) +
|
throw SkipTestException(cv::String("Backend ") + cv::videoio_registry::getBackendName(apiPref) +
|
||||||
cv::String(" can't open the video: ") + video_file);
|
cv::String(" can't open the video: ") + video_file);
|
||||||
|
|
||||||
|
int frame_count = (int)cap.get(CAP_PROP_FRAME_COUNT);
|
||||||
|
|
||||||
|
// HACK: Video consists of 125 frames, but cv::VideoCapture with FFmpeg reports only 122 frames for mpg video.
|
||||||
|
// mpg file reports 5.08 sec * 24 fps => property returns 122 frames,but actual number of frames returned is 125
|
||||||
|
// HACK: CAP_PROP_FRAME_COUNT is not supported for vmw + MSMF. Just force check for all 125 frames
|
||||||
|
if (ext == "mpg")
|
||||||
|
EXPECT_GT(frame_count, 121);
|
||||||
|
else if ((ext == "wmv") && (apiPref == CAP_MSMF))
|
||||||
|
frame_count = 125;
|
||||||
|
else
|
||||||
|
EXPECT_EQ(frame_count, 125);
|
||||||
Mat img;
|
Mat img;
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
|
#ifdef _WIN32 // handle old FFmpeg wrapper on Windows till rebuild
|
||||||
|
frame_count = 10;
|
||||||
|
#else
|
||||||
|
// HACK: FFmpeg reports picture_pts = AV_NOPTS_VALUE_ for the last frame for AVI container by some reason
|
||||||
|
if ((ext == "avi") && (apiPref == CAP_FFMPEG))
|
||||||
|
frame_count--;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int i = 0; i < frame_count; i++)
|
||||||
{
|
{
|
||||||
double timestamp = 0;
|
double timestamp = 0;
|
||||||
ASSERT_NO_THROW(cap >> img);
|
ASSERT_NO_THROW(cap >> img);
|
||||||
|
Loading…
Reference in New Issue
Block a user