Skip to content

Commit 01edce1

Browse files
authored
Merge pull request #33 from luowyang/limit-threads
Limit the maximal number of threads used by FFmpeg to 16.
2 parents 1cab5aa + c34c386 commit 01edce1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/mvextractor/video_cap.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ bool VideoCap::open(const char *url) {
112112
if (avcodec_parameters_to_context(this->video_dec_ctx, st->codecpar) < 0)
113113
goto error;
114114

115-
this->video_dec_ctx->thread_count = std::thread::hardware_concurrency();
115+
// FFmpeg recommends no more than 16 threads
116+
auto thread_count = std::min(std::thread::hardware_concurrency(), 16u);
117+
this->video_dec_ctx->thread_count = static_cast<int>(thread_count);
116118
#ifdef DEBUG
117119
std::cerr << "Using parallel processing with " << this->video_dec_ctx->thread_count << " threads" << std::endl;
118120
#endif

0 commit comments

Comments
 (0)