mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00
videoio(ffmpeg): limit number of default threads
This commit is contained in:
parent
91ac790249
commit
8676d19dc3
@ -373,42 +373,6 @@ inline double get_monotonic_time_diff_ms(timespec time1, timespec time2)
|
|||||||
}
|
}
|
||||||
#endif // USE_AV_INTERRUPT_CALLBACK
|
#endif // USE_AV_INTERRUPT_CALLBACK
|
||||||
|
|
||||||
static int get_number_of_cpus(void)
|
|
||||||
{
|
|
||||||
#if defined _WIN32
|
|
||||||
SYSTEM_INFO sysinfo;
|
|
||||||
GetSystemInfo( &sysinfo );
|
|
||||||
|
|
||||||
return (int)sysinfo.dwNumberOfProcessors;
|
|
||||||
#elif defined __linux__ || defined __HAIKU__
|
|
||||||
return (int)sysconf( _SC_NPROCESSORS_ONLN );
|
|
||||||
#elif defined __APPLE__
|
|
||||||
int numCPU=0;
|
|
||||||
int mib[4];
|
|
||||||
size_t len = sizeof(numCPU);
|
|
||||||
|
|
||||||
// set the mib for hw.ncpu
|
|
||||||
mib[0] = CTL_HW;
|
|
||||||
mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU;
|
|
||||||
|
|
||||||
// get the number of CPUs from the system
|
|
||||||
sysctl(mib, 2, &numCPU, &len, NULL, 0);
|
|
||||||
|
|
||||||
if( numCPU < 1 )
|
|
||||||
{
|
|
||||||
mib[1] = HW_NCPU;
|
|
||||||
sysctl( mib, 2, &numCPU, &len, NULL, 0 );
|
|
||||||
|
|
||||||
if( numCPU < 1 )
|
|
||||||
numCPU = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (int)numCPU;
|
|
||||||
#else
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct Image_FFMPEG
|
struct Image_FFMPEG
|
||||||
{
|
{
|
||||||
@ -998,12 +962,17 @@ public:
|
|||||||
|
|
||||||
inline void fill_codec_context(AVCodecContext * enc, AVDictionary * dict)
|
inline void fill_codec_context(AVCodecContext * enc, AVDictionary * dict)
|
||||||
{
|
{
|
||||||
//#ifdef FF_API_THREAD_INIT
|
if (!enc->thread_count)
|
||||||
// avcodec_thread_init(enc, get_number_of_cpus());
|
{
|
||||||
//#else
|
int nCpus = cv::getNumberOfCPUs();
|
||||||
const int nCpus = get_number_of_cpus();
|
int requestedThreads = std::min(nCpus, 16); // [OPENCV:FFMPEG:24] Application has requested XX threads. Using a thread count greater than 16 is not recommended.
|
||||||
enc->thread_count = enc->thread_count ? enc->thread_count: nCpus;
|
char* threads_option = getenv("OPENCV_FFMPEG_THREADS");
|
||||||
//#endif
|
if (threads_option != NULL)
|
||||||
|
{
|
||||||
|
requestedThreads = atoi(threads_option);
|
||||||
|
}
|
||||||
|
enc->thread_count = requestedThreads;
|
||||||
|
}
|
||||||
|
|
||||||
AVDictionaryEntry* avdiscard_entry = av_dict_get(dict, "avdiscard", NULL, 0);
|
AVDictionaryEntry* avdiscard_entry = av_dict_get(dict, "avdiscard", NULL, 0);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user