Skip to content

Commit 800294a

Browse files
committed
Merge pull request opencv#10060 from allnes:videoio_tests_backend
2 parents 7ae1946 + 6f48dc2 commit 800294a

File tree

2 files changed

+152
-47
lines changed

2 files changed

+152
-47
lines changed

modules/videoio/src/cap_gstreamer.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,8 @@
7878
#if GST_VERSION_MAJOR == 0
7979
#define COLOR_ELEM "ffmpegcolorspace"
8080
#define COLOR_ELEM_NAME "ffmpegcsp"
81-
#elif FULL_GST_VERSION < VERSION_NUM(1,5,0)
82-
#define COLOR_ELEM "videoconvert"
83-
#define COLOR_ELEM_NAME COLOR_ELEM
8481
#else
85-
#define COLOR_ELEM "autovideoconvert"
82+
#define COLOR_ELEM "videoconvert"
8683
#define COLOR_ELEM_NAME COLOR_ELEM
8784
#endif
8885

modules/videoio/test/test_video_io.cpp

Lines changed: 151 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Videoio_Test_Base
5454
protected:
5555
string ext;
5656
string video_file;
57+
int apiPref;
5758
protected:
5859
Videoio_Test_Base() {}
5960
virtual ~Videoio_Test_Base() {}
@@ -81,13 +82,25 @@ class Videoio_Test_Base
8182
public:
8283
void doTest()
8384
{
84-
VideoCapture cap(video_file);
85-
if (!cap.isOpened())
85+
if (apiPref == CAP_AVFOUNDATION)
86+
{
87+
// TODO: fix this backend
88+
std::cout << "SKIP test: AVFoundation backend returns invalid frame count" << std::endl;
89+
return;
90+
}
91+
else if (apiPref == CAP_VFW)
8692
{
87-
std::cout << "SKIP test: Can't open video: " << video_file << std::endl;
93+
// TODO: fix this backend
94+
std::cout << "SKIP test: Video for Windows backend not open files" << std::endl;
8895
return;
8996
}
9097

98+
VideoCapture cap(video_file, apiPref);
99+
if (!cap.isOpened())
100+
{
101+
std::cout << "SKIP test: backend " << apiPref << " can't open the video: " << video_file << std::endl;
102+
return;
103+
}
91104
int n_frames = (int)cap.get(CAP_PROP_FRAME_COUNT);
92105
if (n_frames > 0)
93106
{
@@ -107,7 +120,6 @@ class Videoio_Test_Base
107120
checkFrameRead(k, cap);
108121
}
109122
}
110-
111123
bool canSeek = cap.set(CAP_PROP_POS_FRAMES, 0);
112124
if (!canSeek)
113125
{
@@ -138,21 +150,37 @@ class Videoio_Test_Base
138150
};
139151

140152
//==================================================================================================
153+
typedef tuple<string, int> Backend_Type_Params;
141154

142-
class Videoio_Bunny : public Videoio_Test_Base, public testing::TestWithParam<string>
155+
class Videoio_Bunny : public Videoio_Test_Base, public testing::TestWithParam<Backend_Type_Params>
143156
{
144157
public:
145158
Videoio_Bunny()
146159
{
147-
ext = GetParam();
160+
ext = get<0>(GetParam());
161+
apiPref = get<1>(GetParam());
162+
148163
video_file = cvtest::TS::ptr()->get_data_path() + "video/big_buck_bunny." + ext;
149164
}
150165
void doFrameCountTest()
151166
{
152-
VideoCapture cap(video_file);
167+
if (apiPref == CAP_AVFOUNDATION)
168+
{
169+
// TODO: fix this backend
170+
std::cout << "SKIP test: AVFoundation backend returns invalid frame count" << std::endl;
171+
return;
172+
}
173+
else if (apiPref == CAP_VFW)
174+
{
175+
// TODO: fix this backend
176+
std::cout << "SKIP test: Video for Windows backend not open files" << std::endl;
177+
return;
178+
}
179+
180+
VideoCapture cap(video_file, apiPref);
153181
if (!cap.isOpened())
154182
{
155-
std::cout << "SKIP test: Can't open video: " << video_file << std::endl;
183+
std::cout << "SKIP test: backend " << apiPref << " can't open the video: " << video_file << std::endl;
156184
return;
157185
}
158186

@@ -171,8 +199,8 @@ class Videoio_Bunny : public Videoio_Test_Base, public testing::TestWithParam<st
171199
else
172200
std::cout << "FPS is not available. SKIP check." << std::endl;
173201

174-
int count_prop = (int)cap.get(CAP_PROP_FRAME_COUNT);
175-
202+
int count_prop = 0;
203+
count_prop = (int)cap.get(CAP_PROP_FRAME_COUNT);
176204
// mpg file reports 5.08 sec * 24 fps => property returns 122 frames
177205
// but actual number of frames returned is 125
178206
if (ext != "mpg")
@@ -203,7 +231,7 @@ class Videoio_Bunny : public Videoio_Test_Base, public testing::TestWithParam<st
203231
}
204232
};
205233

