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
->analysisMode
= 0;
180 param
->analysisFileName
= NULL
;
181 param
->bIntraInBFrames
= 0;
182 param
->bLossless
= 0;
183 param
->bCULossless
= 0;
185 /* Rate control options */
186 param
->rc
.vbvMaxBitrate
= 0;
187 param
->rc
.vbvBufferSize
= 0;
188 param
->rc
.vbvBufferInit
= 0.9;
189 param
->rc
.rfConstant
= 28;
190 param
->rc
.bitrate
= 0;
191 param
->rc
.rateTolerance
= 1.0;
192 param
->rc
.qCompress
= 0.6;
193 param
->rc
.ipFactor
= 1.4f
;
194 param
->rc
.pbFactor
= 1.3f
;
195 param
->rc
.qpStep
= 4;
196 param
->rc
.rateControlMode
= X265_RC_CRF
;
198 param
->rc
.aqMode
= X265_AQ_VARIANCE
;
199 param
->rc
.aqStrength
= 1.0;
200 param
->rc
.cuTree
= 1;
201 param
->rc
.rfConstantMax
= 0;
202 param
->rc
.rfConstantMin
= 0;
203 param
->rc
.bStatRead
= 0;
204 param
->rc
.bStatWrite
= 0;
205 param
->rc
.statFileName
= NULL
;
206 param
->rc
.complexityBlur
= 20;
207 param
->rc
.qblur
= 0.5;
208 param
->rc
.bEnableSlowFirstPass
= 0;
210 /* Video Usability Information (VUI) */
211 param
->vui
.aspectRatioIdc
= 0;
212 param
->vui
.sarWidth
= 0;
213 param
->vui
.sarHeight
= 0;
214 param
->vui
.bEnableOverscanAppropriateFlag
= 0;
215 param
->vui
.bEnableVideoSignalTypePresentFlag
= 0;
216 param
->vui
.videoFormat
= 5;
217 param
->vui
.bEnableVideoFullRangeFlag
= 0;
218 param
->vui
.bEnableColorDescriptionPresentFlag
= 0;
219 param
->vui
.colorPrimaries
= 2;
220 param
->vui
.transferCharacteristics
= 2;
221 param
->vui
.matrixCoeffs
= 2;
222 param
->vui
.bEnableChromaLocInfoPresentFlag
= 0;
223 param
->vui
.chromaSampleLocTypeTopField
= 0;
224 param
->vui
.chromaSampleLocTypeBottomField
= 0;
225 param
->vui
.bEnableDefaultDisplayWindowFlag
= 0;
226 param
->vui
.defDispWinLeftOffset
= 0;
227 param
->vui
.defDispWinRightOffset
= 0;
228 param
->vui
.defDispWinTopOffset
= 0;
229 param
->vui
.defDispWinBottomOffset
= 0;
233 int x265_param_default_preset(x265_param
*param
, const char *preset
, const char *tune
)
235 x265_param_default(param
);
240 int i
= strtol(preset
, &end
, 10);
241 if (*end
== 0 && i
>= 0 && i
< (int)(sizeof(x265_preset_names
) / sizeof(*x265_preset_names
) - 1))
242 preset
= x265_preset_names
[i
];
244 if (!strcmp(preset
, "ultrafast"))
246 param
->lookaheadDepth
= 10;
247 param
->scenecutThreshold
= 0; // disable lookahead
248 param
->maxCUSize
= 32;
249 param
->searchRange
= 25;
250 param
->bFrameAdaptive
= 0;
251 param
->subpelRefine
= 0;
252 param
->searchMethod
= X265_DIA_SEARCH
;
253 param
->bEnableEarlySkip
= 1;
254 param
->bEnableSAO
= 0;
255 param
->bEnableSignHiding
= 0;
256 param
->bEnableWeightedPred
= 0;
258 param
->maxNumReferences
= 1;
259 param
->bEnableLoopFilter
= 0;
260 param
->rc
.aqStrength
= 0.0;
261 param
->rc
.aqMode
= X265_AQ_NONE
;
262 param
->rc
.cuTree
= 0;
263 param
->bEnableFastIntra
= 1;
265 else if (!strcmp(preset
, "superfast"))
267 param
->lookaheadDepth
= 10;
268 param
->maxCUSize
= 32;
269 param
->searchRange
= 44;
270 param
->bFrameAdaptive
= 0;
271 param
->subpelRefine
= 1;
272 param
->bEnableEarlySkip
= 1;
273 param
->bEnableWeightedPred
= 0;
275 param
->maxNumReferences
= 1;
276 param
->rc
.aqStrength
= 0.0;
277 param
->rc
.aqMode
= X265_AQ_NONE
;
278 param
->rc
.cuTree
= 0;
279 param
->bEnableSAO
= 0;
280 param
->bEnableFastIntra
= 1;
282 else if (!strcmp(preset
, "veryfast"))
284 param
->lookaheadDepth
= 15;
285 param
->maxCUSize
= 32;
286 param
->bFrameAdaptive
= 0;
287 param
->subpelRefine
= 1;
288 param
->bEnableEarlySkip
= 1;
290 param
->maxNumReferences
= 1;
291 param
->rc
.cuTree
= 0;
292 param
->bEnableFastIntra
= 1;
294 else if (!strcmp(preset
, "faster"))
296 param
->lookaheadDepth
= 15;
297 param
->bFrameAdaptive
= 0;
298 param
->bEnableEarlySkip
= 1;
300 param
->maxNumReferences
= 1;
301 param
->rc
.cuTree
= 0;
302 param
->bEnableFastIntra
= 1;
304 else if (!strcmp(preset
, "fast"))
306 param
->lookaheadDepth
= 15;
307 param
->bFrameAdaptive
= 0;
309 param
->maxNumReferences
= 2;
310 param
->bEnableFastIntra
= 1;
312 else if (!strcmp(preset
, "medium"))
316 else if (!strcmp(preset
, "slow"))
318 param
->bEnableRectInter
= 1;
319 param
->lookaheadDepth
= 25;
321 param
->subpelRefine
= 3;
322 param
->maxNumMergeCand
= 3;
323 param
->searchMethod
= X265_STAR_SEARCH
;
325 else if (!strcmp(preset
, "slower"))
327 param
->bEnableWeightedBiPred
= 1;
328 param
->bEnableAMP
= 1;
329 param
->bEnableRectInter
= 1;
330 param
->lookaheadDepth
= 30;
332 param
->tuQTMaxInterDepth
= 2;
333 param
->tuQTMaxIntraDepth
= 2;
335 param
->subpelRefine
= 3;
336 param
->maxNumMergeCand
= 3;
337 param
->searchMethod
= X265_STAR_SEARCH
;
338 param
->bIntraInBFrames
= 1;
340 else if (!strcmp(preset
, "veryslow"))
342 param
->bEnableWeightedBiPred
= 1;
343 param
->bEnableAMP
= 1;
344 param
->bEnableRectInter
= 1;
345 param
->lookaheadDepth
= 40;
347 param
->tuQTMaxInterDepth
= 3;
348 param
->tuQTMaxIntraDepth
= 3;
350 param
->subpelRefine
= 4;
351 param
->maxNumMergeCand
= 4;
352 param
->searchMethod
= X265_STAR_SEARCH
;
353 param
->maxNumReferences
= 5;
354 param
->bIntraInBFrames
= 1;
356 else if (!strcmp(preset
, "placebo"))
358 param
->bEnableWeightedBiPred
= 1;
359 param
->bEnableAMP
= 1;
360 param
->bEnableRectInter
= 1;
361 param
->lookaheadDepth
= 60;
362 param
->searchRange
= 92;
364 param
->tuQTMaxInterDepth
= 4;
365 param
->tuQTMaxIntraDepth
= 4;
367 param
->subpelRefine
= 5;
368 param
->maxNumMergeCand
= 5;
369 param
->searchMethod
= X265_STAR_SEARCH
;
370 param
->bEnableTransformSkip
= 1;
371 param
->maxNumReferences
= 5;
372 param
->rc
.bEnableSlowFirstPass
= 1;
373 param
->bIntraInBFrames
= 1;
374 // TODO: optimized esa
381 if (!strcmp(tune
, "psnr"))
383 param
->rc
.aqStrength
= 0.0;
385 param
->psyRdoq
= 0.0;
387 else if (!strcmp(tune
, "ssim"))
389 param
->rc
.aqMode
= X265_AQ_AUTO_VARIANCE
;
391 param
->psyRdoq
= 0.0;
393 else if (!strcmp(tune
, "fastdecode") ||
394 !strcmp(tune
, "fast-decode"))
396 param
->bEnableLoopFilter
= 0;
397 param
->bEnableSAO
= 0;
398 param
->bEnableWeightedPred
= 0;
399 param
->bEnableWeightedBiPred
= 0;
400 param
->bIntraInBFrames
= 0;
402 else if (!strcmp(tune
, "zerolatency") ||
403 !strcmp(tune
, "zero-latency"))
405 param
->bFrameAdaptive
= 0;
407 param
->lookaheadDepth
= 0;
408 param
->scenecutThreshold
= 0;
409 param
->rc
.cuTree
= 0;
411 else if (!strcmp(tune
, "grain"))
413 param
->deblockingFilterBetaOffset
= -2;
414 param
->deblockingFilterTCOffset
= -2;
415 param
->bIntraInBFrames
= 0;
418 param
->rc
.ipFactor
= 1.1;
419 param
->rc
.pbFactor
= 1.1;
420 param
->rc
.aqMode
= X265_AQ_VARIANCE
;
421 param
->rc
.aqStrength
= 0.3;
422 param
->rc
.qCompress
= 0.8;
424 else if (!strcmp(tune
, "cbr"))
426 param
->rc
.pbFactor
= 1.0;
427 param
->rc
.rateTolerance
= 0.5;
436 static int x265_atobool(const char *str
, bool& bError
)
438 if (!strcmp(str
, "1") ||
439 !strcmp(str
, "true") ||
442 if (!strcmp(str
, "0") ||
443 !strcmp(str
, "false") ||
450 static double x265_atof(const char *str
, bool& bError
)
453 double v
= strtod(str
, &end
);
455 if (end
== str
|| *end
!= '\0')
460 static int parseName(const char *arg
, const char * const * names
, bool& bError
)
462 for (int i
= 0; names
[i
]; i
++)
464 if (!strcmp(arg
, names
[i
]))
470 return x265_atoi(arg
, bError
);
473 /* internal versions of string-to-int with additional error checking */
476 #define atoi(str) x265_atoi(str, bError)
477 #define atof(str) x265_atof(str, bError)
478 #define atobool(str) (bNameWasBool = true, x265_atobool(str, bError))
481 int x265_param_parse(x265_param
*p
, const char *name
, const char *value
)
484 bool bNameWasBool
= false;
485 bool bValueWasNull
= !value
;
489 return X265_PARAM_BAD_NAME
;
491 // skip -- prefix if provided
492 if (name
[0] == '-' && name
[1] == '-')
496 if (strlen(name
) + 1 < sizeof(nameBuf
) && strchr(name
, '_'))
499 strcpy(nameBuf
, name
);
500 while ((c
= strchr(nameBuf
, '_')) != 0)
508 if (!strncmp(name
, "no-", 3))
511 value
= !value
|| x265_atobool(value
, bError
) ? "false" : "true";
513 else if (!strncmp(name
, "no", 2))
516 value
= !value
|| x265_atobool(value
, bError
) ? "false" : "true";
520 else if (value
[0] == '=')
523 #if defined(_MSC_VER)
524 #pragma warning(disable: 4127) // conditional expression is constant
526 #define OPT(STR) else if (!strcmp(name, STR))
527 #define OPT2(STR1, STR2) else if (!strcmp(name, STR1) || !strcmp(name, STR2))
532 p
->cpuid
= atobool(value
);
534 p
->cpuid
= parseCpuName(value
, bError
);
538 if (sscanf(value
, "%u/%u", &p
->fpsNum
, &p
->fpsDenom
) == 2)
542 float fps
= (float)atof(value
);
543 if (fps
> 0 && fps
<= INT_MAX
/ 1000)
545 p
->fpsNum
= (int)(fps
* 1000 + .5);
550 p
->fpsNum
= atoi(value
);
555 OPT("threads") p
->poolNumThreads
= atoi(value
);
556 OPT("frame-threads") p
->frameNumThreads
= atoi(value
);
557 OPT("pmode") p
->bDistributeModeAnalysis
= atobool(value
);
558 OPT("pme") p
->bDistributeMotionEstimation
= atobool(value
);
559 OPT2("level-idc", "level")
561 /* allow "5.1" or "51", both converted to integer 51 */
563 p
->levelIdc
= (int)(10 * atof(value
) + .5);
565 p
->levelIdc
= atoi(value
);
567 OPT("high-tier") p
->bHighTier
= atobool(value
);
568 OPT2("log-level", "log")
570 p
->logLevel
= atoi(value
);
574 p
->logLevel
= parseName(value
, logLevelNames
, bError
) - 1;
577 OPT("cu-stats") p
->bLogCuStats
= atobool(value
);
578 OPT("repeat-headers") p
->bRepeatHeaders
= atobool(value
);
579 OPT("wpp") p
->bEnableWavefront
= atobool(value
);
580 OPT("ctu") p
->maxCUSize
= (uint32_t)atoi(value
);
581 OPT("tu-intra-depth") p
->tuQTMaxIntraDepth
= (uint32_t)atoi(value
);
582 OPT("tu-inter-depth") p
->tuQTMaxInterDepth
= (uint32_t)atoi(value
);
583 OPT("subme") p
->subpelRefine
= atoi(value
);
584 OPT("merange") p
->searchRange
= atoi(value
);
585 OPT("rect") p
->bEnableRectInter
= atobool(value
);
586 OPT("amp") p
->bEnableAMP
= atobool(value
);
587 OPT("max-merge") p
->maxNumMergeCand
= (uint32_t)atoi(value
);
588 OPT("temporal-mvp") p
->bEnableTemporalMvp
= atobool(value
);
589 OPT("early-skip") p
->bEnableEarlySkip
= atobool(value
);
590 OPT("fast-cbf") p
->bEnableCbfFastMode
= atobool(value
);
591 OPT("rdpenalty") p
->rdPenalty
= atoi(value
);
592 OPT("tskip") p
->bEnableTransformSkip
= atobool(value
);
593 OPT("no-tskip-fast") p
->bEnableTSkipFast
= atobool(value
);
594 OPT("tskip-fast") p
->bEnableTSkipFast
= atobool(value
);
595 OPT("strong-intra-smoothing") p
->bEnableStrongIntraSmoothing
= atobool(value
);
596 OPT("lossless") p
->bLossless
= atobool(value
);
597 OPT("cu-lossless") p
->bCULossless
= atobool(value
);
598 OPT("constrained-intra") p
->bEnableConstrainedIntra
= atobool(value
);
599 OPT("fast-intra") p
->bEnableFastIntra
= atobool(value
);
600 OPT("open-gop") p
->bOpenGOP
= atobool(value
);
603 p
->scenecutThreshold
= atobool(value
);
604 if (bError
|| p
->scenecutThreshold
)
607 p
->scenecutThreshold
= atoi(value
);
610 OPT("keyint") p
->keyframeMax
= atoi(value
);
611 OPT("min-keyint") p
->keyframeMin
= atoi(value
);
612 OPT("rc-lookahead") p
->lookaheadDepth
= atoi(value
);
613 OPT("bframes") p
->bframes
= atoi(value
);
614 OPT("bframe-bias") p
->bFrameBias
= atoi(value
);
617 p
->bFrameAdaptive
= atobool(value
);
618 if (bError
|| p
->bFrameAdaptive
)
621 p
->bFrameAdaptive
= atoi(value
);
626 p
->interlaceMode
= atobool(value
);
627 if (bError
|| p
->interlaceMode
)
630 p
->interlaceMode
= parseName(value
, x265_interlace_names
, bError
);
633 OPT("ref") p
->maxNumReferences
= atoi(value
);
634 OPT("weightp") p
->bEnableWeightedPred
= atobool(value
);
635 OPT("weightb") p
->bEnableWeightedBiPred
= atobool(value
);
636 OPT("cbqpoffs") p
->cbQpOffset
= atoi(value
);
637 OPT("crqpoffs") p
->crQpOffset
= atoi(value
);
638 OPT("rd") p
->rdLevel
= atoi(value
);
639 OPT("psy-rd") p
->psyRd
= atof(value
);
640 OPT("psy-rdoq") p
->psyRdoq
= atof(value
);
641 OPT("signhide") p
->bEnableSignHiding
= atobool(value
);
642 OPT("b-intra") p
->bIntraInBFrames
= atobool(value
);
643 OPT("lft") p
->bEnableLoopFilter
= atobool(value
); /* DEPRECATED */
646 if (2 == sscanf(value
, "%d:%d", &p
->deblockingFilterTCOffset
, &p
->deblockingFilterBetaOffset
) ||
647 2 == sscanf(value
, "%d,%d", &p
->deblockingFilterTCOffset
, &p
->deblockingFilterBetaOffset
))
649 p
->bEnableLoopFilter
= true;
651 else if (sscanf(value
, "%d", &p
->deblockingFilterTCOffset
))
653 p
->bEnableLoopFilter
= 1;
654 p
->deblockingFilterBetaOffset
= p
->deblockingFilterTCOffset
;
657 p
->bEnableLoopFilter
= atobool(value
);
659 OPT("sao") p
->bEnableSAO
= atobool(value
);
660 OPT("sao-non-deblock") p
->bSaoNonDeblocked
= atobool(value
);
661 OPT("ssim") p
->bEnableSsim
= atobool(value
);
662 OPT("psnr") p
->bEnablePsnr
= atobool(value
);
663 OPT("hash") p
->decodedPictureHashSEI
= atoi(value
);
664 OPT("aud") p
->bEnableAccessUnitDelimiters
= atobool(value
);
665 OPT("info") p
->bEmitInfoSEI
= atobool(value
);
666 OPT("b-pyramid") p
->bBPyramid
= atobool(value
);
667 OPT("hrd") p
->bEmitHRDSEI
= atobool(value
);
668 OPT2("ipratio", "ip-factor") p
->rc
.ipFactor
= atof(value
);
669 OPT2("pbratio", "pb-factor") p
->rc
.pbFactor
= atof(value
);
670 OPT("qcomp") p
->rc
.qCompress
= atof(value
);
671 OPT("qpstep") p
->rc
.qpStep
= atoi(value
);
672 OPT("ratetol") p
->rc
.rateTolerance
= atof(value
);
673 OPT("cplxblur") p
->rc
.complexityBlur
= atof(value
);
674 OPT("qblur") p
->rc
.qblur
= atof(value
);
675 OPT("aq-mode") p
->rc
.aqMode
= atoi(value
);
676 OPT("aq-strength") p
->rc
.aqStrength
= atof(value
);
677 OPT("vbv-maxrate") p
->rc
.vbvMaxBitrate
= atoi(value
);
678 OPT("vbv-bufsize") p
->rc
.vbvBufferSize
= atoi(value
);
679 OPT("vbv-init") p
->rc
.vbvBufferInit
= atof(value
);
680 OPT("crf-max") p
->rc
.rfConstantMax
= atof(value
);
681 OPT("crf-min") p
->rc
.rfConstantMin
= atof(value
);
684 p
->rc
.rfConstant
= atof(value
);
685 p
->rc
.rateControlMode
= X265_RC_CRF
;
689 p
->rc
.bitrate
= atoi(value
);
690 p
->rc
.rateControlMode
= X265_RC_ABR
;
694 p
->rc
.qp
= atoi(value
);
695 p
->rc
.rateControlMode
= X265_RC_CQP
;
697 OPT("input-res") bError
|= sscanf(value
, "%dx%d", &p
->sourceWidth
, &p
->sourceHeight
) != 2;
698 OPT("input-csp") p
->internalCsp
= parseName(value
, x265_source_csp_names
, bError
);
699 OPT("me") p
->searchMethod
= parseName(value
, x265_motion_est_names
, bError
);
700 OPT("cutree") p
->rc
.cuTree
= atobool(value
);
701 OPT("slow-firstpass") p
->rc
.bEnableSlowFirstPass
= atobool(value
);
702 OPT("analysis-mode") p
->analysisMode
= parseName(value
, x265_analysis_names
, bError
);
705 p
->vui
.aspectRatioIdc
= parseName(value
, x265_sar_names
, bError
);
708 p
->vui
.aspectRatioIdc
= X265_EXTENDED_SAR
;
709 bError
= sscanf(value
, "%d:%d", &p
->vui
.sarWidth
, &p
->vui
.sarHeight
) != 2;
714 if (!strcmp(value
, "show"))
715 p
->vui
.bEnableOverscanInfoPresentFlag
= 1;
716 else if (!strcmp(value
, "crop"))
718 p
->vui
.bEnableOverscanInfoPresentFlag
= 1;
719 p
->vui
.bEnableOverscanAppropriateFlag
= 1;
721 else if (!strcmp(value
, "undef"))
722 p
->vui
.bEnableOverscanInfoPresentFlag
= 0;
728 p
->vui
.bEnableVideoSignalTypePresentFlag
= 1;
729 p
->vui
.videoFormat
= parseName(value
, x265_video_format_names
, bError
);
733 p
->vui
.bEnableVideoSignalTypePresentFlag
= 1;
734 p
->vui
.bEnableVideoFullRangeFlag
= parseName(value
, x265_fullrange_names
, bError
);
738 p
->vui
.bEnableVideoSignalTypePresentFlag
= 1;
739 p
->vui
.bEnableColorDescriptionPresentFlag
= 1;
740 p
->vui
.colorPrimaries
= parseName(value
, x265_colorprim_names
, bError
);
744 p
->vui
.bEnableVideoSignalTypePresentFlag
= 1;
745 p
->vui
.bEnableColorDescriptionPresentFlag
= 1;
746 p
->vui
.transferCharacteristics
= parseName(value
, x265_transfer_names
, bError
);
750 p
->vui
.bEnableVideoSignalTypePresentFlag
= 1;
751 p
->vui
.bEnableColorDescriptionPresentFlag
= 1;
752 p
->vui
.matrixCoeffs
= parseName(value
, x265_colmatrix_names
, bError
);
756 p
->vui
.bEnableChromaLocInfoPresentFlag
= 1;
757 p
->vui
.chromaSampleLocTypeTopField
= atoi(value
);
758 p
->vui
.chromaSampleLocTypeBottomField
= p
->vui
.chromaSampleLocTypeTopField
;
762 p
->vui
.bEnableDefaultDisplayWindowFlag
= 1;
763 bError
|= sscanf(value
, "%d,%d,%d,%d",
764 &p
->vui
.defDispWinLeftOffset
,
765 &p
->vui
.defDispWinTopOffset
,
766 &p
->vui
.defDispWinRightOffset
,
767 &p
->vui
.defDispWinBottomOffset
) != 4;
769 OPT("nr-intra") p
->noiseReductionIntra
= atoi(value
);
770 OPT("nr-inter") p
->noiseReductionInter
= atoi(value
);
773 int pass
= Clip3(0, 3, atoi(value
));
774 p
->rc
.bStatWrite
= pass
& 1;
775 p
->rc
.bStatRead
= pass
& 2;
777 OPT("stats") p
->rc
.statFileName
= strdup(value
);
778 OPT("csv") p
->csvfn
= strdup(value
);
779 OPT("scaling-list") p
->scalingLists
= strdup(value
);
780 OPT("lambda-file") p
->rc
.lambdaFileName
= strdup(value
);
781 OPT("analysis-file") p
->analysisFileName
= strdup(value
);
783 return X265_PARAM_BAD_NAME
;
789 bError
|= bValueWasNull
&& !bNameWasBool
;
790 return bError
? X265_PARAM_BAD_VALUE
: 0;
794 // internal encoder functions
796 int x265_atoi(const char *str
, bool& bError
)
799 int v
= strtol(str
, &end
, 0);
801 if (end
== str
|| *end
!= '\0')
807 * auto || true - x265::cpu_detect()
808 * false || no - disabled
809 * integer bitmap value
810 * comma separated list of SIMD names, eg: SSE4.1,XOP */
811 int parseCpuName(const char *value
, bool& bError
)
819 if (isdigit(value
[0]))
820 cpu
= x265_atoi(value
, bError
);
822 cpu
= !strcmp(value
, "auto") || x265_atobool(value
, bError
) ? x265::cpu_detect() : 0;
826 char *buf
= strdup(value
);
827 char *tok
, *saveptr
= NULL
, *init
;
830 for (init
= buf
; (tok
= strtok_r(init
, ",", &saveptr
)); init
= NULL
)
833 for (i
= 0; x265::cpu_names
[i
].flags
&& strcasecmp(tok
, x265::cpu_names
[i
].name
); i
++)
837 cpu
|= x265::cpu_names
[i
].flags
;
838 if (!x265::cpu_names
[i
].flags
)
843 if ((cpu
& X265_CPU_SSSE3
) && !(cpu
& X265_CPU_SSE2_IS_SLOW
))
844 cpu
|= X265_CPU_SSE2_IS_FAST
;
850 static const int fixedRatios
[][2] =
870 void setParamAspectRatio(x265_param
*p
, int width
, int height
)
872 p
->vui
.aspectRatioIdc
= X265_EXTENDED_SAR
;
873 p
->vui
.sarWidth
= width
;
874 p
->vui
.sarHeight
= height
;
875 for (size_t i
= 0; i
< sizeof(fixedRatios
) / sizeof(fixedRatios
[0]); i
++)
877 if (width
== fixedRatios
[i
][0] && height
== fixedRatios
[i
][1])
879 p
->vui
.aspectRatioIdc
= (int)i
+ 1;
885 void getParamAspectRatio(x265_param
*p
, int& width
, int& height
)
887 if (!p
->vui
.aspectRatioIdc
)
891 else if ((size_t)p
->vui
.aspectRatioIdc
<= sizeof(fixedRatios
) / sizeof(fixedRatios
[0]))
893 width
= fixedRatios
[p
->vui
.aspectRatioIdc
- 1][0];
894 height
= fixedRatios
[p
->vui
.aspectRatioIdc
- 1][1];
896 else if (p
->vui
.aspectRatioIdc
== X265_EXTENDED_SAR
)
898 width
= p
->vui
.sarWidth
;
899 height
= p
->vui
.sarHeight
;
907 static inline int _confirm(x265_param
*param
, bool bflag
, const char* message
)
912 x265_log(param
, X265_LOG_ERROR
, "%s\n", message
);
916 int x265_check_params(x265_param
*param
)
918 #define CHECK(expr, msg) check_failed |= _confirm(param, expr, msg)
919 int check_failed
= 0; /* abort if there is a fatal configuration problem */
921 CHECK(param
->maxCUSize
!= 64 && param
->maxCUSize
!= 32 && param
->maxCUSize
!= 16,
922 "max ctu size must be 16, 32, or 64");
923 if (check_failed
== 1)
926 uint32_t maxLog2CUSize
= (uint32_t)g_log2Size
[param
->maxCUSize
];
927 uint32_t tuQTMaxLog2Size
= X265_MIN(maxLog2CUSize
, 5);
928 uint32_t tuQTMinLog2Size
= 2; //log2(4)
930 /* These checks might be temporary */
932 CHECK(param
->internalBitDepth
!= 10,
933 "x265 was compiled for 10bit encodes, only 10bit internal depth supported");
935 CHECK(param
->internalBitDepth
!= 8,
936 "x265 was compiled for 8bit encodes, only 8bit internal depth supported");
939 CHECK(param
->rc
.qp
< -6 * (param
->internalBitDepth
- 8) || param
->rc
.qp
> 51,
940 "QP exceeds supported range (-QpBDOffsety to 51)");
941 CHECK(param
->fpsNum
== 0 || param
->fpsDenom
== 0,
942 "Frame rate numerator and denominator must be specified");
943 CHECK(param
->interlaceMode
< 0 || param
->interlaceMode
> 2,
944 "Interlace mode must be 0 (progressive) 1 (top-field first) or 2 (bottom field first)");
945 CHECK(param
->searchMethod
<0 || param
->searchMethod
> X265_FULL_SEARCH
,
946 "Search method is not supported value (0:DIA 1:HEX 2:UMH 3:HM 5:FULL)");
947 CHECK(param
->searchRange
< 0,
948 "Search Range must be more than 0");
949 CHECK(param
->searchRange
>= 32768,
950 "Search Range must be less than 32768");
951 CHECK(param
->subpelRefine
> X265_MAX_SUBPEL_LEVEL
,
952 "subme must be less than or equal to X265_MAX_SUBPEL_LEVEL (7)");
953 CHECK(param
->subpelRefine
< 0,
954 "subme must be greater than or equal to 0");
955 CHECK(param
->frameNumThreads
< 0,
956 "frameNumThreads (--frame-threads) must be 0 or higher");
957 CHECK(param
->cbQpOffset
< -12, "Min. Chroma Cb QP Offset is -12");
958 CHECK(param
->cbQpOffset
> 12, "Max. Chroma Cb QP Offset is 12");
959 CHECK(param
->crQpOffset
< -12, "Min. Chroma Cr QP Offset is -12");
960 CHECK(param
->crQpOffset
> 12, "Max. Chroma Cr QP Offset is 12");
962 CHECK(tuQTMaxLog2Size
> maxLog2CUSize
,
963 "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");
965 CHECK(param
->tuQTMaxInterDepth
< 1 || param
->tuQTMaxInterDepth
> 4,
966 "QuadtreeTUMaxDepthInter must be greater than 0 and less than 5");
967 CHECK(maxLog2CUSize
< tuQTMinLog2Size
+ param
->tuQTMaxInterDepth
- 1,
968 "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1");
969 CHECK(param
->tuQTMaxIntraDepth
< 1 || param
->tuQTMaxIntraDepth
> 4,
970 "QuadtreeTUMaxDepthIntra must be greater 0 and less than 5");
971 CHECK(maxLog2CUSize
< tuQTMinLog2Size
+ param
->tuQTMaxIntraDepth
- 1,
972 "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1");
974 CHECK(param
->maxNumMergeCand
< 1, "MaxNumMergeCand must be 1 or greater.");
975 CHECK(param
->maxNumMergeCand
> 5, "MaxNumMergeCand must be 5 or smaller.");
977 CHECK(param
->maxNumReferences
< 1, "maxNumReferences must be 1 or greater.");
978 CHECK(param
->maxNumReferences
> MAX_NUM_REF
, "maxNumReferences must be 16 or smaller.");
980 CHECK(param
->sourceWidth
< (int)param
->maxCUSize
|| param
->sourceHeight
< (int)param
->maxCUSize
,
981 "Picture size must be at least one CTU");
982 CHECK(param
->internalCsp
< X265_CSP_I420
|| X265_CSP_I444
< param
->internalCsp
,
983 "Color space must be i420, i422, or i444");
984 CHECK(param
->sourceWidth
& !!CHROMA_H_SHIFT(param
->internalCsp
),
985 "Picture width must be an integer multiple of the specified chroma subsampling");
986 CHECK(param
->sourceHeight
& !!CHROMA_V_SHIFT(param
->internalCsp
),
987 "Picture height must be an integer multiple of the specified chroma subsampling");
989 CHECK(param
->rc
.rateControlMode
> X265_RC_CRF
|| param
->rc
.rateControlMode
< X265_RC_ABR
,
990 "Rate control mode is out of range");
991 CHECK(param
->rdLevel
< 0 || param
->rdLevel
> 6,
992 "RD Level is out of range");
993 CHECK(param
->bframes
> param
->lookaheadDepth
&& !param
->rc
.bStatRead
,
994 "Lookahead depth must be greater than the max consecutive bframe count");
995 CHECK(param
->bframes
< 0,
996 "bframe count should be greater than zero");
997 CHECK(param
->bframes
> X265_BFRAME_MAX
,
998 "max consecutive bframe count must be 16 or smaller");
999 CHECK(param
->lookaheadDepth
> X265_LOOKAHEAD_MAX
,
1000 "Lookahead depth must be less than 256");
1001 CHECK(param
->rc
.aqMode
< X265_AQ_NONE
|| X265_AQ_AUTO_VARIANCE
< param
->rc
.aqMode
,
1002 "Aq-Mode is out of range");
1003 CHECK(param
->rc
.aqStrength
< 0 || param
->rc
.aqStrength
> 3,
1004 "Aq-Strength is out of range");
1005 CHECK(param
->deblockingFilterTCOffset
< -6 || param
->deblockingFilterTCOffset
> 6,
1006 "deblocking filter tC offset must be in the range of -6 to +6");
1007 CHECK(param
->deblockingFilterBetaOffset
< -6 || param
->deblockingFilterBetaOffset
> 6,
1008 "deblocking filter Beta offset must be in the range of -6 to +6");
1009 CHECK(param
->psyRd
< 0 || 2.0 < param
->psyRd
, "Psy-rd strength must be between 0 and 2.0");
1010 CHECK(param
->psyRdoq
< 0 || 50.0 < param
->psyRdoq
, "Psy-rdoq strength must be between 0 and 50.0");
1011 CHECK(param
->bEnableWavefront
< 0, "WaveFrontSynchro cannot be negative");
1012 CHECK(!param
->bEnableWavefront
&& param
->rc
.vbvBufferSize
, "VBV requires wave-front parallelism (--wpp)");
1013 CHECK((param
->vui
.aspectRatioIdc
< 0
1014 || param
->vui
.aspectRatioIdc
> 16)
1015 && param
->vui
.aspectRatioIdc
!= X265_EXTENDED_SAR
,
1016 "Sample Aspect Ratio must be 0-16 or 255");
1017 CHECK(param
->vui
.aspectRatioIdc
== X265_EXTENDED_SAR
&& param
->vui
.sarWidth
<= 0,
1018 "Sample Aspect Ratio width must be greater than 0");
1019 CHECK(param
->vui
.aspectRatioIdc
== X265_EXTENDED_SAR
&& param
->vui
.sarHeight
<= 0,
1020 "Sample Aspect Ratio height must be greater than 0");
1021 CHECK(param
->vui
.videoFormat
< 0 || param
->vui
.videoFormat
> 5,
1022 "Video Format must be component,"
1023 " pal, ntsc, secam, mac or undef");
1024 CHECK(param
->vui
.colorPrimaries
< 0
1025 || param
->vui
.colorPrimaries
> 9
1026 || param
->vui
.colorPrimaries
== 3,
1027 "Color Primaries must be undef, bt709, bt470m,"
1028 " bt470bg, smpte170m, smpte240m, film or bt2020");
1029 CHECK(param
->vui
.transferCharacteristics
< 0
1030 || param
->vui
.transferCharacteristics
> 15
1031 || param
->vui
.transferCharacteristics
== 3,
1032 "Transfer Characteristics must be undef, bt709, bt470m, bt470bg,"
1033 " smpte170m, smpte240m, linear, log100, log316, iec61966-2-4, bt1361e,"
1034 " iec61966-2-1, bt2020-10 or bt2020-12");
1035 CHECK(param
->vui
.matrixCoeffs
< 0
1036 || param
->vui
.matrixCoeffs
> 10
1037 || param
->vui
.matrixCoeffs
== 3,
1038 "Matrix Coefficients must be undef, bt709, fcc, bt470bg, smpte170m,"
1039 " smpte240m, GBR, YCgCo, bt2020nc or bt2020c");
1040 CHECK(param
->vui
.chromaSampleLocTypeTopField
< 0
1041 || param
->vui
.chromaSampleLocTypeTopField
> 5,
1042 "Chroma Sample Location Type Top Field must be 0-5");
1043 CHECK(param
->vui
.chromaSampleLocTypeBottomField
< 0
1044 || param
->vui
.chromaSampleLocTypeBottomField
> 5,
1045 "Chroma Sample Location Type Bottom Field must be 0-5");
1046 CHECK(param
->vui
.defDispWinLeftOffset
< 0,
1047 "Default Display Window Left Offset must be 0 or greater");
1048 CHECK(param
->vui
.defDispWinRightOffset
< 0,
1049 "Default Display Window Right Offset must be 0 or greater");
1050 CHECK(param
->vui
.defDispWinTopOffset
< 0,
1051 "Default Display Window Top Offset must be 0 or greater");
1052 CHECK(param
->vui
.defDispWinBottomOffset
< 0,
1053 "Default Display Window Bottom Offset must be 0 or greater");
1054 CHECK(param
->rc
.rfConstant
< -6 * (param
->internalBitDepth
- 8) || param
->rc
.rfConstant
> 51,
1055 "Valid quality based range: -qpBDOffsetY to 51");
1056 CHECK(param
->rc
.rfConstantMax
< -6 * (param
->internalBitDepth
- 8) || param
->rc
.rfConstantMax
> 51,
1057 "Valid quality based range: -qpBDOffsetY to 51");
1058 CHECK(param
->rc
.rfConstantMin
< -6 * (param
->internalBitDepth
- 8) || param
->rc
.rfConstantMin
> 51,
1059 "Valid quality based range: -qpBDOffsetY to 51");
1060 CHECK(param
->bFrameAdaptive
< 0 || param
->bFrameAdaptive
> 2,
1061 "Valid adaptive b scheduling values 0 - none, 1 - fast, 2 - full");
1062 CHECK(param
->logLevel
<-1 || param
->logLevel
> X265_LOG_FULL
,
1063 "Valid Logging level -1:none 0:error 1:warning 2:info 3:debug 4:full");
1064 CHECK(param
->scenecutThreshold
< 0,
1065 "scenecutThreshold must be greater than 0");
1066 CHECK(param
->rdPenalty
< 0 || param
->rdPenalty
> 2,
1067 "Valid penalty for 32x32 intra TU in non-I slices. 0:disabled 1:RD-penalty 2:maximum");
1068 CHECK(param
->keyframeMax
< -1,
1069 "Invalid max IDR period in frames. value should be greater than -1");
1070 CHECK(param
->decodedPictureHashSEI
< 0 || param
->decodedPictureHashSEI
> 3,
1071 "Invalid hash option. Decoded Picture Hash SEI 0: disabled, 1: MD5, 2: CRC, 3: Checksum");
1072 CHECK(param
->rc
.vbvBufferSize
< 0,
1073 "Size of the vbv buffer can not be less than zero");
1074 CHECK(param
->rc
.vbvMaxBitrate
< 0,
1075 "Maximum local bit rate can not be less than zero");
1076 CHECK(param
->rc
.vbvBufferInit
< 0,
1077 "Valid initial VBV buffer occupancy must be a fraction 0 - 1, or size in kbits");
1078 CHECK(param
->rc
.bitrate
< 0,
1079 "Target bitrate can not be less than zero");
1080 CHECK(param
->rc
.qCompress
< 0.5 || param
->rc
.qCompress
> 1.0,
1081 "qCompress must be between 0.5 and 1.0");
1082 if (param
->noiseReductionIntra
)
1083 CHECK(0 > param
->noiseReductionIntra
|| param
->noiseReductionIntra
> 2000, "Valid noise reduction range 0 - 2000");
1084 if (param
->noiseReductionInter
)
1085 CHECK(0 > param
->noiseReductionInter
|| param
->noiseReductionInter
> 2000, "Valid noise reduction range 0 - 2000");
1086 CHECK(param
->rc
.rateControlMode
== X265_RC_CRF
&& param
->rc
.bStatRead
,
1087 "Constant rate-factor is incompatible with 2pass");
1088 CHECK(param
->rc
.rateControlMode
== X265_RC_CQP
&& param
->rc
.bStatRead
,
1089 "Constant QP is incompatible with 2pass");
1090 return check_failed
;
1093 void x265_param_apply_fastfirstpass(x265_param
* param
)
1095 /* Set faster options in case of turbo firstpass */
1096 if (param
->rc
.bStatWrite
&& !param
->rc
.bStatRead
)
1098 param
->maxNumReferences
= 1;
1099 param
->maxNumMergeCand
= 1;
1100 param
->bEnableRectInter
= 0;
1101 param
->bEnableFastIntra
= 1;
1102 param
->bEnableAMP
= 0;
1103 param
->searchMethod
= X265_DIA_SEARCH
;
1104 param
->subpelRefine
= X265_MIN(2, param
->subpelRefine
);
1105 param
->bEnableEarlySkip
= 1;
1106 param
->rdLevel
= X265_MIN(2, param
->rdLevel
);
1110 int x265_set_globals(x265_param
*param
)
1112 static int once
/* = 0 */;
1114 if (ATOMIC_INC(&once
) > 1)
1116 if (param
->maxCUSize
!= g_maxCUSize
)
1118 x265_log(param
, X265_LOG_ERROR
, "maxCUSize must be the same for all encoders in a single process");
1124 uint32_t maxLog2CUSize
= (uint32_t)g_log2Size
[param
->maxCUSize
];
1126 // set max CU width & height
1127 g_maxCUSize
= param
->maxCUSize
;
1128 g_maxLog2CUSize
= maxLog2CUSize
;
1130 // compute actual CU depth with respect to config depth and max transform size
1131 g_maxCUDepth
= maxLog2CUSize
- MIN_LOG2_CU_SIZE
;
1132 g_maxFullDepth
= maxLog2CUSize
- LOG2_UNIT_SIZE
;
1134 // initialize partition order
1135 uint32_t* tmp
= &g_zscanToRaster
[0];
1136 initZscanToRaster(g_maxFullDepth
, 1, 0, tmp
);
1137 initRasterToZscan(g_maxFullDepth
);
1142 void x265_print_params(x265_param
*param
)
1144 if (param
->logLevel
< X265_LOG_INFO
)
1148 x265_log(param
, X265_LOG_INFO
, "Internal bit depth : %d\n", param
->internalBitDepth
);
1150 if (param
->interlaceMode
)
1151 x265_log(param
, X265_LOG_INFO
, "Interlaced field inputs : %s\n", x265_interlace_names
[param
->interlaceMode
]);
1153 x265_log(param
, X265_LOG_INFO
, "CTU size / RQT depth inter / intra : %d / %d / %d\n",
1154 param
->maxCUSize
, param
->tuQTMaxInterDepth
, param
->tuQTMaxIntraDepth
);
1156 x265_log(param
, X265_LOG_INFO
, "ME / range / subpel / merge : %s / %d / %d / %d\n",
1157 x265_motion_est_names
[param
->searchMethod
], param
->searchRange
, param
->subpelRefine
, param
->maxNumMergeCand
);
1159 if (param
->keyframeMax
!= INT_MAX
|| param
->scenecutThreshold
)
1160 x265_log(param
, X265_LOG_INFO
, "Keyframe min / max / scenecut : %d / %d / %d\n", param
->keyframeMin
, param
->keyframeMax
, param
->scenecutThreshold
);
1162 x265_log(param
, X265_LOG_INFO
, "Keyframe min / max / scenecut : disabled\n");
1164 if (param
->cbQpOffset
|| param
->crQpOffset
)
1165 x265_log(param
, X265_LOG_INFO
, "Cb/Cr QP Offset : %d / %d\n", param
->cbQpOffset
, param
->crQpOffset
);
1167 if (param
->rdPenalty
)
1168 x265_log(param
, X265_LOG_INFO
, "Intra 32x32 TU penalty type : %d\n", param
->rdPenalty
);
1170 x265_log(param
, X265_LOG_INFO
, "Lookahead / bframes / badapt : %d / %d / %d\n", param
->lookaheadDepth
, param
->bframes
, param
->bFrameAdaptive
);
1171 x265_log(param
, X265_LOG_INFO
, "b-pyramid / weightp / weightb / refs: %d / %d / %d / %d\n",
1172 param
->bBPyramid
, param
->bEnableWeightedPred
, param
->bEnableWeightedBiPred
, param
->maxNumReferences
);
1174 if (param
->bLossless
)
1175 x265_log(param
, X265_LOG_INFO
, "Rate Control : Lossless\n");
1176 else switch (param
->rc
.rateControlMode
)
1179 x265_log(param
, X265_LOG_INFO
, "Rate Control / AQ-Strength / CUTree : ABR-%d kbps / %0.1f / %d\n", param
->rc
.bitrate
,
1180 param
->rc
.aqStrength
, param
->rc
.cuTree
);
1183 x265_log(param
, X265_LOG_INFO
, "Rate Control / AQ-Strength / CUTree : CQP-%d / %0.1f / %d\n", param
->rc
.qp
, param
->rc
.aqStrength
,
1187 x265_log(param
, X265_LOG_INFO
, "Rate Control / AQ-Strength / CUTree : CRF-%0.1f / %0.1f / %d\n", param
->rc
.rfConstant
,
1188 param
->rc
.aqStrength
, param
->rc
.cuTree
);
1192 if (param
->rc
.vbvBufferSize
)
1193 x265_log(param
, X265_LOG_INFO
, "VBV/HRD buffer / max-rate / init : %d / %d / %.3f\n",
1194 param
->rc
.vbvBufferSize
, param
->rc
.vbvMaxBitrate
, param
->rc
.vbvBufferInit
);
1196 x265_log(param
, X265_LOG_INFO
, "tools: ");
1197 #define TOOLOPT(FLAG, STR) if (FLAG) fprintf(stderr, "%s ", STR)
1198 TOOLOPT(param
->bEnableRectInter
, "rect");
1199 TOOLOPT(param
->bEnableAMP
, "amp");
1200 fprintf(stderr
, "rd=%d ", param
->rdLevel
);
1201 if (param
->psyRd
> 0.)
1202 fprintf(stderr
, "psy-rd=%.2lf ", param
->psyRd
);
1203 if (param
->psyRdoq
> 0.)
1204 fprintf(stderr
, "psy-rdoq=%.2lf ", param
->psyRdoq
);
1205 TOOLOPT(param
->bEnableEarlySkip
, "early-skip");
1206 TOOLOPT(param
->bEnableCbfFastMode
, "fast-cbf");
1207 if (param
->noiseReductionIntra
)
1208 fprintf(stderr
, "nr-intra=%d ", param
->noiseReductionIntra
);
1209 if (param
->noiseReductionInter
)
1210 fprintf(stderr
, "nr-inter=%d ", param
->noiseReductionInter
);
1211 if (param
->bEnableLoopFilter
)
1213 if (param
->deblockingFilterBetaOffset
|| param
->deblockingFilterTCOffset
)
1214 fprintf(stderr
, "deblock(tC=%d:B=%d) ", param
->deblockingFilterTCOffset
, param
->deblockingFilterBetaOffset
);
1216 TOOLOPT(param
->bEnableLoopFilter
, "deblock");
1218 if (param
->bEnableSAO
)
1219 fprintf(stderr
, "sao%s ", param
->bSaoNonDeblocked
? "-non-deblock" : "");
1220 TOOLOPT(param
->bEnableSignHiding
, "signhide");
1221 TOOLOPT(param
->bEnableConstrainedIntra
, "cip");
1222 TOOLOPT(param
->bIntraInBFrames
, "b-intra");
1223 TOOLOPT(param
->bEnableFastIntra
, "fast-intra");
1224 TOOLOPT(param
->bEnableTemporalMvp
, "tmvp");
1225 if (param
->bEnableTransformSkip
)
1226 fprintf(stderr
, "tskip%s ", param
->bEnableTSkipFast
? "-fast" : "");
1227 TOOLOPT(param
->bCULossless
, "cu-lossless");
1228 TOOLOPT(param
->rc
.bStatWrite
, "stats-write");
1229 TOOLOPT(param
->rc
.bStatRead
, "stats-read");
1230 fprintf(stderr
, "\n");
1234 char *x265_param2string(x265_param
*p
)
1238 buf
= s
= X265_MALLOC(char, MAXPARAMSIZE
);
1242 #define BOOL(param, cliopt) \
1243 s += sprintf(s, " %s", (param) ? cliopt : "no-"cliopt);
1245 s
+= sprintf(s
, "%dx%d", p
->sourceWidth
,p
->sourceHeight
);
1246 s
+= sprintf(s
, " fps=%u/%u", p
->fpsNum
, p
->fpsDenom
);
1247 s
+= sprintf(s
, " bitdepth=%d", p
->internalBitDepth
);
1248 BOOL(p
->bEnableWavefront
, "wpp");
1249 s
+= sprintf(s
, " ctu=%d", p
->maxCUSize
);
1250 s
+= sprintf(s
, " tu-intra-depth=%d", p
->tuQTMaxIntraDepth
);
1251 s
+= sprintf(s
, " tu-inter-depth=%d", p
->tuQTMaxInterDepth
);
1252 s
+= sprintf(s
, " me=%d", p
->searchMethod
);
1253 s
+= sprintf(s
, " subme=%d", p
->subpelRefine
);
1254 s
+= sprintf(s
, " merange=%d", p
->searchRange
);
1255 BOOL(p
->bEnableRectInter
, "rect");
1256 BOOL(p
->bEnableAMP
, "amp");
1257 s
+= sprintf(s
, " max-merge=%d", p
->maxNumMergeCand
);
1258 BOOL(p
->bEnableTemporalMvp
, "temporal-mvp");
1259 BOOL(p
->bEnableEarlySkip
, "early-skip");
1260 BOOL(p
->bEnableCbfFastMode
, "fast-cbf");
1261 s
+= sprintf(s
, " rdpenalty=%d", p
->rdPenalty
);
1262 BOOL(p
->bEnableTransformSkip
, "tskip");
1263 BOOL(p
->bEnableTSkipFast
, "tskip-fast");
1264 BOOL(p
->bEnableStrongIntraSmoothing
, "strong-intra-smoothing");
1265 BOOL(p
->bLossless
, "lossless");
1266 BOOL(p
->bCULossless
, "cu-lossless");
1267 BOOL(p
->bEnableConstrainedIntra
, "constrained-intra");
1268 BOOL(p
->bEnableFastIntra
, "fast-intra");
1269 BOOL(p
->bOpenGOP
, "open-gop");
1270 s
+= sprintf(s
, " interlace=%d", p
->interlaceMode
);
1271 s
+= sprintf(s
, " keyint=%d", p
->keyframeMax
);
1272 s
+= sprintf(s
, " min-keyint=%d", p
->keyframeMin
);
1273 s
+= sprintf(s
, " scenecut=%d", p
->scenecutThreshold
);
1274 s
+= sprintf(s
, " rc-lookahead=%d", p
->lookaheadDepth
);
1275 s
+= sprintf(s
, " bframes=%d", p
->bframes
);
1276 s
+= sprintf(s
, " bframe-bias=%d", p
->bFrameBias
);
1277 s
+= sprintf(s
, " b-adapt=%d", p
->bFrameAdaptive
);
1278 s
+= sprintf(s
, " ref=%d", p
->maxNumReferences
);
1279 BOOL(p
->bEnableWeightedPred
, "weightp");
1280 BOOL(p
->bEnableWeightedBiPred
, "weightb");
1281 s
+= sprintf(s
, " aq-mode=%d", p
->rc
.aqMode
);
1282 s
+= sprintf(s
, " aq-strength=%.2f", p
->rc
.aqStrength
);
1283 s
+= sprintf(s
, " cbqpoffs=%d", p
->cbQpOffset
);
1284 s
+= sprintf(s
, " crqpoffs=%d", p
->crQpOffset
);
1285 s
+= sprintf(s
, " rd=%d", p
->rdLevel
);
1286 s
+= sprintf(s
, " psy-rd=%.2f", p
->psyRd
);
1287 s
+= sprintf(s
, " psy-rdoq=%.2f", p
->psyRdoq
);
1288 BOOL(p
->bEnableSignHiding
, "signhide");
1289 BOOL(p
->bEnableLoopFilter
, "lft");
1290 BOOL(p
->bEnableSAO
, "sao");
1291 BOOL(p
->bSaoNonDeblocked
, "sao-non-deblock");
1292 BOOL(p
->bBPyramid
, "b-pyramid");
1293 BOOL(p
->rc
.cuTree
, "cutree");
1294 s
+= sprintf(s
, " rc=%s", p
->rc
.rateControlMode
== X265_RC_ABR
? (
1295 p
->rc
.bStatRead
? "2 pass" : p
->rc
.bitrate
== p
->rc
.vbvMaxBitrate
? "cbr" : "abr")
1296 : p
->rc
.rateControlMode
== X265_RC_CRF
? "crf" : "cqp");
1297 if (p
->rc
.rateControlMode
== X265_RC_ABR
|| p
->rc
.rateControlMode
== X265_RC_CRF
)
1299 if (p
->rc
.rateControlMode
== X265_RC_CRF
)
1300 s
+= sprintf(s
, " crf=%.1f", p
->rc
.rfConstant
);
1302 s
+= sprintf(s
, " bitrate=%d ratetol=%.1f",
1303 p
->rc
.bitrate
, p
->rc
.rateTolerance
);
1304 s
+= sprintf(s
, " qcomp=%.2f qpmin=%d qpmax=%d qpstep=%d",
1305 p
->rc
.qCompress
, QP_MIN
, QP_MAX_SPEC
, p
->rc
.qpStep
);
1306 if (p
->rc
.bStatRead
)
1307 s
+= sprintf( s
, " cplxblur=%.1f qblur=%.1f",
1308 p
->rc
.complexityBlur
, p
->rc
.qblur
);
1309 if (p
->rc
.vbvBufferSize
)
1311 s
+= sprintf(s
, " vbv-maxrate=%d vbv-bufsize=%d",
1312 p
->rc
.vbvMaxBitrate
, p
->rc
.vbvBufferSize
);
1313 if (p
->rc
.rateControlMode
== X265_RC_CRF
)
1314 s
+= sprintf(s
, " crf-max=%.1f", p
->rc
.rfConstantMax
);
1317 else if (p
->rc
.rateControlMode
== X265_RC_CQP
)
1318 s
+= sprintf(s
, " qp=%d", p
->rc
.qp
);
1319 if (!(p
->rc
.rateControlMode
== X265_RC_CQP
&& p
->rc
.qp
== 0))
1321 s
+= sprintf(s
, " ipratio=%.2f", p
->rc
.ipFactor
);
1323 s
+= sprintf(s
, " pbratio=%.2f", p
->rc
.pbFactor
);
1329 bool parseLambdaFile(x265_param
*param
)
1331 if (!param
->rc
.lambdaFileName
)
1334 FILE *lfn
= fopen(param
->rc
.lambdaFileName
, "r");
1337 x265_log(param
, X265_LOG_ERROR
, "unable to read lambda file <%s>\n", param
->rc
.lambdaFileName
);
1342 char *toksave
= NULL
, *tok
= NULL
, *buf
= NULL
;
1344 for (int t
= 0; t
< 3; t
++)
1346 double *table
= t
? x265_lambda2_tab
: x265_lambda_tab
;
1348 for (int i
= 0; i
< QP_MAX_MAX
+ 1; i
++)
1356 /* consume a line of text file */
1357 if (!fgets(line
, sizeof(line
), lfn
))
1363 x265_log(param
, X265_LOG_ERROR
, "lambda file is incomplete\n");
1370 /* truncate at first hash */
1371 char *hash
= strchr(line
, '#');
1372 if (hash
) *hash
= 0;
1376 tok
= strtok_r(buf
, " ,", &toksave
);
1378 if (tok
&& sscanf(tok
, "%lf", &value
) == 1)
1385 x265_log(param
, X265_LOG_ERROR
, "lambda file contains too many values\n");
1390 x265_log(param
, X265_LOG_DEBUG
, "lambda%c[%d] = %lf\n", t
? '2' : ' ', i
, value
);