Merge pull request #16713 from VadimLevin:dev/vlevin/ffmpeg_video_capture_bitrate
* feature: Add video capture bitrate read-only property for FFMPEG backend * test: For WIN32 property should be either expected or 0. Added `IsOneOf` helper function, enabled only for _WIN32.
This commit is contained in:
@@ -573,5 +573,68 @@ TEST(Videoio_Video_parallel_writers_and_readers, accuracy)
|
||||
readers.clear();
|
||||
}
|
||||
|
||||
typedef std::pair<VideoCaptureProperties, double> cap_property_t;
|
||||
typedef std::vector<cap_property_t> cap_properties_t;
|
||||
typedef std::pair<std::string, cap_properties_t> ffmpeg_cap_properties_param_t;
|
||||
typedef testing::TestWithParam<ffmpeg_cap_properties_param_t> ffmpeg_cap_properties;
|
||||
|
||||
#ifdef _WIN32
|
||||
namespace {
|
||||
::testing::AssertionResult IsOneOf(double value, double expected1, double expected2)
|
||||
{
|
||||
// internal floating point class is used to perform accurate floating point types comparison
|
||||
typedef ::testing::internal::FloatingPoint<double> FloatingPoint;
|
||||
|
||||
FloatingPoint val(value);
|
||||
if (val.AlmostEquals(FloatingPoint(expected1)) || val.AlmostEquals(FloatingPoint(expected2)))
|
||||
{
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
else
|
||||
{
|
||||
return ::testing::AssertionFailure()
|
||||
<< value << " is neither equal to " << expected1 << " nor " << expected2;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_P(ffmpeg_cap_properties, can_read_property)
|
||||
{
|
||||
ffmpeg_cap_properties_param_t parameters = GetParam();
|
||||
const std::string path = parameters.first;
|
||||
const cap_properties_t properties = parameters.second;
|
||||
|
||||
VideoCapture cap(findDataFile(path), CAP_FFMPEG);
|
||||
ASSERT_TRUE(cap.isOpened()) << "Can not open " << findDataFile(path);
|
||||
|
||||
for (std::size_t i = 0; i < properties.size(); ++i)
|
||||
{
|
||||
const cap_property_t& prop = properties[i];
|
||||
const double actualValue = cap.get(static_cast<int>(prop.first));
|
||||
#ifndef _WIN32
|
||||
EXPECT_DOUBLE_EQ(actualValue, prop.second)
|
||||
<< "Property " << static_cast<int>(prop.first) << " has wrong value";
|
||||
#else
|
||||
EXPECT_TRUE(IsOneOf(actualValue, prop.second, 0.0))
|
||||
<< "Property " << static_cast<int>(prop.first) << " has wrong value";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
cap_properties_t loadBigBuckBunnyFFProbeResults() {
|
||||
cap_property_t properties[] = { cap_property_t(CAP_PROP_BITRATE, 5851.),
|
||||
cap_property_t(CAP_PROP_FPS, 24.),
|
||||
cap_property_t(CAP_PROP_FRAME_HEIGHT, 384.),
|
||||
cap_property_t(CAP_PROP_FRAME_WIDTH, 672.) };
|
||||
return cap_properties_t(properties, properties + sizeof(properties) / sizeof(cap_property_t));
|
||||
}
|
||||
|
||||
const ffmpeg_cap_properties_param_t videoio_ffmpeg_properties[] = {
|
||||
ffmpeg_cap_properties_param_t("video/big_buck_bunny.avi", loadBigBuckBunnyFFProbeResults())
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(videoio, ffmpeg_cap_properties, testing::ValuesIn(videoio_ffmpeg_properties));
|
||||
|
||||
#endif
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user