MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / ff_frame_thread_encoder_init

Function ff_frame_thread_encoder_init

libavcodec/frame_thread_encoder.c:120–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120av_cold int ff_frame_thread_encoder_init(AVCodecContext *avctx)
121{
122 int i=0;
123 ThreadContext *c;
124 AVCodecContext *thread_avctx = NULL;
125 AVCodecParameters *par = NULL;
126 int ret;
127
128 if( !(avctx->thread_type & FF_THREAD_FRAME)
129 || !(avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
130 return 0;
131
132 if( !avctx->thread_count
133 && avctx->codec_id == AV_CODEC_ID_MJPEG
134 && !(avctx->flags & AV_CODEC_FLAG_QSCALE)) {
135 av_log(avctx, AV_LOG_DEBUG,
136 "Forcing thread count to 1 for MJPEG encoding, use -thread_type slice "
137 "or a constant quantizer if you want to use multiple cpu cores\n");
138 avctx->thread_count = 1;
139 }
140 if( avctx->thread_count > 1
141 && avctx->codec_id == AV_CODEC_ID_MJPEG
142 && !(avctx->flags & AV_CODEC_FLAG_QSCALE))
143 av_log(avctx, AV_LOG_WARNING,
144 "MJPEG CBR encoding works badly with frame multi-threading, consider "
145 "using -threads 1, -thread_type slice or a constant quantizer.\n");
146
147 if (avctx->codec_id == AV_CODEC_ID_HUFFYUV ||
148 avctx->codec_id == AV_CODEC_ID_FFVHUFF) {
149 int warn = 0;
150 int64_t tmp;
151
152 if (avctx->flags & AV_CODEC_FLAG_PASS1)
153 warn = 1;
154 else if (av_opt_get_int(avctx->priv_data, "context", 0, &tmp) >= 0 &&
155 tmp > 0) {
156 warn = av_opt_get_int(avctx->priv_data, "non_deterministic", 0, &tmp) < 0
157 || !tmp;
158 }
159 // huffyuv does not support these with multiple frame threads currently
160 if (warn) {
161 av_log(avctx, AV_LOG_WARNING,
162 "Forcing thread count to 1 for huffyuv encoding with first pass or context 1\n");
163 avctx->thread_count = 1;
164 }
165 }
166
167 if(!avctx->thread_count) {
168 avctx->thread_count = av_cpu_count();
169 avctx->thread_count = FFMIN(avctx->thread_count, MAX_THREADS);
170 }
171
172 if(avctx->thread_count <= 1)
173 return 0;
174
175 if(avctx->thread_count > MAX_THREADS)
176 return AVERROR(EINVAL);
177

Callers 1

ff_encode_preinitFunction · 0.85

Calls 15

av_logFunction · 0.85
av_opt_get_intFunction · 0.85
av_cpu_countFunction · 0.85
ff_pthread_initFunction · 0.85
av_frame_allocFunction · 0.85
av_packet_allocFunction · 0.85
avcodec_parameters_allocFunction · 0.85
avcodec_alloc_context3Function · 0.85
av_opt_copyFunction · 0.85
avcodec_open2Function · 0.85

Tested by

no test coverage detected