Skip to content

Commit 688c6b7

Browse files
authored
Merge pull request #161 from OpenShot/limit-threads-for-omp-and-ffmpeg
Limiting threads for both FFmpeg and OpenMP
2 parents e879188 + 6b37ad7 commit 688c6b7

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

include/OpenMPUtilities.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
#include <stdlib.h>
3333
#include <string.h>
3434

35-
// Calculate the # of OpenMP Threads to allow
36-
#define OPEN_MP_NUM_PROCESSORS omp_get_num_procs()
35+
// Calculate the # of OpenMP and FFmpeg Threads to allow. We are limiting both
36+
// of these based on our own performance tests (more is not always better).
37+
#define OPEN_MP_NUM_PROCESSORS (min(omp_get_num_procs(), 6))
38+
#define FF_NUM_PROCESSORS (min(omp_get_num_procs(), 12))
3739

3840
using namespace std;
3941

src/FFmpegReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void FFmpegReader::Open()
153153
pCodecCtx = AV_GET_CODEC_CONTEXT(pStream, pCodec);
154154

155155
// Set number of threads equal to number of processors (not to exceed 16)
156-
pCodecCtx->thread_count = min(OPEN_MP_NUM_PROCESSORS, 16);
156+
pCodecCtx->thread_count = min(FF_NUM_PROCESSORS, 16);
157157

158158
if (pCodec == NULL) {
159159
throw InvalidCodec("A valid video codec could not be found for this file.", path);
@@ -191,7 +191,7 @@ void FFmpegReader::Open()
191191
aCodecCtx = AV_GET_CODEC_CONTEXT(aStream, aCodec);
192192

193193
// Set number of threads equal to number of processors (not to exceed 16)
194-
aCodecCtx->thread_count = min(OPEN_MP_NUM_PROCESSORS, 16);
194+
aCodecCtx->thread_count = min(FF_NUM_PROCESSORS, 16);
195195

196196
if (aCodec == NULL) {
197197
throw InvalidCodec("A valid audio codec could not be found for this file.", path);

src/FFmpegWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ void FFmpegWriter::open_audio(AVFormatContext *oc, AVStream *st)
10261026
AV_GET_CODEC_FROM_STREAM(st, audio_codec)
10271027

10281028
// Set number of threads equal to number of processors (not to exceed 16)
1029-
audio_codec->thread_count = min(OPEN_MP_NUM_PROCESSORS, 16);
1029+
audio_codec->thread_count = min(FF_NUM_PROCESSORS, 16);
10301030

10311031
// Find the audio encoder
10321032
codec = avcodec_find_encoder_by_name(info.acodec.c_str());
@@ -1100,7 +1100,7 @@ void FFmpegWriter::open_video(AVFormatContext *oc, AVStream *st)
11001100
AV_GET_CODEC_FROM_STREAM(st, video_codec)
11011101

11021102
// Set number of threads equal to number of processors (not to exceed 16)
1103-
video_codec->thread_count = min(OPEN_MP_NUM_PROCESSORS, 16);
1103+
video_codec->thread_count = min(FF_NUM_PROCESSORS, 16);
11041104

11051105
/* find the video encoder */
11061106
codec = avcodec_find_encoder_by_name(info.vcodec.c_str());

0 commit comments

Comments
 (0)