mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge pull request #22248 from cudawarped:ffmpeg_rtsp_low_fps
* Allow the number of threads FFMpeg uses to be selected during VideoCapture::open(). Reset interupt timer in grab if err = avformat_find_stream_info(ic, NULL); is interupted but open is successful. * Correct the returned number of threads and amend test cases. * Update container test case. * Reverse changes added to existing videoio_container test case and include test combining thread change and raw read in the newly added videoio_read test case.
This commit is contained in:
@@ -987,7 +987,8 @@ inline void fill_codec_context(AVCodecContext * enc, AVDictionary * dict)
|
||||
//#ifdef FF_API_THREAD_INIT
|
||||
// avcodec_thread_init(enc, get_number_of_cpus());
|
||||
//#else
|
||||
enc->thread_count = get_number_of_cpus();
|
||||
const int nCpus = get_number_of_cpus();
|
||||
enc->thread_count = enc->thread_count ? enc->thread_count: nCpus;
|
||||
//#endif
|
||||
|
||||
AVDictionaryEntry* avdiscard_entry = av_dict_get(dict, "avdiscard", NULL, 0);
|
||||
@@ -1024,6 +1025,7 @@ bool CvCapture_FFMPEG::open(const char* _filename, const VideoCaptureParameters&
|
||||
|
||||
unsigned i;
|
||||
bool valid = false;
|
||||
int nThreads = 0;
|
||||
|
||||
close();
|
||||
|
||||
@@ -1081,6 +1083,10 @@ bool CvCapture_FFMPEG::open(const char* _filename, const VideoCaptureParameters&
|
||||
read_timeout = params.get<int>(CAP_PROP_READ_TIMEOUT_MSEC);
|
||||
}
|
||||
#endif
|
||||
if (params.has(CAP_PROP_N_THREADS))
|
||||
{
|
||||
nThreads = params.get<int>(CAP_PROP_N_THREADS);
|
||||
}
|
||||
if (params.warnUnusedParameters())
|
||||
{
|
||||
CV_LOG_ERROR(NULL, "VIDEOIO/FFMPEG: unsupported parameters in .open(), see logger INFO channel for details. Bailout");
|
||||
@@ -1248,6 +1254,7 @@ bool CvCapture_FFMPEG::open(const char* _filename, const VideoCaptureParameters&
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
context->thread_count = nThreads;
|
||||
fill_codec_context(context, dict);
|
||||
#ifdef CV_FFMPEG_CODECPAR
|
||||
avcodec_parameters_to_context(context, par);
|
||||
@@ -1444,6 +1451,7 @@ bool CvCapture_FFMPEG::grabFrame()
|
||||
|
||||
#if USE_AV_INTERRUPT_CALLBACK
|
||||
// activate interrupt callback
|
||||
interrupt_metadata.timeout = 0;
|
||||
get_monotonic_time(&interrupt_metadata.value);
|
||||
interrupt_metadata.timeout_after_ms = read_timeout;
|
||||
#endif
|
||||
@@ -1774,6 +1782,8 @@ double CvCapture_FFMPEG::getProperty( int property_id ) const
|
||||
case CAP_PROP_STREAM_OPEN_TIME_USEC:
|
||||
//ic->start_time_realtime is in microseconds
|
||||
return ((double)ic->start_time_realtime);
|
||||
case CAP_PROP_N_THREADS:
|
||||
return static_cast<double>(context->thread_count);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user