Merge pull request #20541 from iyadahmed:video_capture_timeout_prop

* VideoCapture timeout set/get

* Common formatting for enum values

* Fix enum values wrongly in videoio.hpp

* Define timeout enum values in public api and align with master
pull/20553/head^2
Iyad Ahmed 3 years ago committed by GitHub
parent 6edc438789
commit 4300bb2e1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/videoio/include/opencv2/videoio.hpp
  2. 4
      modules/videoio/src/cap_ffmpeg_api.hpp
  3. 33
      modules/videoio/src/cap_ffmpeg_impl.hpp

@ -179,6 +179,8 @@ enum VideoCaptureProperties {
CAP_PROP_BITRATE =47, //!< (read-only) Video bitrate in kbits/s
CAP_PROP_ORIENTATION_META=48, //!< (read-only) Frame rotation defined by stream meta (applicable for FFmpeg back-end only)
CAP_PROP_ORIENTATION_AUTO=49, //!< if true - rotates output frames of CvCapture considering video file's metadata (applicable for FFmpeg back-end only) (https://github.com/opencv/opencv/issues/15499)
CAP_PROP_OPEN_TIMEOUT_MSEC=53,
CAP_PROP_READ_TIMEOUT_MSEC=54,
#ifndef CV_DOXYGEN
CV__CAP_PROP_LATEST
#endif

@ -30,7 +30,9 @@ enum
CV_FFMPEG_CAP_PROP_CODEC_PIXEL_FORMAT=46,
CV_FFMPEG_CAP_PROP_BITRATE=47,
CV_FFMPEG_CAP_PROP_ORIENTATION_META=48,
CV_FFMPEG_CAP_PROP_ORIENTATION_AUTO=49
CV_FFMPEG_CAP_PROP_ORIENTATION_AUTO=49,
CV_FFMPEG_CAP_PROP_OPEN_TIMEOUT_MSEC=53,
CV_FFMPEG_CAP_PROP_READ_TIMEOUT_MSEC=54
};
typedef struct CvCapture_FFMPEG CvCapture_FFMPEG;

@ -186,8 +186,8 @@ extern "C" {
#endif
#if USE_AV_INTERRUPT_CALLBACK
#define LIBAVFORMAT_INTERRUPT_OPEN_TIMEOUT_MS 30000
#define LIBAVFORMAT_INTERRUPT_READ_TIMEOUT_MS 30000
#define LIBAVFORMAT_INTERRUPT_OPEN_DEFAULT_TIMEOUT_MS 30000
#define LIBAVFORMAT_INTERRUPT_READ_DEFAULT_TIMEOUT_MS 30000
#ifdef _WIN32
// http://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows
@ -534,6 +534,8 @@ struct CvCapture_FFMPEG
AVDictionary *dict;
#endif
#if USE_AV_INTERRUPT_CALLBACK
int open_timeout_ms;
int read_timeout_ms;
AVInterruptCallbackMetadata interrupt_metadata;
#endif
@ -568,6 +570,11 @@ void CvCapture_FFMPEG::init()
frame_number = 0;
eps_zero = 0.000025;
#if USE_AV_INTERRUPT_CALLBACK
open_timeout_ms = LIBAVFORMAT_INTERRUPT_OPEN_DEFAULT_TIMEOUT_MS;
read_timeout_ms = LIBAVFORMAT_INTERRUPT_READ_DEFAULT_TIMEOUT_MS;
#endif
rotation_angle = 0;
#if (LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0))
@ -923,7 +930,7 @@ bool CvCapture_FFMPEG::open( const char* _filename )
#if USE_AV_INTERRUPT_CALLBACK
/* interrupt callback */
interrupt_metadata.timeout_after_ms = LIBAVFORMAT_INTERRUPT_OPEN_TIMEOUT_MS;
interrupt_metadata.timeout_after_ms = open_timeout_ms;
get_monotonic_time(&interrupt_metadata.value);
ic = avformat_alloc_context();
@ -1227,7 +1234,7 @@ bool CvCapture_FFMPEG::grabFrame()
#if USE_AV_INTERRUPT_CALLBACK
// activate interrupt callback
get_monotonic_time(&interrupt_metadata.value);
interrupt_metadata.timeout_after_ms = LIBAVFORMAT_INTERRUPT_READ_TIMEOUT_MS;
interrupt_metadata.timeout_after_ms = read_timeout_ms;
#endif
// get the next frame
@ -1483,6 +1490,12 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
#else
return 0;
#endif
#if USE_AV_INTERRUPT_CALLBACK
case CV_FFMPEG_CAP_PROP_OPEN_TIMEOUT_MSEC:
return static_cast<double>(open_timeout_ms);
case CV_FFMPEG_CAP_PROP_READ_TIMEOUT_MSEC:
return static_cast<double>(read_timeout_ms);
#endif // USE_AV_INTERRUPT_CALLBACK
default:
break;
}
@ -1677,6 +1690,14 @@ bool CvCapture_FFMPEG::setProperty( int property_id, double value )
return false;
#endif
break;
#if USE_AV_INTERRUPT_CALLBACK
case CV_FFMPEG_CAP_PROP_OPEN_TIMEOUT_MSEC:
open_timeout_ms = (int)value;
break;
case CV_FFMPEG_CAP_PROP_READ_TIMEOUT_MSEC:
read_timeout_ms = (int)value;
break;
#endif // USE_AV_INTERRUPT_CALLBACK
default:
return false;
}
@ -3114,7 +3135,7 @@ bool InputMediaStream_FFMPEG::open(const char* fileName, int* codec, int* chroma
#if USE_AV_INTERRUPT_CALLBACK
/* interrupt callback */
interrupt_metadata.timeout_after_ms = LIBAVFORMAT_INTERRUPT_OPEN_TIMEOUT_MS;
interrupt_metadata.timeout_after_ms = LIBAVFORMAT_INTERRUPT_OPEN_DEFAULT_TIMEOUT_MS;
get_monotonic_time(&interrupt_metadata.value);
ctx_ = avformat_alloc_context();
@ -3241,7 +3262,7 @@ bool InputMediaStream_FFMPEG::read(unsigned char** data, int* size, int* endOfFi
#if USE_AV_INTERRUPT_CALLBACK
// activate interrupt callback
get_monotonic_time(&interrupt_metadata.value);
interrupt_metadata.timeout_after_ms = LIBAVFORMAT_INTERRUPT_READ_TIMEOUT_MS;
interrupt_metadata.timeout_after_ms = LIBAVFORMAT_INTERRUPT_READ_DEFAULT_TIMEOUT_MS;
#endif
// free last packet if exist

Loading…
Cancel
Save