1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Deepthi Nandakumar <deepthi@multicorewareinc.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
26 #include "threading.h"
32 #pragma warning(disable: 4996) // POSIX functions are just fine, thanks
33 #pragma warning(disable: 4706) // assignment within conditional
34 #pragma warning(disable: 4127) // conditional expression is constant
38 #define strcasecmp _stricmp
41 #if !defined(HAVE_STRTOK_R)
44 * adapted from public domain strtok_r() by Charlie Gordon
46 * from comp.lang.c 9/14/2007
48 * http://groups.google.com/group/comp.lang.c/msg/2ab1ecbb86646684
50 * (Declaration that it's public domain):
51 * http://groups.google.com/group/comp.lang.c/msg/7c7b39328fefab9c
55 char* strtok_r(char * str
,
62 str
+= strspn(str
, delim
);
69 str
+= strcspn(str
, delim
);
79 #endif // if !defined(HAVE_STRTOK_R)
84 x265_param
*x265_param_alloc()
86 return (x265_param
*)x265_malloc(sizeof(x265_param
));
90 void x265_param_free(x265_param
*p
)
96 void x265_param_default(x265_param
*param
)
98 memset(param
, 0, sizeof(x265_param
));
100 /* Applying default values to all elements in the param structure */
101 param
->cpuid
= x265::cpu_detect();
102 param
->bEnableWavefront
= 1;
103 param
->poolNumThreads
= 0;
104 param
->frameNumThreads
= 0;
106 param
->logLevel
= X265_LOG_INFO
;
108 param
->rc
.lambdaFileName
= NULL
;
109 param
->bLogCuStats
= 0;
110 param
->decodedPictureHashSEI
= 0;
112 /* Quality Measurement Metrics */
113 param
->bEnablePsnr
= 0;
114 param
->bEnableSsim
= 0;
116 /* Source specifications */
117 param
->internalBitDepth
= x265_max_bit_depth
;
118 param
->internalCsp
= X265_CSP_I420
;
121 param
->bHighTier
= 0;
122 param
->interlaceMode
= 0;
123 param
->bRepeatHeaders
= 0;
124 param
->bEnableAccessUnitDelimiters
= 0;
125 param
->bEmitHRDSEI
= 0;
126 param
->bEmitInfoSEI
= 1;
129 param
->maxCUSize
= 64;
130 param
->tuQTMaxInterDepth
= 1;
131 param
->tuQTMaxIntraDepth
= 1;
133 /* Coding Structure */
134 param
->keyframeMin
= 0;
135 param
->keyframeMax
= 250;
138 param
->lookaheadDepth
= 20;
139 param
->bFrameAdaptive
= X265_B_ADAPT_TRELLIS
;
140 param
->bBPyramid
= 1;
141 param
->scenecutThreshold
= 40; /* Magic number pulled in from x264 */
143 /* Intra Coding Tools */
144 param
->bEnableConstrainedIntra
= 0;
145 param
->bEnableStrongIntraSmoothing
= 1;
146 param
->bEnableFastIntra
= 0;
148 /* Inter Coding tools */
149 param
->searchMethod
= X265_HEX_SEARCH
;
150 param
->subpelRefine
= 2;
151 param
->searchRange
= 57;
152 param
->maxNumMergeCand
= 2;
153 param
->bEnableWeightedPred
= 1;
154 param
->bEnableWeightedBiPred
= 0;
155 param
->bEnableEarlySkip
= 0;
156 param
->bEnableCbfFastMode
= 0;
157 param
->bEnableAMP
= 0;
158 param
->bEnableRectInter
= 0;
160 param
->bEnableSignHiding
= 1;
161 param
->bEnableTransformSkip
= 0;
162 param
->bEnableTSkipFast
= 0;
163 param
->maxNumReferences
= 3;
164 param
->bEnableTemporalMvp
= 1;
167 param
->bEnableLoopFilter
= 1;
169 /* SAO Loop Filter */
170 param
->bEnableSAO
= 1;
171 param
->bSaoNonDeblocked
= 0;
174 param
->cbQpOffset
= 0;
175 param
->crQpOffset
= 0;
176 param
->rdPenalty
= 0;
178 param
->psyRdoq
= 0.0;
179 param
->bIntraInBFrames
= 0;
180 param
->bLossless
= 0;
181 param
->bCULossless
= 0;
183 /* Rate control options */
184 param
->rc
.vbvMaxBitrate
= 0;
185 param
->rc
.vbvBufferSize
= 0;
186 param
->rc
.vbvBufferInit
= 0.9;
187 param
->rc
.rfConstant
= 28;
188 param
->rc
.bitrate
= 0;
189 param
->rc
.rateTolerance
= 1.0;
190 param
->rc
.qCompress
= 0.6;
191 param
->rc
.ipFactor
= 1.4f
;
192 param
->rc
.pbFactor
= 1.3f
;
193 param
->rc
.qpStep
= 4;
194 param
->rc
.rateControlMode
= X265_RC_CRF
;
196 param
->rc
.aqMode
= X265_AQ_AUTO_VARIANCE
;
197 param
->rc
.aqStrength
= 1.0;
198 param
->rc
.cuTree
= 1;
199 param
->rc
.rfConstantMax
= 0;
200 param
->rc
.rfConstantMin
= 0;
201 param
->rc
.bStatRead
= 0;
202 param
->rc
.bStatWrite
= 0;
203 param
->rc
.statFileName
= NULL
;
204 param
->rc
.complexityBlur
= 20;
205 param
->rc
.qblur
= 0.5;
206 param
->rc
.bEnableSlowFirstPass
= 0;
208 /* Video Usability Information (VUI) */
209 param
->vui
.aspectRatioIdc
= 0;
210 param
->vui
.sarWidth
= 0;
211 param
->vui
.sarHeight
= 0;
212 param
->vui
.bEnableOverscanAppropriateFlag
= 0;
213 param
->vui
.bEnableVideoSignalTypePresentFlag
= 0;
214 param
->vui
.videoFormat
= 5;
215 param
->vui
.bEnableVideoFullRangeFlag
= 0;
216 param
->vui
.bEnableColorDescriptionPresentFlag
= 0;
217 param
->vui
.colorPrimaries
= 2;
218 param
->vui
.transferCharacteristics
= 2;
219 param
->vui
.matrixCoeffs
= 2;
220 param
->vui
.bEnableChromaLocInfoPresentFlag
= 0;
221 param
->vui
.chromaSampleLocTypeTopField
= 0;
222 param
->vui
.chromaSampleLocTypeBottomField
= 0;
223 param
->vui
.bEnableDefaultDisplayWindowFlag
= 0;
224 param
->vui
.defDispWinLeftOffset
= 0;
225 param
->vui
.defDispWinRightOffset
= 0;
226 param
->vui
.defDispWinTopOffset
= 0;
227 param
->vui
.defDispWinBottomOffset
= 0;
231 int x265_param_default_preset(x265_param
*param
, const char *preset
, const char *tune
)
233 x265_param_default(param
);
238 int i
= strtol(preset
, &end
, 10);
239 if (*end
== 0 && i
>= 0 && i
< (int)(sizeof(x265_preset_names
) / sizeof(*x265_preset_names
) - 1))
240 preset
= x265_preset_names
[i
];
242 if (!strcmp(preset
, "ultrafast"))
244 param
->lookaheadDepth
= 10;
245 param
->scenecutThreshold
= 0; // disable lookahead
246 param
->maxCUSize
= 32;
247 param
->searchRange
= 25;
248 param
->bFrameAdaptive
= 0;
249 param
->subpelRefine
= 0;
250 param
->searchMethod
= X265_DIA_SEARCH
;
251 param
->bEnableEarlySkip
= 1;
252 param
->bEnableSAO
= 0;
253 param
->bEnableSignHiding
= 0;
254 param
->bEnableWeightedPred
= 0;
256 param
->maxNumReferences
= 1;
257 param
->bEnableLoopFilter
= 0;
258 param
->rc
.aqStrength
= 0.0;
259 param
->rc
.aqMode
= X265_AQ_NONE
;
260 param
->rc
.cuTree
= 0;
261 param
->bEnableFastIntra
= 1;
263 else if (!strcmp(preset
, "superfast"))
265 param
->lookaheadDepth
= 10;
266 param
->maxCUSize
= 32;
267 param
->searchRange
= 44;
268 param
->bFrameAdaptive
= 0;
269 param
->subpelRefine
= 1;
270 param
->bEnableEarlySkip
= 1;
271 param
->bEnableWeightedPred
= 0;
273 param
->maxNumReferences
= 1;
274 param
->rc
.aqStrength
= 0.0;
275 param
->rc
.aqMode
= X265_AQ_NONE
;
276 param
->rc
.cuTree
= 0;
277 param
->bEnableSAO
= 0;
278 param
->bEnableFastIntra
= 1;
280 else if (!strcmp(preset
, "veryfast"))
282 param
->lookaheadDepth
= 15;
283 param
->maxCUSize
= 32;
284 param
->bFrameAdaptive
= 0;
285 param
->subpelRefine
= 1;
286 param
->bEnableEarlySkip
= 1;
288 param
->maxNumReferences
= 1;
289 param
->rc
.cuTree
= 0;
290 param
->bEnableFastIntra
= 1;
292 else if (!strcmp(preset
, "faster"))
294 param
->lookaheadDepth
= 15;
295 param
->bFrameAdaptive
= 0;
296 param
->bEnableEarlySkip
= 1;
298 param
->maxNumReferences
= 1;
299 param
->rc
.cuTree
= 0;
300 param
->bEnableFastIntra
= 1;
302 else if (!strcmp(preset
, "fast"))
304 param
->lookaheadDepth
= 15;
305 param
->bFrameAdaptive
= 0;
307 param
->maxNumReferences
= 2;
308 param
->bEnableFastIntra
= 1;
310 else if (!strcmp(preset
, "medium"))
314 else if (!strcmp(preset
, "slow"))
316 param
->bEnableRectInter
= 1;
317 param
->lookaheadDepth
= 25;
319 param
->subpelRefine
= 3;
320 param
->maxNumMergeCand
= 3;
321 param
->searchMethod
= X265_STAR_SEARCH
;
323 else if (!strcmp(preset
, "slower"))
325 param
->bEnableWeightedBiPred
= 1;
326 param
->bEnableAMP
= 1;
327 param
->bEnableRectInter
= 1;
328 param
->lookaheadDepth
= 30;
330 param
->tuQTMaxInterDepth
= 2;
331 param
->tuQTMaxIntraDepth
= 2;
333 param
->subpelRefine
= 3;
334 param
->maxNumMergeCand
= 3;
335 param
->searchMethod
= X265_STAR_SEARCH
;
336 param
->bIntraInBFrames
= 1;
338 else if (!strcmp(preset
, "veryslow"))
340 param
->bEnableWeightedBiPred
= 1;
341 param
->bEnableAMP
= 1;
342 param
->bEnableRectInter
= 1;
343 param
->lookaheadDepth
= 40;
345 param
->tuQTMaxInterDepth
= 3;
346 param
->tuQTMaxIntraDepth
= 3;
348 param
->subpelRefine
= 4;
349 param
->maxNumMergeCand
= 4;
350 param
->searchMethod
= X265_STAR_SEARCH
;
351 param
->maxNumReferences
= 5;
352 param
->bIntraInBFrames
= 1;
354 else if (!strcmp(preset
, "placebo"))
356 param
->bEnableWeightedBiPred
= 1;
357 param
->bEnableAMP
= 1;
358 param
->bEnableRectInter
= 1;
359 param
->lookaheadDepth
= 60;
360 param
->searchRange
= 92;
362 param
->tuQTMaxInterDepth
= 4;
363 param
->tuQTMaxIntraDepth
= 4;
365 param
->subpelRefine
= 5;
366 param
->maxNumMergeCand
= 5;
367 param
->searchMethod
= X265_STAR_SEARCH
;
368 param
->bEnableTransformSkip
= 1;
369 param
->maxNumReferences
= 5;
370 param
->rc
.bEnableSlowFirstPass
= 1;
371 param
->bIntraInBFrames
= 1;
372 // TODO: optimized esa
379 if (!strcmp(tune
, "psnr"))
381 param
->rc
.aqStrength
= 0.0;
383 param
->psyRdoq
= 0.0;
385 else if (!strcmp(tune
, "ssim"))
387 param
->rc
.aqMode
= X265_AQ_AUTO_VARIANCE
;
389 param
->psyRdoq
= 0.0;
391 else if (!strcmp(tune
, "fastdecode") ||
392 !strcmp(tune
, "fast-decode"))
394 param
->bEnableLoopFilter
= 0;
395 param
->bEnableSAO
= 0;
396 param
->bEnableWeightedPred
= 0;
397 param
->bEnableWeightedBiPred
= 0;
398 param
->bIntraInBFrames
= 0;
400 else if (!strcmp(tune
, "zerolatency") ||
401 !strcmp(tune
, "zero-latency"))
403 param
->bFrameAdaptive
= 0;
405 param
->lookaheadDepth
= 0;
406 param
->scenecutThreshold
= 0;
407 param
->rc
.cuTree
= 0;
416 static int x265_atobool(const char *str
, bool& bError
)
418 if (!strcmp(str
, "1") ||
419 !strcmp(str
, "true") ||
422 if (!strcmp(str
, "0") ||
423 !strcmp(str
, "false") ||
430 static double x265_atof(const char *str
, bool& bError
)
433 double v
= strtod(str
, &end
);
435 if (end
== str
|| *end
!= '\0')
440 static int parseName(const char *arg
, const char * const * names
, bool& bError
)
442 for (int i
= 0; names
[i
]; i
++)
444 if (!strcmp(arg
, names
[i
]))
450 return x265_atoi(arg
, bError
);
453 /* internal versions of string-to-int with additional error checking */
456 #define atoi(str) x265_atoi(str, bError)
457 #define atof(str) x265_atof(str, bError)
458 #define atobool(str) (bNameWasBool = true, x265_atobool(str, bError))
461 int x265_param_parse(x265_param
*p
, const char *name
, const char *value
)
464 bool bNameWasBool
= false;
465 bool bValueWasNull
= !value
;
469 return X265_PARAM_BAD_NAME
;
471 // skip -- prefix if provided
472 if (name
[0] == '-' && name
[1] == '-')
476 if (strlen(name
) + 1 < sizeof(nameBuf
) && strchr(name
, '_'))
479 strcpy(nameBuf
, name
);
480 while ((c
= strchr(nameBuf
, '_')) != 0)
488 if (!strncmp(name
, "no-", 3))
491 value
= !value
|| x265_atobool(value
, bError
) ? "false" : "true";
493 else if (!strncmp(name
, "no", 2))
496 value
= !value
|| x265_atobool(value
, bError
) ? "false" : "true";
500 else if (value
[0] == '=')
503 #if defined(_MSC_VER)
504 #pragma warning(disable: 4127) // conditional expression is constant
506 #define OPT(STR) else if (!strcmp(name, STR))
507 #define OPT2(STR1, STR2) else if (!strcmp(name, STR1) || !strcmp(name, STR2))
512 p
->cpuid
= atobool(value
);
514 p
->cpuid
= parseCpuName(value
, bError
);
518 if (sscanf(value
, "%u/%u", &p
->fpsNum
, &p
->fpsDenom
) == 2)
522 float fps
= (float)atof(value
);
523 if (fps
> 0 && fps
<= INT_MAX
/ 1000)
525 p
->fpsNum
= (int)(fps
* 1000 + .5);
530 p
->fpsNum
= atoi(value
);
535 OPT("csv") p
->csvfn
= value
;
536 OPT("scaling-list") p
->scalingLists
= value
;
537 OPT("lambda-file") p
->rc
.lambdaFileName
= value
;
538 OPT("threads") p
->poolNumThreads
= atoi(value
);
539 OPT("frame-threads") p
->frameNumThreads
= atoi(value
);
540 OPT("pmode") p
->bDistributeModeAnalysis
= atobool(value
);
541 OPT("pme") p
->bDistributeMotionEstimation
= atobool(value
);
542 OPT2("level-idc", "level")
544 /* allow "5.1" or "51", both converted to integer 51 */
546 p
->levelIdc
= (int)(10 * atof(value
) + .5);
548 p
->levelIdc
= atoi(value
);
550 OPT("high-tier") p
->bHighTier
= atobool(value
);
551 OPT2("log-level", "log")
553 p
->logLevel
= atoi(value
);
557 p
->logLevel
= parseName(value
, logLevelNames
, bError
) - 1;
560 OPT("cu-stats") p
->bLogCuStats
= atobool(value
);
561 OPT("repeat-headers") p
->bRepeatHeaders
= atobool(value
);
562 OPT("wpp") p
->bEnableWavefront
= atobool(value
);
563 OPT("ctu") p
->maxCUSize
= (uint32_t)atoi(value
);
564 OPT("tu-intra-depth") p
->tuQTMaxIntraDepth
= (uint32_t)atoi(value
);
565 OPT("tu-inter-depth") p
->tuQTMaxInterDepth
= (uint32_t)atoi(value
);
566 OPT("subme") p
->subpelRefine
= atoi(value
);
567 OPT("merange") p
->searchRange
= atoi(value
);
568 OPT("rect") p
->bEnableRectInter
= atobool(value
);
569 OPT("amp") p
->bEnableAMP
= atobool(value
);
570 OPT("max-merge") p
->maxNumMergeCand
= (uint32_t)atoi(value
);
571 OPT("temporal-mvp") p
->bEnableTemporalMvp
= atobool(value
);
572 OPT("early-skip") p
->bEnableEarlySkip
= atobool(value
);
573 OPT("fast-cbf") p
->bEnableCbfFastMode
= atobool(value
);
574 OPT("rdpenalty") p
->rdPenalty
= atoi(value
);
575 OPT("tskip") p
->bEnableTransformSkip
= atobool(value
);
576 OPT("no-tskip-fast") p
->bEnableTSkipFast
= atobool(value
);
577 OPT("tskip-fast") p
->bEnableTSkipFast
= atobool(value
);
578 OPT("strong-intra-smoothing") p
->bEnableStrongIntraSmoothing
= atobool(value
);
579 OPT("lossless") p
->bLossless
= atobool(value
);
580 OPT("cu-lossless") p
->bCULossless
= atobool(value
);
581 OPT("constrained-intra") p
->bEnableConstrainedIntra
= atobool(value
);
582 OPT("fast-intra") p
->bEnableFastIntra
= atobool(value
);
583 OPT("open-gop") p
->bOpenGOP
= atobool(value
);
586 p
->scenecutThreshold
= atobool(value
);
587 if (bError
|| p
->scenecutThreshold
)
590 p
->scenecutThreshold
= atoi(value
);
593 OPT("keyint") p
->keyframeMax
= atoi(value
);
594 OPT("min-keyint") p
->keyframeMin
= atoi(value
);
595 OPT("rc-lookahead") p
->lookaheadDepth
= atoi(value
);
596 OPT("bframes") p
->bframes
= atoi(value
);
597 OPT("bframe-bias") p
->bFrameBias
= atoi(value
);
600 p
->bFrameAdaptive
= atobool(value
);
601 if (bError
|| p
->bFrameAdaptive
)
604 p
->bFrameAdaptive
= atoi(value
);
609 p
->interlaceMode
= atobool(value
);
610 if (bError
|| p
->interlaceMode
)
613 p
->interlaceMode
= parseName(value
, x265_interlace_names
, bError
);
616 OPT("ref") p
->maxNumReferences
= atoi(value
);
617 OPT("weightp") p
->bEnableWeightedPred
= atobool(value
);
618 OPT("weightb") p
->bEnableWeightedBiPred
= atobool(value
);
619 OPT("cbqpoffs") p
->cbQpOffset
= atoi(value
);
620 OPT("crqpoffs") p
->crQpOffset
= atoi(value
);
621 OPT("rd") p
->rdLevel
= atoi(value
);
622 OPT("psy-rd") p
->psyRd
= atof(value
);
623 OPT("psy-rdoq") p
->psyRdoq
= atof(value
);
624 OPT("signhide") p
->bEnableSignHiding
= atobool(value
);
625 OPT("b-intra") p
->bIntraInBFrames
= atobool(value
);
626 OPT("lft") p
->bEnableLoopFilter
= atobool(value
);
627 OPT("sao") p
->bEnableSAO
= atobool(value
);
628 OPT("sao-non-deblock") p
->bSaoNonDeblocked
= atobool(value
);
629 OPT("ssim") p
->bEnableSsim
= atobool(value
);
630 OPT("psnr") p
->bEnablePsnr
= atobool(value
);
631 OPT("hash") p
->decodedPictureHashSEI
= atoi(value
);
632 OPT("aud") p
->bEnableAccessUnitDelimiters
= atobool(value
);
633 OPT("info") p
->bEmitInfoSEI
= atobool(value
);
634 OPT("b-pyramid") p
->bBPyramid
= atobool(value
);
635 OPT("hrd") p
->bEmitHRDSEI
= atobool(value
);
636 OPT2("ipratio", "ip-factor") p
->rc
.ipFactor
= atof(value
);
637 OPT2("pbratio", "pb-factor") p
->rc
.pbFactor
= atof(value
);
638 OPT("aq-mode") p
->rc
.aqMode
= atoi(value
);
639 OPT("aq-strength") p
->rc
.aqStrength
= atof(value
);
640 OPT("vbv-maxrate") p
->rc
.vbvMaxBitrate
= atoi(value
);
641 OPT("vbv-bufsize") p
->rc
.vbvBufferSize
= atoi(value
);
642 OPT("vbv-init") p
->rc
.vbvBufferInit
= atof(value
);
643 OPT("crf-max") p
->rc
.rfConstantMax
= atof(value
);
644 OPT("crf-min") p
->rc
.rfConstantMin
= atof(value
);
647 p
->rc
.rfConstant
= atof(value
);
648 p
->rc
.rateControlMode
= X265_RC_CRF
;
652 p
->rc
.bitrate
= atoi(value
);
653 p
->rc
.rateControlMode
= X265_RC_ABR
;
657 p
->rc
.qp
= atoi(value
);
658 p
->rc
.rateControlMode
= X265_RC_CQP
;
660 OPT("input-res") bError
|= sscanf(value
, "%dx%d", &p
->sourceWidth
, &p
->sourceHeight
) != 2;
661 OPT("input-csp") p
->internalCsp
= parseName(value
, x265_source_csp_names
, bError
);
662 OPT("me") p
->searchMethod
= parseName(value
, x265_motion_est_names
, bError
);
663 OPT("cutree") p
->rc
.cuTree
= atobool(value
);
664 OPT("slow-firstpass") p
->rc
.bEnableSlowFirstPass
= atobool(value
);
665 OPT("analysis-mode") p
->analysisMode
= parseName(value
, x265_analysis_names
, bError
);
668 p
->vui
.aspectRatioIdc
= parseName(value
, x265_sar_names
, bError
);
671 p
->vui
.aspectRatioIdc
= X265_EXTENDED_SAR
;
672 bError
= sscanf(value
, "%d:%d", &p
->vui
.sarWidth
, &p
->vui
.sarHeight
) != 2;
677 if (!strcmp(value
, "show"))
678 p
->vui
.bEnableOverscanInfoPresentFlag
= 1;
679 else if (!strcmp(value
, "crop"))
681 p
->vui
.bEnableOverscanInfoPresentFlag
= 1;
682 p
->vui
.bEnableOverscanAppropriateFlag
= 1;
684 else if (!strcmp(value
, "undef"))
685 p
->vui
.bEnableOverscanInfoPresentFlag
= 0;
691 p
->vui
.bEnableVideoSignalTypePresentFlag
= 1;
692 p
->vui
.videoFormat
= parseName(value
, x265_video_format_names
, bError
);
696 p
->vui
.bEnableVideoSignalTypePresentFlag
= 1;
697 p
->vui
.bEnableVideoFullRangeFlag
= parseName(value
, x265_fullrange_names
, bError
);
701 p
->vui
.bEnableVideoSignalTypePresentFlag
= 1;
702 p
->vui
.bEnableColorDescriptionPresentFlag
= 1;
703 p
->vui
.colorPrimaries
= parseName(value
, x265_colorprim_names
, bError
);
707 p
->vui
.bEnableVideoSignalTypePresentFlag
= 1;
708 p
->vui
.bEnableColorDescriptionPresentFlag
= 1;
709 p
->vui
.transferCharacteristics
= parseName(value
, x265_transfer_names
, bError
);
713 p
->vui
.bEnableVideoSignalTypePresentFlag
= 1;
714 p
->vui
.bEnableColorDescriptionPresentFlag
= 1;
715 p
->vui
.matrixCoeffs
= parseName(value
, x265_colmatrix_names
, bError
);
719 p
->vui
.bEnableChromaLocInfoPresentFlag
= 1;
720 p
->vui
.chromaSampleLocTypeTopField
= atoi(value
);
721 p
->vui
.chromaSampleLocTypeBottomField
= p
->vui
.chromaSampleLocTypeTopField
;
725 p
->vui
.bEnableDefaultDisplayWindowFlag
= 1;
726 bError
|= sscanf(value
, "%d,%d,%d,%d",
727 &p
->vui
.defDispWinLeftOffset
,
728 &p
->vui
.defDispWinTopOffset
,
729 &p
->vui
.defDispWinRightOffset
,
730 &p
->vui
.defDispWinBottomOffset
) != 4;
732 OPT("nr") p
->noiseReduction
= atoi(value
);
735 int pass
= Clip3(0, 3, atoi(value
));
736 p
->rc
.bStatWrite
= pass
& 1;
737 p
->rc
.bStatRead
= pass
& 2;
739 OPT("stats") p
->rc
.statFileName
= strdup(value
);
741 return X265_PARAM_BAD_NAME
;
747 bError
|= bValueWasNull
&& !bNameWasBool
;
748 return bError
? X265_PARAM_BAD_VALUE
: 0;
752 // internal encoder functions
754 int x265_atoi(const char *str
, bool& bError
)
757 int v
= strtol(str
, &end
, 0);
759 if (end
== str
|| *end
!= '\0')
765 * auto || true - x265::cpu_detect()
766 * false || no - disabled
767 * integer bitmap value
768 * comma separated list of SIMD names, eg: SSE4.1,XOP */
769 int parseCpuName(const char *value
, bool& bError
)
777 if (isdigit(value
[0]))
778 cpu
= x265_atoi(value
, bError
);
780 cpu
= !strcmp(value
, "auto") || x265_atobool(value
, bError
) ? x265::cpu_detect() : 0;
784 char *buf
= strdup(value
);
785 char *tok
, *saveptr
= NULL
, *init
;
788 for (init
= buf
; (tok
= strtok_r(init
, ",", &saveptr
)); init
= NULL
)
791 for (i
= 0; x265::cpu_names
[i
].flags
&& strcasecmp(tok
, x265::cpu_names
[i
].name
); i
++)
795 cpu
|= x265::cpu_names
[i
].flags
;
796 if (!x265::cpu_names
[i
].flags
)
801 if ((cpu
& X265_CPU_SSSE3
) && !(cpu
& X265_CPU_SSE2_IS_SLOW
))
802 cpu
|= X265_CPU_SSE2_IS_FAST
;
808 static const int fixedRatios
[][2] =
828 void setParamAspectRatio(x265_param
*p
, int width
, int height
)
830 p
->vui
.aspectRatioIdc
= X265_EXTENDED_SAR
;
831 p
->vui
.sarWidth
= width
;
832 p
->vui
.sarHeight
= height
;
833 for (size_t i
= 0; i
< sizeof(fixedRatios
) / sizeof(fixedRatios
[0]); i
++)
835 if (width
== fixedRatios
[i
][0] && height
== fixedRatios
[i
][1])
837 p
->vui
.aspectRatioIdc
= (int)i
+ 1;
843 void getParamAspectRatio(x265_param
*p
, int& width
, int& height
)
845 if (!p
->vui
.aspectRatioIdc
)
849 else if ((size_t)p
->vui
.aspectRatioIdc
<= sizeof(fixedRatios
) / sizeof(fixedRatios
[0]))
851 width
= fixedRatios
[p
->vui
.aspectRatioIdc
- 1][0];
852 height
= fixedRatios
[p
->vui
.aspectRatioIdc
- 1][1];
854 else if (p
->vui
.aspectRatioIdc
== X265_EXTENDED_SAR
)
856 width
= p
->vui
.sarWidth
;
857 height
= p
->vui
.sarHeight
;
865 static inline int _confirm(x265_param
*param
, bool bflag
, const char* message
)
870 x265_log(param
, X265_LOG_ERROR
, "%s\n", message
);
874 int x265_check_params(x265_param
*param
)
876 #define CHECK(expr, msg) check_failed |= _confirm(param, expr, msg)
877 int check_failed
= 0; /* abort if there is a fatal configuration problem */
879 CHECK(param
->maxCUSize
!= 64 && param
->maxCUSize
!= 32 && param
->maxCUSize
!= 16,
880 "max ctu size must be 16, 32, or 64");
881 if (check_failed
== 1)
884 uint32_t maxLog2CUSize
= (uint32_t)g_log2Size
[param
->maxCUSize
];
885 uint32_t tuQTMaxLog2Size
= X265_MIN(maxLog2CUSize
, 5);
886 uint32_t tuQTMinLog2Size
= 2; //log2(4)
888 /* These checks might be temporary */
890 CHECK(param
->internalBitDepth
!= 10,
891 "x265 was compiled for 10bit encodes, only 10bit internal depth supported");
893 CHECK(param
->internalBitDepth
!= 8,
894 "x265 was compiled for 8bit encodes, only 8bit internal depth supported");
897 CHECK(param
->rc
.qp
< -6 * (param
->internalBitDepth
- 8) || param
->rc
.qp
> 51,
898 "QP exceeds supported range (-QpBDOffsety to 51)");
899 CHECK(param
->fpsNum
== 0 || param
->fpsDenom
== 0,
900 "Frame rate numerator and denominator must be specified");
901 CHECK(param
->interlaceMode
< 0 || param
->interlaceMode
> 2,
902 "Interlace mode must be 0 (progressive) 1 (top-field first) or 2 (bottom field first)");
903 CHECK(param
->searchMethod
<0 || param
->searchMethod
> X265_FULL_SEARCH
,
904 "Search method is not supported value (0:DIA 1:HEX 2:UMH 3:HM 5:FULL)");
905 CHECK(param
->searchRange
< 0,
906 "Search Range must be more than 0");
907 CHECK(param
->searchRange
>= 32768,
908 "Search Range must be less than 32768");
909 CHECK(param
->subpelRefine
> X265_MAX_SUBPEL_LEVEL
,
910 "subme must be less than or equal to X265_MAX_SUBPEL_LEVEL (7)");
911 CHECK(param
->subpelRefine
< 0,
912 "subme must be greater than or equal to 0");
913 CHECK(param
->frameNumThreads
< 0,
914 "frameNumThreads (--frame-threads) must be 0 or higher");
915 CHECK(param
->cbQpOffset
< -12, "Min. Chroma Cb QP Offset is -12");
916 CHECK(param
->cbQpOffset
> 12, "Max. Chroma Cb QP Offset is 12");
917 CHECK(param
->crQpOffset
< -12, "Min. Chroma Cr QP Offset is -12");
918 CHECK(param
->crQpOffset
> 12, "Max. Chroma Cr QP Offset is 12");
920 CHECK(tuQTMaxLog2Size
> maxLog2CUSize
,
921 "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");
923 CHECK(param
->tuQTMaxInterDepth
< 1 || param
->tuQTMaxInterDepth
> 4,
924 "QuadtreeTUMaxDepthInter must be greater than 0 and less than 5");
925 CHECK(maxLog2CUSize
< tuQTMinLog2Size
+ param
->tuQTMaxInterDepth
- 1,
926 "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1");
927 CHECK(param
->tuQTMaxIntraDepth
< 1 || param
->tuQTMaxIntraDepth
> 4,
928 "QuadtreeTUMaxDepthIntra must be greater 0 and less than 5");
929 CHECK(maxLog2CUSize
< tuQTMinLog2Size
+ param
->tuQTMaxIntraDepth
- 1,
930 "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1");
932 CHECK(param
->maxNumMergeCand
< 1, "MaxNumMergeCand must be 1 or greater.");
933 CHECK(param
->maxNumMergeCand
> 5, "MaxNumMergeCand must be 5 or smaller.");
935 CHECK(param
->maxNumReferences
< 1, "maxNumReferences must be 1 or greater.");
936 CHECK(param
->maxNumReferences
> MAX_NUM_REF
, "maxNumReferences must be 16 or smaller.");
938 CHECK(param
->sourceWidth
< (int)param
->maxCUSize
|| param
->sourceHeight
< (int)param
->maxCUSize
,
939 "Picture size must be at least one CTU");
940 CHECK(param
->internalCsp
< X265_CSP_I420
|| X265_CSP_I444
< param
->internalCsp
,
941 "Color space must be i420, i422, or i444");
942 CHECK(param
->sourceWidth
& !!CHROMA_H_SHIFT(param
->internalCsp
),
943 "Picture width must be an integer multiple of the specified chroma subsampling");
944 CHECK(param
->sourceHeight
& !!CHROMA_V_SHIFT(param
->internalCsp
),
945 "Picture height must be an integer multiple of the specified chroma subsampling");
947 CHECK(param
->rc
.rateControlMode
> X265_RC_CRF
|| param
->rc
.rateControlMode
< X265_RC_ABR
,
948 "Rate control mode is out of range");
949 CHECK(param
->rdLevel
< 0 || param
->rdLevel
> 6,
950 "RD Level is out of range");
951 CHECK(param
->bframes
> param
->lookaheadDepth
&& !param
->rc
.bStatRead
,
952 "Lookahead depth must be greater than the max consecutive bframe count");
953 CHECK(param
->bframes
< 0,
954 "bframe count should be greater than zero");
955 CHECK(param
->bframes
> X265_BFRAME_MAX
,
956 "max consecutive bframe count must be 16 or smaller");
957 CHECK(param
->lookaheadDepth
> X265_LOOKAHEAD_MAX
,
958 "Lookahead depth must be less than 256");
959 CHECK(param
->rc
.aqMode
< X265_AQ_NONE
|| X265_AQ_AUTO_VARIANCE
< param
->rc
.aqMode
,
960 "Aq-Mode is out of range");
961 CHECK(param
->rc
.aqStrength
< 0 || param
->rc
.aqStrength
> 3,
962 "Aq-Strength is out of range");
963 CHECK(param
->psyRd
< 0 || 2.0 < param
->psyRd
, "Psy-rd strength must be between 0 and 2.0");
964 CHECK(param
->psyRdoq
< 0 || 50.0 < param
->psyRdoq
, "Psy-rdoq strength must be between 0 and 50.0");
965 CHECK(param
->bEnableWavefront
< 0, "WaveFrontSynchro cannot be negative");
966 CHECK(!param
->bEnableWavefront
&& param
->rc
.vbvBufferSize
, "VBV requires wave-front parallelism (--wpp)");
967 CHECK((param
->vui
.aspectRatioIdc
< 0
968 || param
->vui
.aspectRatioIdc
> 16)
969 && param
->vui
.aspectRatioIdc
!= X265_EXTENDED_SAR
,
970 "Sample Aspect Ratio must be 0-16 or 255");
971 CHECK(param
->vui
.aspectRatioIdc
== X265_EXTENDED_SAR
&& param
->vui
.sarWidth
<= 0,
972 "Sample Aspect Ratio width must be greater than 0");
973 CHECK(param
->vui
.aspectRatioIdc
== X265_EXTENDED_SAR
&& param
->vui
.sarHeight
<= 0,
974 "Sample Aspect Ratio height must be greater than 0");
975 CHECK(param
->vui
.videoFormat
< 0 || param
->vui
.videoFormat
> 5,
976 "Video Format must be component,"
977 " pal, ntsc, secam, mac or undef");
978 CHECK(param
->vui
.colorPrimaries
< 0
979 || param
->vui
.colorPrimaries
> 9
980 || param
->vui
.colorPrimaries
== 3,
981 "Color Primaries must be undef, bt709, bt470m,"
982 " bt470bg, smpte170m, smpte240m, film or bt2020");
983 CHECK(param
->vui
.transferCharacteristics
< 0
984 || param
->vui
.transferCharacteristics
> 15
985 || param
->vui
.transferCharacteristics
== 3,
986 "Transfer Characteristics must be undef, bt709, bt470m, bt470bg,"
987 " smpte170m, smpte240m, linear, log100, log316, iec61966-2-4, bt1361e,"
988 " iec61966-2-1, bt2020-10 or bt2020-12");
989 CHECK(param
->vui
.matrixCoeffs
< 0
990 || param
->vui
.matrixCoeffs
> 10
991 || param
->vui
.matrixCoeffs
== 3,
992 "Matrix Coefficients must be undef, bt709, fcc, bt470bg, smpte170m,"
993 " smpte240m, GBR, YCgCo, bt2020nc or bt2020c");
994 CHECK(param
->vui
.chromaSampleLocTypeTopField
< 0
995 || param
->vui
.chromaSampleLocTypeTopField
> 5,
996 "Chroma Sample Location Type Top Field must be 0-5");
997 CHECK(param
->vui
.chromaSampleLocTypeBottomField
< 0
998 || param
->vui
.chromaSampleLocTypeBottomField
> 5,
999 "Chroma Sample Location Type Bottom Field must be 0-5");
1000 CHECK(param
->vui
.defDispWinLeftOffset
< 0,
1001 "Default Display Window Left Offset must be 0 or greater");
1002 CHECK(param
->vui
.defDispWinRightOffset
< 0,
1003 "Default Display Window Right Offset must be 0 or greater");
1004 CHECK(param
->vui
.defDispWinTopOffset
< 0,
1005 "Default Display Window Top Offset must be 0 or greater");
1006 CHECK(param
->vui
.defDispWinBottomOffset
< 0,
1007 "Default Display Window Bottom Offset must be 0 or greater");
1008 CHECK(param
->rc
.rfConstant
< -6 * (param
->internalBitDepth
- 8) || param
->rc
.rfConstant
> 51,
1009 "Valid quality based range: -qpBDOffsetY to 51");
1010 CHECK(param
->rc
.rfConstantMax
< -6 * (param
->internalBitDepth
- 8) || param
->rc
.rfConstantMax
> 51,
1011 "Valid quality based range: -qpBDOffsetY to 51");
1012 CHECK(param
->rc
.rfConstantMin
< -6 * (param
->internalBitDepth
- 8) || param
->rc
.rfConstantMin
> 51,
1013 "Valid quality based range: -qpBDOffsetY to 51");
1014 CHECK(param
->bFrameAdaptive
< 0 || param
->bFrameAdaptive
> 2,
1015 "Valid adaptive b scheduling values 0 - none, 1 - fast, 2 - full");
1016 CHECK(param
->logLevel
<-1 || param
->logLevel
> X265_LOG_FULL
,
1017 "Valid Logging level -1:none 0:error 1:warning 2:info 3:debug 4:full");
1018 CHECK(param
->scenecutThreshold
< 0,
1019 "scenecutThreshold must be greater than 0");
1020 CHECK(param
->rdPenalty
< 0 || param
->rdPenalty
> 2,
1021 "Valid penalty for 32x32 intra TU in non-I slices. 0:disabled 1:RD-penalty 2:maximum");
1022 CHECK(param
->keyframeMax
< -1,
1023 "Invalid max IDR period in frames. value should be greater than -1");
1024 CHECK(param
->decodedPictureHashSEI
< 0 || param
->decodedPictureHashSEI
> 3,
1025 "Invalid hash option. Decoded Picture Hash SEI 0: disabled, 1: MD5, 2: CRC, 3: Checksum");
1026 CHECK(param
->rc
.vbvBufferSize
< 0,
1027 "Size of the vbv buffer can not be less than zero");
1028 CHECK(param
->rc
.vbvMaxBitrate
< 0,
1029 "Maximum local bit rate can not be less than zero");
1030 CHECK(param
->rc
.vbvBufferInit
< 0,
1031 "Valid initial VBV buffer occupancy must be a fraction 0 - 1, or size in kbits");
1032 CHECK(param
->rc
.bitrate
< 0,
1033 "Target bitrate can not be less than zero");
1034 if (param
->noiseReduction
)
1035 CHECK(100 > param
->noiseReduction
|| param
->noiseReduction
> 1000, "Valid noise reduction range 100 - 1000");
1036 CHECK(param
->rc
.rateControlMode
== X265_RC_CRF
&& param
->rc
.bStatRead
,
1037 "Constant rate-factor is incompatible with 2pass");
1038 CHECK(param
->rc
.rateControlMode
== X265_RC_CQP
&& param
->rc
.bStatRead
,
1039 "Constant QP is incompatible with 2pass");
1040 return check_failed
;
1043 void x265_param_apply_fastfirstpass(x265_param
* param
)
1045 /* Set faster options in case of turbo firstpass */
1046 if (param
->rc
.bStatWrite
&& !param
->rc
.bStatRead
)
1048 param
->maxNumReferences
= 1;
1049 param
->maxNumMergeCand
= 1;
1050 param
->bEnableRectInter
= 0;
1051 param
->bEnableFastIntra
= 1;
1052 param
->bEnableAMP
= 0;
1053 param
->searchMethod
= X265_DIA_SEARCH
;
1054 param
->subpelRefine
= X265_MIN(2, param
->subpelRefine
);
1055 param
->bEnableEarlySkip
= 1;
1056 param
->rdLevel
= X265_MIN(2, param
->rdLevel
);
1060 int x265_set_globals(x265_param
*param
)
1062 static int once
/* = 0 */;
1064 if (ATOMIC_CAS32(&once
, 0, 1) == 1)
1066 if (param
->maxCUSize
!= g_maxCUSize
)
1068 x265_log(param
, X265_LOG_ERROR
, "maxCUSize must be the same for all encoders in a single process");
1074 uint32_t maxLog2CUSize
= (uint32_t)g_log2Size
[param
->maxCUSize
];
1076 // set max CU width & height
1077 g_maxCUSize
= param
->maxCUSize
;
1078 g_maxLog2CUSize
= maxLog2CUSize
;
1080 // compute actual CU depth with respect to config depth and max transform size
1081 g_maxCUDepth
= maxLog2CUSize
- MIN_LOG2_CU_SIZE
;
1082 g_maxFullDepth
= maxLog2CUSize
- LOG2_UNIT_SIZE
;
1084 // initialize partition order
1085 uint32_t* tmp
= &g_zscanToRaster
[0];
1086 initZscanToRaster(g_maxFullDepth
, 1, 0, tmp
);
1087 initRasterToZscan(g_maxFullDepth
);
1092 void x265_print_params(x265_param
*param
)
1094 if (param
->logLevel
< X265_LOG_INFO
)
1098 x265_log(param
, X265_LOG_INFO
, "Internal bit depth : %d\n", param
->internalBitDepth
);
1100 if (param
->interlaceMode
)
1101 x265_log(param
, X265_LOG_INFO
, "Interlaced field inputs : %s\n", x265_interlace_names
[param
->interlaceMode
]);
1103 x265_log(param
, X265_LOG_INFO
, "CTU size / RQT depth inter / intra : %d / %d / %d\n",
1104 param
->maxCUSize
, param
->tuQTMaxInterDepth
, param
->tuQTMaxIntraDepth
);
1106 x265_log(param
, X265_LOG_INFO
, "ME / range / subpel / merge : %s / %d / %d / %d\n",
1107 x265_motion_est_names
[param
->searchMethod
], param
->searchRange
, param
->subpelRefine
, param
->maxNumMergeCand
);
1109 if (param
->keyframeMax
!= INT_MAX
|| param
->scenecutThreshold
)
1110 x265_log(param
, X265_LOG_INFO
, "Keyframe min / max / scenecut : %d / %d / %d\n", param
->keyframeMin
, param
->keyframeMax
, param
->scenecutThreshold
);
1112 x265_log(param
, X265_LOG_INFO
, "Keyframe min / max / scenecut : disabled\n");
1114 if (param
->cbQpOffset
|| param
->crQpOffset
)
1115 x265_log(param
, X265_LOG_INFO
, "Cb/Cr QP Offset : %d / %d\n", param
->cbQpOffset
, param
->crQpOffset
);
1117 if (param
->rdPenalty
)
1118 x265_log(param
, X265_LOG_INFO
, "Intra 32x32 TU penalty type : %d\n", param
->rdPenalty
);
1120 x265_log(param
, X265_LOG_INFO
, "Lookahead / bframes / badapt : %d / %d / %d\n", param
->lookaheadDepth
, param
->bframes
, param
->bFrameAdaptive
);
1121 x265_log(param
, X265_LOG_INFO
, "b-pyramid / weightp / weightb / refs: %d / %d / %d / %d\n",
1122 param
->bBPyramid
, param
->bEnableWeightedPred
, param
->bEnableWeightedBiPred
, param
->maxNumReferences
);
1124 if (param
->bLossless
)
1125 x265_log(param
, X265_LOG_INFO
, "Rate Control : Lossless\n");
1126 else switch (param
->rc
.rateControlMode
)
1129 x265_log(param
, X265_LOG_INFO
, "Rate Control / AQ-Strength / CUTree : ABR-%d kbps / %0.1f / %d\n", param
->rc
.bitrate
,
1130 param
->rc
.aqStrength
, param
->rc
.cuTree
);
1133 x265_log(param
, X265_LOG_INFO
, "Rate Control / AQ-Strength / CUTree : CQP-%d / %0.1f / %d\n", param
->rc
.qp
, param
->rc
.aqStrength
,
1137 x265_log(param
, X265_LOG_INFO
, "Rate Control / AQ-Strength / CUTree : CRF-%0.1f / %0.1f / %d\n", param
->rc
.rfConstant
,
1138 param
->rc
.aqStrength
, param
->rc
.cuTree
);
1142 if (param
->rc
.vbvBufferSize
)
1143 x265_log(param
, X265_LOG_INFO
, "VBV/HRD buffer / max-rate / init : %d / %d / %.3f\n",
1144 param
->rc
.vbvBufferSize
, param
->rc
.vbvMaxBitrate
, param
->rc
.vbvBufferInit
);
1146 x265_log(param
, X265_LOG_INFO
, "tools: ");
1147 #define TOOLOPT(FLAG, STR) if (FLAG) fprintf(stderr, "%s ", STR)
1148 TOOLOPT(param
->bEnableRectInter
, "rect");
1149 TOOLOPT(param
->bEnableAMP
, "amp");
1150 fprintf(stderr
, "rd=%d ", param
->rdLevel
);
1151 if (param
->psyRd
> 0.)
1152 fprintf(stderr
, "psy-rd=%.2lf ", param
->psyRd
);
1153 if (param
->psyRdoq
> 0.)
1154 fprintf(stderr
, "psy-rdoq=%.2lf ", param
->psyRdoq
);
1155 TOOLOPT(param
->bEnableEarlySkip
, "esd");
1156 TOOLOPT(param
->bEnableCbfFastMode
, "cfm");
1157 if (param
->noiseReduction
)
1158 fprintf(stderr
, "nr=%d ", param
->noiseReduction
);
1159 TOOLOPT(param
->bEnableLoopFilter
, "lft");
1160 if (param
->bEnableSAO
)
1161 fprintf(stderr
, "sao%s ", param
->bSaoNonDeblocked
? "-non-deblock" : "");
1162 TOOLOPT(param
->bEnableSignHiding
, "signhide");
1163 TOOLOPT(param
->bEnableConstrainedIntra
, "cip");
1164 TOOLOPT(param
->bIntraInBFrames
, "b-intra");
1165 TOOLOPT(param
->bEnableFastIntra
, "fast-intra");
1166 TOOLOPT(param
->bEnableTemporalMvp
, "tmvp");
1167 if (param
->bEnableTransformSkip
)
1168 fprintf(stderr
, "tskip%s ", param
->bEnableTSkipFast
? "-fast" : "");
1169 TOOLOPT(param
->bCULossless
, "cu-lossless");
1170 TOOLOPT(param
->rc
.bStatWrite
, "stats-write");
1171 TOOLOPT(param
->rc
.bStatRead
, "stats-read");
1172 fprintf(stderr
, "\n");
1176 char *x265_param2string(x265_param
*p
)
1180 buf
= s
= X265_MALLOC(char, MAXPARAMSIZE
);
1184 #define BOOL(param, cliopt) \
1185 s += sprintf(s, " %s", (param) ? cliopt : "no-"cliopt);
1187 s
+= sprintf(s
, "%dx%d", p
->sourceWidth
,p
->sourceHeight
);
1188 s
+= sprintf(s
, " fps=%u/%u", p
->fpsNum
, p
->fpsDenom
);
1189 s
+= sprintf(s
, " bitdepth=%d", p
->internalBitDepth
);
1190 BOOL(p
->bEnableWavefront
, "wpp");
1191 s
+= sprintf(s
, " ctu=%d", p
->maxCUSize
);
1192 s
+= sprintf(s
, " tu-intra-depth=%d", p
->tuQTMaxIntraDepth
);
1193 s
+= sprintf(s
, " tu-inter-depth=%d", p
->tuQTMaxInterDepth
);
1194 s
+= sprintf(s
, " me=%d", p
->searchMethod
);
1195 s
+= sprintf(s
, " subme=%d", p
->subpelRefine
);
1196 s
+= sprintf(s
, " merange=%d", p
->searchRange
);
1197 BOOL(p
->bEnableRectInter
, "rect");
1198 BOOL(p
->bEnableAMP
, "amp");
1199 s
+= sprintf(s
, " max-merge=%d", p
->maxNumMergeCand
);
1200 BOOL(p
->bEnableTemporalMvp
, "temporal-mvp");
1201 BOOL(p
->bEnableEarlySkip
, "early-skip");
1202 BOOL(p
->bEnableCbfFastMode
, "fast-cbf");
1203 s
+= sprintf(s
, " rdpenalty=%d", p
->rdPenalty
);
1204 BOOL(p
->bEnableTransformSkip
, "tskip");
1205 BOOL(p
->bEnableTSkipFast
, "tskip-fast");
1206 BOOL(p
->bEnableStrongIntraSmoothing
, "strong-intra-smoothing");
1207 BOOL(p
->bLossless
, "lossless");
1208 BOOL(p
->bCULossless
, "cu-lossless");
1209 BOOL(p
->bEnableConstrainedIntra
, "constrained-intra");
1210 BOOL(p
->bEnableFastIntra
, "fast-intra");
1211 BOOL(p
->bOpenGOP
, "open-gop");
1212 s
+= sprintf(s
, " interlace=%d", p
->interlaceMode
);
1213 s
+= sprintf(s
, " keyint=%d", p
->keyframeMax
);
1214 s
+= sprintf(s
, " min-keyint=%d", p
->keyframeMin
);
1215 s
+= sprintf(s
, " scenecut=%d", p
->scenecutThreshold
);
1216 s
+= sprintf(s
, " rc-lookahead=%d", p
->lookaheadDepth
);
1217 s
+= sprintf(s
, " bframes=%d", p
->bframes
);
1218 s
+= sprintf(s
, " bframe-bias=%d", p
->bFrameBias
);
1219 s
+= sprintf(s
, " b-adapt=%d", p
->bFrameAdaptive
);
1220 s
+= sprintf(s
, " ref=%d", p
->maxNumReferences
);
1221 BOOL(p
->bEnableWeightedPred
, "weightp");
1222 BOOL(p
->bEnableWeightedBiPred
, "weightb");
1223 s
+= sprintf(s
, " aq-mode=%d", p
->rc
.aqMode
);
1224 s
+= sprintf(s
, " aq-strength=%.2f", p
->rc
.aqStrength
);
1225 s
+= sprintf(s
, " cbqpoffs=%d", p
->cbQpOffset
);
1226 s
+= sprintf(s
, " crqpoffs=%d", p
->crQpOffset
);
1227 s
+= sprintf(s
, " rd=%d", p
->rdLevel
);
1228 s
+= sprintf(s
, " psy-rd=%.2f", p
->psyRd
);
1229 s
+= sprintf(s
, " psy-rdoq=%.2f", p
->psyRdoq
);
1230 BOOL(p
->bEnableSignHiding
, "signhide");
1231 BOOL(p
->bEnableLoopFilter
, "lft");
1232 BOOL(p
->bEnableSAO
, "sao");
1233 BOOL(p
->bSaoNonDeblocked
, "sao-non-deblock");
1234 BOOL(p
->bBPyramid
, "b-pyramid");
1235 BOOL(p
->rc
.cuTree
, "cutree");
1236 s
+= sprintf(s
, " rc=%s", p
->rc
.rateControlMode
== X265_RC_ABR
? (
1237 p
->rc
.bStatRead
? "2 pass" : p
->rc
.bitrate
== p
->rc
.vbvMaxBitrate
? "cbr" : "abr")
1238 : p
->rc
.rateControlMode
== X265_RC_CRF
? "crf" : "cqp");
1239 if (p
->rc
.rateControlMode
== X265_RC_ABR
|| p
->rc
.rateControlMode
== X265_RC_CRF
)
1241 if (p
->rc
.rateControlMode
== X265_RC_CRF
)
1242 s
+= sprintf(s
, " crf=%.1f", p
->rc
.rfConstant
);
1244 s
+= sprintf(s
, " bitrate=%d ratetol=%.1f",
1245 p
->rc
.bitrate
, p
->rc
.rateTolerance
);
1246 s
+= sprintf(s
, " qcomp=%.2f qpmin=%d qpmax=%d qpstep=%d",
1247 p
->rc
.qCompress
, QP_MIN
, QP_MAX_SPEC
, p
->rc
.qpStep
);
1248 if (p
->rc
.bStatRead
)
1249 s
+= sprintf( s
, " cplxblur=%.1f qblur=%.1f",
1250 p
->rc
.complexityBlur
, p
->rc
.qblur
);
1251 if (p
->rc
.vbvBufferSize
)
1253 s
+= sprintf(s
, " vbv-maxrate=%d vbv-bufsize=%d",
1254 p
->rc
.vbvMaxBitrate
, p
->rc
.vbvBufferSize
);
1255 if (p
->rc
.rateControlMode
== X265_RC_CRF
)
1256 s
+= sprintf(s
, " crf-max=%.1f", p
->rc
.rfConstantMax
);
1259 else if (p
->rc
.rateControlMode
== X265_RC_CQP
)
1260 s
+= sprintf(s
, " qp=%d", p
->rc
.qp
);
1261 if (!(p
->rc
.rateControlMode
== X265_RC_CQP
&& p
->rc
.qp
== 0))
1263 s
+= sprintf(s
, " ipratio=%.2f", p
->rc
.ipFactor
);
1265 s
+= sprintf(s
, " pbratio=%.2f", p
->rc
.pbFactor
);
1271 bool parseLambdaFile(x265_param
*param
)
1273 if (!param
->rc
.lambdaFileName
)
1276 FILE *lfn
= fopen(param
->rc
.lambdaFileName
, "r");
1279 x265_log(param
, X265_LOG_ERROR
, "unable to read lambda file <%s>\n", param
->rc
.lambdaFileName
);
1284 char *toksave
= NULL
, *tok
= NULL
, *buf
= NULL
;
1286 for (int t
= 0; t
< 3; t
++)
1288 double *table
= t
? x265_lambda2_tab
: x265_lambda_tab
;
1290 for (int i
= 0; i
< QP_MAX_MAX
+ 1; i
++)
1298 /* consume a line of text file */
1299 if (!fgets(line
, sizeof(line
), lfn
))
1305 x265_log(param
, X265_LOG_ERROR
, "lambda file is incomplete\n");
1312 /* truncate at first hash */
1313 char *hash
= strchr(line
, '#');
1314 if (hash
) *hash
= 0;
1318 tok
= strtok_r(buf
, " ,", &toksave
);
1320 if (tok
&& sscanf(tok
, "%lf", &value
) == 1)
1327 x265_log(param
, X265_LOG_ERROR
, "lambda file contains too many values\n");
1332 x265_log(param
, X265_LOG_DEBUG
, "lambda%c[%d] = %lf\n", t
? '2' : ' ', i
, value
);