1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge pull request #21337 from mansourmoufid:videocapture-get-property-return

Make cv::VideoCapture::get return cv::CAP_PROP_UNKNOWN (-1) for unsupported properties #21337

The return value indicating an unsupported property is not consistent across backends.

I stumbled on this issue because my code was determining if a property value is valid if it's non-zero (like the documentation says), which worked fine on macOS, but not on Android.

For example, auto-exposure is not supported on macOS, so get() returns 0. But it is supported on Android and 0 means auto-exposure is off.

I think -1 is the better return value to indicate unsupported properties.

I made changes to all the backends. I think I got every case. This breaks API compatibility for some backends, so I based this on branch 3.4.

- [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 other license that is incompatible with OpenCV
- [x] The PR is proposed to proper branch
- [ ] There is reference to original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Mansour Moufid
2026-06-02 01:27:24 -04:00
committed by GitHub
parent 1d4d81103e
commit a68e8d8289
37 changed files with 142 additions and 114 deletions
+8 -6
View File
@@ -2100,7 +2100,7 @@ static inline double getCodecIdFourcc(const AVCodecID codec_id)
double CvCapture_FFMPEG::getProperty( int property_id ) const
{
if( !video_st || (!rawMode && !context) ) return 0;
if( !video_st || (!rawMode && !context) ) return CAP_PROP_UNKNOWN;
switch( property_id )
{
@@ -2129,7 +2129,7 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
if (fourcc != -1) return fourcc;
const double codec_tag = (double)video_st->CV_FFMPEG_CODEC_FIELD->codec_tag;
if (codec_tag) return codec_tag;
else return -1;
else return CAP_PROP_UNKNOWN;
}
case CAP_PROP_SAR_NUM:
return _opencv_ffmpeg_get_sample_aspect_ratio(ic->streams[video_stream]).num;
@@ -2143,11 +2143,11 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
AVPixelFormat pix_fmt = video_st->codec->pix_fmt;
#endif
unsigned int fourcc_tag = avcodec_pix_fmt_to_codec_tag(pix_fmt);
return (fourcc_tag == 0) ? (double)-1 : (double)fourcc_tag;
return (fourcc_tag == 0) ? static_cast<double>(CAP_PROP_UNKNOWN) : (double)fourcc_tag;
}
case CAP_PROP_FORMAT:
if (rawMode)
return -1;
return CAP_PROP_UNKNOWN;
else if (!convertRGB)
return CV_8UC1;
else if (enableAlpha)
@@ -2181,6 +2181,8 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
case CAP_PROP_N_THREADS:
if (!rawMode)
return static_cast<double>(context->thread_count);
else
return 0;
break;
case CAP_PROP_PTS:
return static_cast<double>(pts_in_fps_time_base);
@@ -2190,7 +2192,7 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
break;
}
return 0;
return CAP_PROP_UNKNOWN;
}
double CvCapture_FFMPEG::r2d(AVRational r) const
@@ -3007,7 +3009,7 @@ double CvVideoWriter_FFMPEG::getProperty(int propId) const
return static_cast<double>(use_opencl);
}
#endif
return 0;
return CAP_PROP_UNKNOWN;
}
bool CvVideoWriter_FFMPEG::setProperty(int property_id, double value)