206-
typedef tuple<string, string, float> Ext_Fourcc_PSNR;
234+
typedef tuple<string, string, float, int> Ext_Fourcc_PSNR;
207235
typedef tuple<Size, Ext_Fourcc_PSNR> Size_Ext_Fourcc_PSNR;
208236

209237
class Videoio_Synthetic : public Videoio_Test_Base, public testing::TestWithParam<Size_Ext_Fourcc_PSNR>
@@ -224,11 +252,25 @@ class Videoio_Synthetic : public Videoio_Test_Base, public testing::TestWithPara
224252
video_file = cv::tempfile((fourccToString(fourcc) + "." + ext).c_str());
225253
frame_count = 100;
226254
fps = 25.;
255+
apiPref = get<3>(param);
227256
}
228257
void SetUp()
229258
{
259+
260+
if (apiPref == CAP_AVFOUNDATION)
261+
{
262+
// TODO: fix this backend
263+
std::cout << "SKIP test: AVFoundation backend can not write video" << std::endl;
264+
return;
265+
}
266+
else if (apiPref == CAP_VFW)
267+
{
268+
// TODO: fix this backend
269+
std::cout << "SKIP test: Video for Windows backend not open files" << std::endl;
270+
return;
271+
}
230272
Mat img(frame_size, CV_8UC3);
231-
VideoWriter writer(video_file, fourcc, fps, frame_size, true);
273+
VideoWriter writer(video_file, apiPref, fourcc, fps, frame_size, true);
232274
ASSERT_TRUE(writer.isOpened());
233275
for(int i = 0; i < frame_count; ++i )
234276
{
@@ -261,11 +303,6 @@ class Videoio_Synthetic : public Videoio_Test_Base, public testing::TestWithPara
261303
if (fourcc == VideoWriter::fourcc('M', 'P', 'E', 'G') && ext == "mkv")
262304
expected_frame_count.end += 1;
263305

264-
// Hack! Some GStreamer encoding pipelines drop last frame in the video
265-
#ifdef HAVE_GSTREAMER
266-
expected_frame_count.start -= 1;
267-
#endif
268-
269306
ASSERT_LE(expected_frame_count.start, actual);
270307
ASSERT_GE(expected_frame_count.end, actual);
271308

@@ -275,14 +312,41 @@ class Videoio_Synthetic : public Videoio_Test_Base, public testing::TestWithPara
275312

276313
//==================================================================================================
277314

315+
int backend_params[] = {
316+
#ifdef HAVE_QUICKTIME
317+
CAP_QT,
318+
#endif
319+
320+
#ifdef HAVE_AVFOUNDATION
321+
CAP_AVFOUNDATION,
322+
#endif
323+
324+
#ifdef HAVE_MSMF
325+
CAP_MSMF,
326+
#endif
327+
328+
#ifdef HAVE_VFW
329+
CAP_VFW,
330+
#endif
331+
332+
#ifdef HAVE_GSTREAMER
333+
CAP_GSTREAMER,
334+
#endif
335+
336+
#ifdef HAVE_FFMPEG
337+
CAP_FFMPEG,
338+
#endif
339+
CAP_OPENCV_MJPEG
340+
// CAP_INTEL_MFX
341+
};
278342

279343
string bunny_params[] = {
280344
#ifdef HAVE_VIDEO_INPUT
281-
string("avi"),
345+
string("wmv"),
282346
string("mov"),
283347
string("mp4"),
284348
string("mpg"),
285-
string("wmv"),
349+
string("avi"),
286350
#endif
287351
string("mjpg.avi")
288352
};
@@ -292,49 +356,93 @@ TEST_P(Videoio_Bunny, read_position) { doTest(); }
292356
TEST_P(Videoio_Bunny, frame_count) { doFrameCountTest(); }
293357

294358
INSTANTIATE_TEST_CASE_P(videoio, Videoio_Bunny,
295-
testing::ValuesIn(bunny_params));
359+
testing::Combine(
360+
testing::ValuesIn(bunny_params),
361+
testing::ValuesIn(backend_params)));
296362

297363

298364
//==================================================================================================
299365

300-
inline Ext_Fourcc_PSNR makeParam(const char * ext, const char * fourcc, float psnr)
366+
inline Ext_Fourcc_PSNR makeParam(const char * ext, const char * fourcc, float psnr, int apipref)
301367
{
302-
return make_tuple(string(ext), string(fourcc), (float)psnr);
368+
return make_tuple(string(ext), string(fourcc), (float)psnr, (int)apipref);
303369
}
304370

305371
Ext_Fourcc_PSNR synthetic_params[] = {
306372

307-
#if defined(HAVE_VIDEO_INPUT) && defined(HAVE_VIDEO_OUTPUT) && !defined(__APPLE__)
308-
309373
#ifdef HAVE_MSMF
374+
#if !defined(_M_ARM)
375+
makeParam("wmv", "WMV1", 30.f, CAP_MSMF),
376+
makeParam("wmv", "WMV2", 30.f, CAP_MSMF),
377+
#endif
378+
makeParam("wmv", "WMV3", 30.f, CAP_MSMF),
379+
makeParam("wmv", "WVC1", 30.f, CAP_MSMF),
380+
makeParam("avi", "H264", 30.f, CAP_MSMF),
381+
makeParam("avi", "MJPG", 30.f, CAP_MSMF),
382+
#endif
310383

384+
#ifdef HAVE_VFW
311385
#if !defined(_M_ARM)
312-
makeParam("wmv", "WMV1", 30.f),
313-
makeParam("wmv", "WMV2", 30.f),
386+
makeParam("wmv", "WMV1", 30.f, CAP_VFW),
387+
makeParam("wmv", "WMV2", 30.f, CAP_VFW),
388+
#endif
389+
makeParam("wmv", "WMV3", 30.f, CAP_VFW),
390+
makeParam("wmv", "WVC1", 30.f, CAP_VFW),
391+
makeParam("avi", "H264", 30.f, CAP_VFW),
392+
makeParam("avi", "MJPG", 30.f, CAP_VFW),
314393
#endif
315-
makeParam("wmv", "WMV3", 30.f),
316-
makeParam("avi", "H264", 30.f),
317-
makeParam("wmv", "WVC1", 30.f),
318-
319-
#else // HAVE_MSMF
320-
321-
makeParam("avi", "XVID", 30.f),
322-
makeParam("avi", "MPEG", 30.f),
323-
makeParam("avi", "IYUV", 30.f),
324-
makeParam("mkv", "XVID", 30.f),
325-
makeParam("mkv", "MPEG", 30.f),
326-
makeParam("mkv", "MJPG", 30.f),
327-
#ifndef HAVE_GSTREAMER
328-
makeParam("mov", "mp4v", 30.f),
394+
395+
#ifdef HAVE_QUICKTIME
396+
makeParam("mov", "mp4v", 30.f, CAP_QT),
397+
makeParam("avi", "XVID", 30.f, CAP_QT),
398+
makeParam("avi", "MPEG", 30.f, CAP_QT),
399+
makeParam("avi", "IYUV", 30.f, CAP_QT),
400+
makeParam("avi", "MJPG", 30.f, CAP_QT),
401+
402+
makeParam("mkv", "XVID", 30.f, CAP_QT),
403+
makeParam("mkv", "MPEG", 30.f, CAP_QT),
404+
makeParam("mkv", "MJPG", 30.f, CAP_QT),
329405
#endif
330406

331-
#endif // HAVE_MSMF
407+
#ifdef HAVE_AVFOUNDATION
408+
makeParam("mov", "mp4v", 30.f, CAP_AVFOUNDATION),
409+
makeParam("avi", "XVID", 30.f, CAP_AVFOUNDATION),
410+
makeParam("avi", "MPEG", 30.f, CAP_AVFOUNDATION),
411+
makeParam("avi", "IYUV", 30.f, CAP_AVFOUNDATION),
412+
makeParam("avi", "MJPG", 30.f, CAP_AVFOUNDATION),
413+
414+
makeParam("mkv", "XVID", 30.f, CAP_AVFOUNDATION),
415+
makeParam("mkv", "MPEG", 30.f, CAP_AVFOUNDATION),
416+
makeParam("mkv", "MJPG", 30.f, CAP_AVFOUNDATION),
417+
#endif
332418

333-
#endif // HAVE_VIDEO_INPUT && HAVE_VIDEO_OUTPUT ...
419+
#ifdef HAVE_FFMPEG
420+
makeParam("avi", "XVID", 30.f, CAP_FFMPEG),
421+
makeParam("avi", "MPEG", 30.f, CAP_FFMPEG),
422+
makeParam("avi", "IYUV", 30.f, CAP_FFMPEG),
423+
makeParam("avi", "MJPG", 30.f, CAP_FFMPEG),
334424

335-
makeParam("avi", "MJPG", 30.f)
425+
makeParam("mkv", "XVID", 30.f, CAP_FFMPEG),
426+
makeParam("mkv", "MPEG", 30.f, CAP_FFMPEG),
427+
makeParam("mkv", "MJPG", 30.f, CAP_FFMPEG),
428+
#endif
429+
430+
#ifdef HAVE_GSTREAMER
431+
// makeParam("avi", "XVID", 30.f, CAP_GSTREAMER), - corrupted frames, broken indexes
432+
makeParam("avi", "MPEG", 30.f, CAP_GSTREAMER),
433+
makeParam("avi", "IYUV", 30.f, CAP_GSTREAMER),
434+
makeParam("avi", "MJPG", 30.f, CAP_GSTREAMER),
435+
makeParam("avi", "H264", 30.f, CAP_GSTREAMER),
436+
437+
// makeParam("mkv", "XVID", 30.f, CAP_GSTREAMER),
438+
makeParam("mkv", "MPEG", 30.f, CAP_GSTREAMER),
439+
makeParam("mkv", "MJPG", 30.f, CAP_GSTREAMER),
440+
441+
#endif
442+
makeParam("avi", "MJPG", 30.f, CAP_OPENCV_MJPEG),
336443
};
337444

445+
338446
Size all_sizes[] = {
339447
Size(640, 480),
340448
Size(976, 768)

0 commit comments

Comments
 (0)