/src/x265/source/common/param.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * Copyright (C) 2013-2020 MulticoreWare, Inc |
3 | | * |
4 | | * Authors: Deepthi Nandakumar <deepthi@multicorewareinc.com> |
5 | | * Min Chen <min.chen@multicorewareinc.com> |
6 | | * |
7 | | * This program is free software; you can redistribute it and/or modify |
8 | | * it under the terms of the GNU General Public License as published by |
9 | | * the Free Software Foundation; either version 2 of the License, or |
10 | | * (at your option) any later version. |
11 | | * |
12 | | * This program is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU General Public License |
18 | | * along with this program; if not, write to the Free Software |
19 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. |
20 | | * |
21 | | * This program is also available under a commercial proprietary license. |
22 | | * For more information, contact us at license @ x265.com. |
23 | | *****************************************************************************/ |
24 | | |
25 | | #include "common.h" |
26 | | #include "slice.h" |
27 | | #include "threading.h" |
28 | | #include "param.h" |
29 | | #include "cpu.h" |
30 | | #include "x265.h" |
31 | | #include "svt.h" |
32 | | |
33 | | #if _MSC_VER |
34 | | #pragma warning(disable: 4996) // POSIX functions are just fine, thanks |
35 | | #pragma warning(disable: 4706) // assignment within conditional |
36 | | #pragma warning(disable: 4127) // conditional expression is constant |
37 | | #endif |
38 | | |
39 | | #if _WIN32 |
40 | | #define strcasecmp _stricmp |
41 | | #endif |
42 | | |
43 | | #if !defined(HAVE_STRTOK_R) |
44 | | |
45 | | /* |
46 | | * adapted from public domain strtok_r() by Charlie Gordon |
47 | | * |
48 | | * from comp.lang.c 9/14/2007 |
49 | | * |
50 | | * http://groups.google.com/group/comp.lang.c/msg/2ab1ecbb86646684 |
51 | | * |
52 | | * (Declaration that it's public domain): |
53 | | * http://groups.google.com/group/comp.lang.c/msg/7c7b39328fefab9c |
54 | | */ |
55 | | |
56 | | #undef strtok_r |
57 | | static char* strtok_r(char* str, const char* delim, char** nextp) |
58 | | { |
59 | | if (!str) |
60 | | str = *nextp; |
61 | | |
62 | | str += strspn(str, delim); |
63 | | |
64 | | if (!*str) |
65 | | return NULL; |
66 | | |
67 | | char *ret = str; |
68 | | |
69 | | str += strcspn(str, delim); |
70 | | |
71 | | if (*str) |
72 | | *str++ = '\0'; |
73 | | |
74 | | *nextp = str; |
75 | | |
76 | | return ret; |
77 | | } |
78 | | |
79 | | #endif // if !defined(HAVE_STRTOK_R) |
80 | | |
81 | | #if EXPORT_C_API |
82 | | |
83 | | /* these functions are exported as C functions (default) */ |
84 | | using namespace X265_NS; |
85 | | extern "C" { |
86 | | |
87 | | #else |
88 | | |
89 | | /* these functions exist within private namespace (multilib) */ |
90 | | namespace X265_NS { |
91 | | |
92 | | #endif |
93 | | |
94 | | x265_param *x265_param_alloc() |
95 | 0 | { |
96 | 0 | x265_param* param = (x265_param*)x265_malloc(sizeof(x265_param)); |
97 | | #ifdef SVT_HEVC |
98 | | param->svtHevcParam = (EB_H265_ENC_CONFIGURATION*)x265_malloc(sizeof(EB_H265_ENC_CONFIGURATION)); |
99 | | #endif |
100 | 0 | return param; |
101 | 0 | } |
102 | | |
103 | | void x265_param_free(x265_param* p) |
104 | 0 | { |
105 | 0 | x265_zone_free(p); |
106 | | #ifdef SVT_HEVC |
107 | | x265_free(p->svtHevcParam); |
108 | | #endif |
109 | 0 | x265_free(p); |
110 | 0 | } |
111 | | |
112 | | void x265_param_default(x265_param* param) |
113 | 0 | { |
114 | | #ifdef SVT_HEVC |
115 | | EB_H265_ENC_CONFIGURATION* svtParam = (EB_H265_ENC_CONFIGURATION*)param->svtHevcParam; |
116 | | #endif |
117 | |
|
118 | 0 | memset(param, 0, sizeof(x265_param)); |
119 | | |
120 | | /* Applying default values to all elements in the param structure */ |
121 | 0 | param->cpuid = X265_NS::cpu_detect(false); |
122 | 0 | param->bEnableWavefront = 1; |
123 | 0 | param->frameNumThreads = 0; |
124 | |
|
125 | 0 | param->logLevel = X265_LOG_INFO; |
126 | 0 | param->csvLogLevel = 0; |
127 | 0 | param->csvfn = NULL; |
128 | 0 | param->rc.lambdaFileName = NULL; |
129 | 0 | param->bLogCuStats = 0; |
130 | 0 | param->decodedPictureHashSEI = 0; |
131 | | |
132 | | /* Quality Measurement Metrics */ |
133 | 0 | param->bEnablePsnr = 0; |
134 | 0 | param->bEnableSsim = 0; |
135 | | |
136 | | /* Source specifications */ |
137 | 0 | param->internalBitDepth = X265_DEPTH; |
138 | 0 | param->sourceBitDepth = 8; |
139 | 0 | param->internalCsp = X265_CSP_I420; |
140 | 0 | param->levelIdc = 0; //Auto-detect level |
141 | 0 | param->uhdBluray = 0; |
142 | 0 | param->bHighTier = 1; //Allow high tier by default |
143 | 0 | param->interlaceMode = 0; |
144 | 0 | param->bField = 0; |
145 | 0 | param->bAnnexB = 1; |
146 | 0 | param->bRepeatHeaders = 0; |
147 | 0 | param->bEnableAccessUnitDelimiters = 0; |
148 | 0 | param->bEmitHRDSEI = 0; |
149 | 0 | param->bEmitInfoSEI = 1; |
150 | 0 | param->bEmitHDRSEI = 0; /*Deprecated*/ |
151 | 0 | param->bEmitHDR10SEI = 0; |
152 | 0 | param->bEmitIDRRecoverySEI = 0; |
153 | | |
154 | | /* CU definitions */ |
155 | 0 | param->maxCUSize = 64; |
156 | 0 | param->minCUSize = 8; |
157 | 0 | param->tuQTMaxInterDepth = 1; |
158 | 0 | param->tuQTMaxIntraDepth = 1; |
159 | 0 | param->maxTUSize = 32; |
160 | | |
161 | | /* Coding Structure */ |
162 | 0 | param->keyframeMin = 0; |
163 | 0 | param->keyframeMax = 250; |
164 | 0 | param->gopLookahead = 0; |
165 | 0 | param->bOpenGOP = 1; |
166 | 0 | param->bframes = 4; |
167 | 0 | param->lookaheadDepth = 20; |
168 | 0 | param->bFrameAdaptive = X265_B_ADAPT_TRELLIS; |
169 | 0 | param->bBPyramid = 1; |
170 | 0 | param->scenecutThreshold = 40; /* Magic number pulled in from x264 */ |
171 | 0 | param->edgeTransitionThreshold = 0.01; |
172 | 0 | param->bHistBasedSceneCut = 0; |
173 | 0 | param->lookaheadSlices = 8; |
174 | 0 | param->lookaheadThreads = 0; |
175 | 0 | param->scenecutBias = 5.0; |
176 | 0 | param->radl = 0; |
177 | 0 | param->chunkStart = 0; |
178 | 0 | param->chunkEnd = 0; |
179 | 0 | param->bEnableHRDConcatFlag = 0; |
180 | 0 | param->bEnableFades = 0; |
181 | 0 | param->bEnableSceneCutAwareQp = 0; |
182 | 0 | param->scenecutWindow = 500; |
183 | 0 | param->maxQpDelta = 5; |
184 | | |
185 | | /* Intra Coding Tools */ |
186 | 0 | param->bEnableConstrainedIntra = 0; |
187 | 0 | param->bEnableStrongIntraSmoothing = 1; |
188 | 0 | param->bEnableFastIntra = 0; |
189 | 0 | param->bEnableSplitRdSkip = 0; |
190 | | |
191 | | /* Inter Coding tools */ |
192 | 0 | param->searchMethod = X265_HEX_SEARCH; |
193 | 0 | param->subpelRefine = 2; |
194 | 0 | param->searchRange = 57; |
195 | 0 | param->maxNumMergeCand = 3; |
196 | 0 | param->limitReferences = 1; |
197 | 0 | param->limitModes = 0; |
198 | 0 | param->bEnableWeightedPred = 1; |
199 | 0 | param->bEnableWeightedBiPred = 0; |
200 | 0 | param->bEnableEarlySkip = 1; |
201 | 0 | param->recursionSkipMode = 1; |
202 | 0 | param->edgeVarThreshold = 0.05f; |
203 | 0 | param->bEnableAMP = 0; |
204 | 0 | param->bEnableRectInter = 0; |
205 | 0 | param->rdLevel = 3; |
206 | 0 | param->rdoqLevel = 0; |
207 | 0 | param->bEnableSignHiding = 1; |
208 | 0 | param->bEnableTransformSkip = 0; |
209 | 0 | param->bEnableTSkipFast = 0; |
210 | 0 | param->maxNumReferences = 3; |
211 | 0 | param->bEnableTemporalMvp = 1; |
212 | 0 | param->bEnableHME = 0; |
213 | 0 | param->hmeSearchMethod[0] = X265_HEX_SEARCH; |
214 | 0 | param->hmeSearchMethod[1] = param->hmeSearchMethod[2] = X265_UMH_SEARCH; |
215 | 0 | param->hmeRange[0] = 16; |
216 | 0 | param->hmeRange[1] = 32; |
217 | 0 | param->hmeRange[2] = 48; |
218 | 0 | param->bSourceReferenceEstimation = 0; |
219 | 0 | param->limitTU = 0; |
220 | 0 | param->dynamicRd = 0; |
221 | | |
222 | | /* Loop Filter */ |
223 | 0 | param->bEnableLoopFilter = 1; |
224 | | |
225 | | /* SAO Loop Filter */ |
226 | 0 | param->bEnableSAO = 1; |
227 | 0 | param->bSaoNonDeblocked = 0; |
228 | 0 | param->bLimitSAO = 0; |
229 | 0 | param->selectiveSAO = 0; |
230 | | |
231 | | /* Coding Quality */ |
232 | 0 | param->cbQpOffset = 0; |
233 | 0 | param->crQpOffset = 0; |
234 | 0 | param->rdPenalty = 0; |
235 | 0 | param->psyRd = 2.0; |
236 | 0 | param->psyRdoq = 0.0; |
237 | 0 | param->analysisReuseMode = 0; /*DEPRECATED*/ |
238 | 0 | param->analysisMultiPassRefine = 0; |
239 | 0 | param->analysisMultiPassDistortion = 0; |
240 | 0 | param->analysisReuseFileName = NULL; |
241 | 0 | param->analysisSave = NULL; |
242 | 0 | param->analysisLoad = NULL; |
243 | 0 | param->bIntraInBFrames = 1; |
244 | 0 | param->bLossless = 0; |
245 | 0 | param->bCULossless = 0; |
246 | 0 | param->bEnableTemporalSubLayers = 0; |
247 | 0 | param->bEnableRdRefine = 0; |
248 | 0 | param->bMultiPassOptRPS = 0; |
249 | 0 | param->bSsimRd = 0; |
250 | | |
251 | | /* Rate control options */ |
252 | 0 | param->rc.vbvMaxBitrate = 0; |
253 | 0 | param->rc.vbvBufferSize = 0; |
254 | 0 | param->rc.vbvBufferInit = 0.9; |
255 | 0 | param->vbvBufferEnd = 0; |
256 | 0 | param->vbvEndFrameAdjust = 0; |
257 | 0 | param->rc.rfConstant = 28; |
258 | 0 | param->rc.bitrate = 0; |
259 | 0 | param->rc.qCompress = 0.6; |
260 | 0 | param->rc.ipFactor = 1.4f; |
261 | 0 | param->rc.pbFactor = 1.3f; |
262 | 0 | param->rc.qpStep = 4; |
263 | 0 | param->rc.rateControlMode = X265_RC_CRF; |
264 | 0 | param->rc.qp = 32; |
265 | 0 | param->rc.aqMode = X265_AQ_AUTO_VARIANCE; |
266 | 0 | param->rc.hevcAq = 0; |
267 | 0 | param->rc.qgSize = 32; |
268 | 0 | param->rc.aqStrength = 1.0; |
269 | 0 | param->rc.qpAdaptationRange = 1.0; |
270 | 0 | param->rc.cuTree = 1; |
271 | 0 | param->rc.rfConstantMax = 0; |
272 | 0 | param->rc.rfConstantMin = 0; |
273 | 0 | param->rc.bStatRead = 0; |
274 | 0 | param->rc.bStatWrite = 0; |
275 | 0 | param->rc.statFileName = NULL; |
276 | 0 | param->rc.complexityBlur = 20; |
277 | 0 | param->rc.qblur = 0.5; |
278 | 0 | param->rc.zoneCount = 0; |
279 | 0 | param->rc.zonefileCount = 0; |
280 | 0 | param->rc.zones = NULL; |
281 | 0 | param->rc.bEnableSlowFirstPass = 1; |
282 | 0 | param->rc.bStrictCbr = 0; |
283 | 0 | param->rc.bEnableGrain = 0; |
284 | 0 | param->rc.qpMin = 0; |
285 | 0 | param->rc.qpMax = QP_MAX_MAX; |
286 | 0 | param->rc.bEnableConstVbv = 0; |
287 | 0 | param->bResetZoneConfig = 1; |
288 | 0 | param->reconfigWindowSize = 0; |
289 | 0 | param->decoderVbvMaxRate = 0; |
290 | | |
291 | | /* Video Usability Information (VUI) */ |
292 | 0 | param->vui.aspectRatioIdc = 0; |
293 | 0 | param->vui.sarWidth = 0; |
294 | 0 | param->vui.sarHeight = 0; |
295 | 0 | param->vui.bEnableOverscanAppropriateFlag = 0; |
296 | 0 | param->vui.bEnableVideoSignalTypePresentFlag = 0; |
297 | 0 | param->vui.videoFormat = 5; |
298 | 0 | param->vui.bEnableVideoFullRangeFlag = 0; |
299 | 0 | param->vui.bEnableColorDescriptionPresentFlag = 0; |
300 | 0 | param->vui.colorPrimaries = 2; |
301 | 0 | param->vui.transferCharacteristics = 2; |
302 | 0 | param->vui.matrixCoeffs = 2; |
303 | 0 | param->vui.bEnableChromaLocInfoPresentFlag = 0; |
304 | 0 | param->vui.chromaSampleLocTypeTopField = 0; |
305 | 0 | param->vui.chromaSampleLocTypeBottomField = 0; |
306 | 0 | param->vui.bEnableDefaultDisplayWindowFlag = 0; |
307 | 0 | param->vui.defDispWinLeftOffset = 0; |
308 | 0 | param->vui.defDispWinRightOffset = 0; |
309 | 0 | param->vui.defDispWinTopOffset = 0; |
310 | 0 | param->vui.defDispWinBottomOffset = 0; |
311 | 0 | param->maxCLL = 0; |
312 | 0 | param->maxFALL = 0; |
313 | 0 | param->minLuma = 0; |
314 | 0 | param->maxLuma = PIXEL_MAX; |
315 | 0 | param->log2MaxPocLsb = 8; |
316 | 0 | param->maxSlices = 1; |
317 | | |
318 | | /*Conformance window*/ |
319 | 0 | param->confWinRightOffset = 0; |
320 | 0 | param->confWinBottomOffset = 0; |
321 | |
|
322 | 0 | param->bEmitVUITimingInfo = 1; |
323 | 0 | param->bEmitVUIHRDInfo = 1; |
324 | 0 | param->bOptQpPPS = 0; |
325 | 0 | param->bOptRefListLengthPPS = 0; |
326 | 0 | param->bOptCUDeltaQP = 0; |
327 | 0 | param->bAQMotion = 0; |
328 | 0 | param->bHDROpt = 0; /*DEPRECATED*/ |
329 | 0 | param->bHDR10Opt = 0; |
330 | 0 | param->analysisReuseLevel = 0; /*DEPRECATED*/ |
331 | 0 | param->analysisSaveReuseLevel = 0; |
332 | 0 | param->analysisLoadReuseLevel = 0; |
333 | 0 | param->toneMapFile = NULL; |
334 | 0 | param->bDhdr10opt = 0; |
335 | 0 | param->dolbyProfile = 0; |
336 | 0 | param->bCTUInfo = 0; |
337 | 0 | param->bUseRcStats = 0; |
338 | 0 | param->scaleFactor = 0; |
339 | 0 | param->intraRefine = 0; |
340 | 0 | param->interRefine = 0; |
341 | 0 | param->bDynamicRefine = 0; |
342 | 0 | param->mvRefine = 1; |
343 | 0 | param->ctuDistortionRefine = 0; |
344 | 0 | param->bUseAnalysisFile = 1; |
345 | 0 | param->csvfpt = NULL; |
346 | 0 | param->forceFlush = 0; |
347 | 0 | param->bDisableLookahead = 0; |
348 | 0 | param->bCopyPicToFrame = 1; |
349 | 0 | param->maxAUSizeFactor = 1; |
350 | 0 | param->naluFile = NULL; |
351 | | |
352 | | /* DCT Approximations */ |
353 | 0 | param->bLowPassDct = 0; |
354 | 0 | param->bAnalysisType = 0; |
355 | 0 | param->bSingleSeiNal = 0; |
356 | | |
357 | | /* SEI messages */ |
358 | 0 | param->preferredTransferCharacteristics = -1; |
359 | 0 | param->pictureStructure = -1; |
360 | 0 | param->bEmitCLL = 1; |
361 | |
|
362 | 0 | param->bEnableFrameDuplication = 0; |
363 | 0 | param->dupThreshold = 70; |
364 | | |
365 | | /* SVT Hevc Encoder specific params */ |
366 | 0 | param->bEnableSvtHevc = 0; |
367 | 0 | param->svtHevcParam = NULL; |
368 | |
|
369 | | #ifdef SVT_HEVC |
370 | | param->svtHevcParam = svtParam; |
371 | | svt_param_default(param); |
372 | | #endif |
373 | 0 | } |
374 | | |
375 | | int x265_param_default_preset(x265_param* param, const char* preset, const char* tune) |
376 | 0 | { |
377 | 0 | #if EXPORT_C_API |
378 | 0 | ::x265_param_default(param); |
379 | | #else |
380 | | X265_NS::x265_param_default(param); |
381 | | #endif |
382 | |
|
383 | 0 | if (preset) |
384 | 0 | { |
385 | 0 | char *end; |
386 | 0 | int i = strtol(preset, &end, 10); |
387 | 0 | if (*end == 0 && i >= 0 && i < (int)(sizeof(x265_preset_names) / sizeof(*x265_preset_names) - 1)) |
388 | 0 | preset = x265_preset_names[i]; |
389 | |
|
390 | 0 | if (!strcmp(preset, "ultrafast")) |
391 | 0 | { |
392 | 0 | param->maxNumMergeCand = 2; |
393 | 0 | param->bIntraInBFrames = 0; |
394 | 0 | param->lookaheadDepth = 5; |
395 | 0 | param->scenecutThreshold = 0; // disable lookahead |
396 | 0 | param->maxCUSize = 32; |
397 | 0 | param->minCUSize = 16; |
398 | 0 | param->bframes = 3; |
399 | 0 | param->bFrameAdaptive = 0; |
400 | 0 | param->subpelRefine = 0; |
401 | 0 | param->searchMethod = X265_DIA_SEARCH; |
402 | 0 | param->bEnableSAO = 0; |
403 | 0 | param->bEnableSignHiding = 0; |
404 | 0 | param->bEnableWeightedPred = 0; |
405 | 0 | param->rdLevel = 2; |
406 | 0 | param->maxNumReferences = 1; |
407 | 0 | param->limitReferences = 0; |
408 | 0 | param->rc.aqStrength = 0.0; |
409 | 0 | param->rc.aqMode = X265_AQ_NONE; |
410 | 0 | param->rc.hevcAq = 0; |
411 | 0 | param->rc.qgSize = 32; |
412 | 0 | param->bEnableFastIntra = 1; |
413 | 0 | } |
414 | 0 | else if (!strcmp(preset, "superfast")) |
415 | 0 | { |
416 | 0 | param->maxNumMergeCand = 2; |
417 | 0 | param->bIntraInBFrames = 0; |
418 | 0 | param->lookaheadDepth = 10; |
419 | 0 | param->maxCUSize = 32; |
420 | 0 | param->bframes = 3; |
421 | 0 | param->bFrameAdaptive = 0; |
422 | 0 | param->subpelRefine = 1; |
423 | 0 | param->bEnableWeightedPred = 0; |
424 | 0 | param->rdLevel = 2; |
425 | 0 | param->maxNumReferences = 1; |
426 | 0 | param->limitReferences = 0; |
427 | 0 | param->rc.aqStrength = 0.0; |
428 | 0 | param->rc.aqMode = X265_AQ_NONE; |
429 | 0 | param->rc.hevcAq = 0; |
430 | 0 | param->rc.qgSize = 32; |
431 | 0 | param->bEnableSAO = 0; |
432 | 0 | param->bEnableFastIntra = 1; |
433 | 0 | } |
434 | 0 | else if (!strcmp(preset, "veryfast")) |
435 | 0 | { |
436 | 0 | param->maxNumMergeCand = 2; |
437 | 0 | param->limitReferences = 3; |
438 | 0 | param->bIntraInBFrames = 0; |
439 | 0 | param->lookaheadDepth = 15; |
440 | 0 | param->bFrameAdaptive = 0; |
441 | 0 | param->subpelRefine = 1; |
442 | 0 | param->rdLevel = 2; |
443 | 0 | param->maxNumReferences = 2; |
444 | 0 | param->rc.qgSize = 32; |
445 | 0 | param->bEnableFastIntra = 1; |
446 | 0 | } |
447 | 0 | else if (!strcmp(preset, "faster")) |
448 | 0 | { |
449 | 0 | param->maxNumMergeCand = 2; |
450 | 0 | param->limitReferences = 3; |
451 | 0 | param->bIntraInBFrames = 0; |
452 | 0 | param->lookaheadDepth = 15; |
453 | 0 | param->bFrameAdaptive = 0; |
454 | 0 | param->rdLevel = 2; |
455 | 0 | param->maxNumReferences = 2; |
456 | 0 | param->bEnableFastIntra = 1; |
457 | 0 | } |
458 | 0 | else if (!strcmp(preset, "fast")) |
459 | 0 | { |
460 | 0 | param->maxNumMergeCand = 2; |
461 | 0 | param->limitReferences = 3; |
462 | 0 | param->bEnableEarlySkip = 0; |
463 | 0 | param->bIntraInBFrames = 0; |
464 | 0 | param->lookaheadDepth = 15; |
465 | 0 | param->bFrameAdaptive = 0; |
466 | 0 | param->rdLevel = 2; |
467 | 0 | param->maxNumReferences = 3; |
468 | 0 | param->bEnableFastIntra = 1; |
469 | 0 | } |
470 | 0 | else if (!strcmp(preset, "medium")) |
471 | 0 | { |
472 | | /* defaults */ |
473 | 0 | } |
474 | 0 | else if (!strcmp(preset, "slow")) |
475 | 0 | { |
476 | 0 | param->limitReferences = 3; |
477 | 0 | param->bEnableEarlySkip = 0; |
478 | 0 | param->bIntraInBFrames = 0; |
479 | 0 | param->bEnableRectInter = 1; |
480 | 0 | param->lookaheadDepth = 25; |
481 | 0 | param->rdLevel = 4; |
482 | 0 | param->rdoqLevel = 2; |
483 | 0 | param->psyRdoq = 1.0; |
484 | 0 | param->subpelRefine = 3; |
485 | 0 | param->searchMethod = X265_STAR_SEARCH; |
486 | 0 | param->maxNumReferences = 4; |
487 | 0 | param->limitModes = 1; |
488 | 0 | param->lookaheadSlices = 4; // limit parallelism as already enough work exists |
489 | 0 | } |
490 | 0 | else if (!strcmp(preset, "slower")) |
491 | 0 | { |
492 | 0 | param->bEnableEarlySkip = 0; |
493 | 0 | param->bEnableWeightedBiPred = 1; |
494 | 0 | param->bEnableAMP = 1; |
495 | 0 | param->bEnableRectInter = 1; |
496 | 0 | param->lookaheadDepth = 40; |
497 | 0 | param->bframes = 8; |
498 | 0 | param->tuQTMaxInterDepth = 3; |
499 | 0 | param->tuQTMaxIntraDepth = 3; |
500 | 0 | param->rdLevel = 6; |
501 | 0 | param->rdoqLevel = 2; |
502 | 0 | param->psyRdoq = 1.0; |
503 | 0 | param->subpelRefine = 4; |
504 | 0 | param->maxNumMergeCand = 4; |
505 | 0 | param->searchMethod = X265_STAR_SEARCH; |
506 | 0 | param->maxNumReferences = 5; |
507 | 0 | param->limitModes = 1; |
508 | 0 | param->lookaheadSlices = 0; // disabled for best quality |
509 | 0 | param->limitTU = 4; |
510 | 0 | } |
511 | 0 | else if (!strcmp(preset, "veryslow")) |
512 | 0 | { |
513 | 0 | param->bEnableEarlySkip = 0; |
514 | 0 | param->bEnableWeightedBiPred = 1; |
515 | 0 | param->bEnableAMP = 1; |
516 | 0 | param->bEnableRectInter = 1; |
517 | 0 | param->lookaheadDepth = 40; |
518 | 0 | param->bframes = 8; |
519 | 0 | param->tuQTMaxInterDepth = 3; |
520 | 0 | param->tuQTMaxIntraDepth = 3; |
521 | 0 | param->rdLevel = 6; |
522 | 0 | param->rdoqLevel = 2; |
523 | 0 | param->psyRdoq = 1.0; |
524 | 0 | param->subpelRefine = 4; |
525 | 0 | param->maxNumMergeCand = 5; |
526 | 0 | param->searchMethod = X265_STAR_SEARCH; |
527 | 0 | param->maxNumReferences = 5; |
528 | 0 | param->limitReferences = 0; |
529 | 0 | param->limitModes = 0; |
530 | 0 | param->lookaheadSlices = 0; // disabled for best quality |
531 | 0 | param->limitTU = 0; |
532 | 0 | } |
533 | 0 | else if (!strcmp(preset, "placebo")) |
534 | 0 | { |
535 | 0 | param->bEnableEarlySkip = 0; |
536 | 0 | param->bEnableWeightedBiPred = 1; |
537 | 0 | param->bEnableAMP = 1; |
538 | 0 | param->bEnableRectInter = 1; |
539 | 0 | param->lookaheadDepth = 60; |
540 | 0 | param->searchRange = 92; |
541 | 0 | param->bframes = 8; |
542 | 0 | param->tuQTMaxInterDepth = 4; |
543 | 0 | param->tuQTMaxIntraDepth = 4; |
544 | 0 | param->rdLevel = 6; |
545 | 0 | param->rdoqLevel = 2; |
546 | 0 | param->psyRdoq = 1.0; |
547 | 0 | param->subpelRefine = 5; |
548 | 0 | param->maxNumMergeCand = 5; |
549 | 0 | param->searchMethod = X265_STAR_SEARCH; |
550 | 0 | param->bEnableTransformSkip = 1; |
551 | 0 | param->recursionSkipMode = 0; |
552 | 0 | param->maxNumReferences = 5; |
553 | 0 | param->limitReferences = 0; |
554 | 0 | param->lookaheadSlices = 0; // disabled for best quality |
555 | | // TODO: optimized esa |
556 | 0 | } |
557 | 0 | else |
558 | 0 | return -1; |
559 | 0 | } |
560 | 0 | if (tune) |
561 | 0 | { |
562 | 0 | if (!strcmp(tune, "psnr")) |
563 | 0 | { |
564 | 0 | param->rc.aqStrength = 0.0; |
565 | 0 | param->psyRd = 0.0; |
566 | 0 | param->psyRdoq = 0.0; |
567 | 0 | } |
568 | 0 | else if (!strcmp(tune, "ssim")) |
569 | 0 | { |
570 | 0 | param->rc.aqMode = X265_AQ_AUTO_VARIANCE; |
571 | 0 | param->psyRd = 0.0; |
572 | 0 | param->psyRdoq = 0.0; |
573 | 0 | } |
574 | 0 | else if (!strcmp(tune, "fastdecode") || |
575 | 0 | !strcmp(tune, "fast-decode")) |
576 | 0 | { |
577 | 0 | param->bEnableLoopFilter = 0; |
578 | 0 | param->bEnableSAO = 0; |
579 | 0 | param->bEnableWeightedPred = 0; |
580 | 0 | param->bEnableWeightedBiPred = 0; |
581 | 0 | param->bIntraInBFrames = 0; |
582 | 0 | } |
583 | 0 | else if (!strcmp(tune, "zerolatency") || |
584 | 0 | !strcmp(tune, "zero-latency")) |
585 | 0 | { |
586 | 0 | param->bFrameAdaptive = 0; |
587 | 0 | param->bframes = 0; |
588 | 0 | param->lookaheadDepth = 0; |
589 | 0 | param->scenecutThreshold = 0; |
590 | 0 | param->bHistBasedSceneCut = 0; |
591 | 0 | param->rc.cuTree = 0; |
592 | 0 | param->frameNumThreads = 1; |
593 | 0 | } |
594 | 0 | else if (!strcmp(tune, "grain")) |
595 | 0 | { |
596 | 0 | param->rc.ipFactor = 1.1; |
597 | 0 | param->rc.pbFactor = 1.0; |
598 | 0 | param->rc.cuTree = 0; |
599 | 0 | param->rc.aqMode = 0; |
600 | 0 | param->rc.hevcAq = 0; |
601 | 0 | param->rc.qpStep = 1; |
602 | 0 | param->rc.bEnableGrain = 1; |
603 | 0 | param->recursionSkipMode = 0; |
604 | 0 | param->psyRd = 4.0; |
605 | 0 | param->psyRdoq = 10.0; |
606 | 0 | param->bEnableSAO = 0; |
607 | 0 | param->rc.bEnableConstVbv = 1; |
608 | 0 | } |
609 | 0 | else if (!strcmp(tune, "animation")) |
610 | 0 | { |
611 | 0 | param->bframes = (param->bframes + 2) >= param->lookaheadDepth? param->bframes : param->bframes + 2; |
612 | 0 | param->psyRd = 0.4; |
613 | 0 | param->rc.aqStrength = 0.4; |
614 | 0 | param->deblockingFilterBetaOffset = 1; |
615 | 0 | param->deblockingFilterTCOffset = 1; |
616 | 0 | } |
617 | 0 | else if (!strcmp(tune, "vmaf")) /*Adding vmaf for x265 + SVT-HEVC integration support*/ |
618 | 0 | { |
619 | | /*vmaf is under development, currently x265 won't support vmaf*/ |
620 | 0 | } |
621 | 0 | else |
622 | 0 | return -1; |
623 | 0 | } |
624 | | |
625 | | #ifdef SVT_HEVC |
626 | | if (svt_set_preset(param, preset)) |
627 | | return -1; |
628 | | #endif |
629 | | |
630 | 0 | return 0; |
631 | 0 | } |
632 | | |
633 | | static int x265_atobool(const char* str, bool& bError) |
634 | 0 | { |
635 | 0 | if (!strcmp(str, "1") || |
636 | 0 | !strcmp(str, "true") || |
637 | 0 | !strcmp(str, "yes")) |
638 | 0 | return 1; |
639 | 0 | if (!strcmp(str, "0") || |
640 | 0 | !strcmp(str, "false") || |
641 | 0 | !strcmp(str, "no")) |
642 | 0 | return 0; |
643 | 0 | bError = true; |
644 | 0 | return 0; |
645 | 0 | } |
646 | | |
647 | | static int parseName(const char* arg, const char* const* names, bool& bError) |
648 | 0 | { |
649 | 0 | for (int i = 0; names[i]; i++) |
650 | 0 | if (!strcmp(arg, names[i])) |
651 | 0 | return i; |
652 | | |
653 | 0 | return x265_atoi(arg, bError); |
654 | 0 | } |
655 | | /* internal versions of string-to-int with additional error checking */ |
656 | | #undef atoi |
657 | | #undef atof |
658 | 0 | #define atoi(str) x265_atoi(str, bError) |
659 | 0 | #define atof(str) x265_atof(str, bError) |
660 | 0 | #define atobool(str) (x265_atobool(str, bError)) |
661 | | |
662 | | int x265_zone_param_parse(x265_param* p, const char* name, const char* value) |
663 | 0 | { |
664 | 0 | bool bError = false; |
665 | 0 | char nameBuf[64]; |
666 | |
|
667 | 0 | if (!name) |
668 | 0 | return X265_PARAM_BAD_NAME; |
669 | | |
670 | | // skip -- prefix if provided |
671 | 0 | if (name[0] == '-' && name[1] == '-') |
672 | 0 | name += 2; |
673 | | |
674 | | // s/_/-/g |
675 | 0 | if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_')) |
676 | 0 | { |
677 | 0 | char *c; |
678 | 0 | strcpy(nameBuf, name); |
679 | 0 | while ((c = strchr(nameBuf, '_')) != 0) |
680 | 0 | *c = '-'; |
681 | |
|
682 | 0 | name = nameBuf; |
683 | 0 | } |
684 | |
|
685 | 0 | if (!strncmp(name, "no-", 3)) |
686 | 0 | { |
687 | 0 | name += 3; |
688 | 0 | value = !value || x265_atobool(value, bError) ? "false" : "true"; |
689 | 0 | } |
690 | 0 | else if (!strncmp(name, "no", 2)) |
691 | 0 | { |
692 | 0 | name += 2; |
693 | 0 | value = !value || x265_atobool(value, bError) ? "false" : "true"; |
694 | 0 | } |
695 | 0 | else if (!value) |
696 | 0 | value = "true"; |
697 | 0 | else if (value[0] == '=') |
698 | 0 | value++; |
699 | |
|
700 | 0 | #define OPT(STR) else if (!strcmp(name, STR)) |
701 | 0 | #define OPT2(STR1, STR2) else if (!strcmp(name, STR1) || !strcmp(name, STR2)) |
702 | |
|
703 | 0 | if (0); |
704 | 0 | OPT("ref") p->maxNumReferences = atoi(value); |
705 | 0 | OPT("fast-intra") p->bEnableFastIntra = atobool(value); |
706 | 0 | OPT("early-skip") p->bEnableEarlySkip = atobool(value); |
707 | 0 | OPT("rskip") p->recursionSkipMode = atoi(value); |
708 | 0 | OPT("rskip-edge-threshold") p->edgeVarThreshold = atoi(value)/100.0f; |
709 | 0 | OPT("me") p->searchMethod = parseName(value, x265_motion_est_names, bError); |
710 | 0 | OPT("subme") p->subpelRefine = atoi(value); |
711 | 0 | OPT("merange") p->searchRange = atoi(value); |
712 | 0 | OPT("rect") p->bEnableRectInter = atobool(value); |
713 | 0 | OPT("amp") p->bEnableAMP = atobool(value); |
714 | 0 | OPT("max-merge") p->maxNumMergeCand = (uint32_t)atoi(value); |
715 | 0 | OPT("rd") p->rdLevel = atoi(value); |
716 | 0 | OPT("radl") p->radl = atoi(value); |
717 | 0 | OPT2("rdoq", "rdoq-level") |
718 | 0 | { |
719 | 0 | int bval = atobool(value); |
720 | 0 | if (bError || bval) |
721 | 0 | { |
722 | 0 | bError = false; |
723 | 0 | p->rdoqLevel = atoi(value); |
724 | 0 | } |
725 | 0 | else |
726 | 0 | p->rdoqLevel = 0; |
727 | 0 | } |
728 | 0 | OPT("b-intra") p->bIntraInBFrames = atobool(value); |
729 | 0 | OPT("scaling-list") p->scalingLists = strdup(value); |
730 | 0 | OPT("crf") |
731 | 0 | { |
732 | 0 | p->rc.rfConstant = atof(value); |
733 | 0 | p->rc.rateControlMode = X265_RC_CRF; |
734 | 0 | } |
735 | 0 | OPT("qp") |
736 | 0 | { |
737 | 0 | p->rc.qp = atoi(value); |
738 | 0 | p->rc.rateControlMode = X265_RC_CQP; |
739 | 0 | } |
740 | 0 | OPT("bitrate") |
741 | 0 | { |
742 | 0 | p->rc.bitrate = atoi(value); |
743 | 0 | p->rc.rateControlMode = X265_RC_ABR; |
744 | 0 | } |
745 | 0 | OPT("aq-mode") p->rc.aqMode = atoi(value); |
746 | 0 | OPT("aq-strength") p->rc.aqStrength = atof(value); |
747 | 0 | OPT("nr-intra") p->noiseReductionIntra = atoi(value); |
748 | 0 | OPT("nr-inter") p->noiseReductionInter = atoi(value); |
749 | 0 | OPT("limit-modes") p->limitModes = atobool(value); |
750 | 0 | OPT("splitrd-skip") p->bEnableSplitRdSkip = atobool(value); |
751 | 0 | OPT("cu-lossless") p->bCULossless = atobool(value); |
752 | 0 | OPT("rd-refine") p->bEnableRdRefine = atobool(value); |
753 | 0 | OPT("limit-tu") p->limitTU = atoi(value); |
754 | 0 | OPT("tskip") p->bEnableTransformSkip = atobool(value); |
755 | 0 | OPT("tskip-fast") p->bEnableTSkipFast = atobool(value); |
756 | 0 | OPT("rdpenalty") p->rdPenalty = atoi(value); |
757 | 0 | OPT("dynamic-rd") p->dynamicRd = atof(value); |
758 | 0 | else |
759 | 0 | return X265_PARAM_BAD_NAME; |
760 | | |
761 | 0 | #undef OPT |
762 | 0 | #undef OPT2 |
763 | | |
764 | 0 | return bError ? X265_PARAM_BAD_VALUE : 0; |
765 | 0 | } |
766 | | |
767 | | #undef atobool |
768 | | #undef atoi |
769 | | #undef atof |
770 | | |
771 | | /* internal versions of string-to-int with additional error checking */ |
772 | | #undef atoi |
773 | | #undef atof |
774 | 0 | #define atoi(str) x265_atoi(str, bError) |
775 | 0 | #define atof(str) x265_atof(str, bError) |
776 | 0 | #define atobool(str) (bNameWasBool = true, x265_atobool(str, bError)) |
777 | | |
778 | | int x265_param_parse(x265_param* p, const char* name, const char* value) |
779 | 0 | { |
780 | 0 | bool bError = false; |
781 | 0 | bool bNameWasBool = false; |
782 | 0 | bool bValueWasNull = !value; |
783 | 0 | bool bExtraParams = false; |
784 | 0 | char nameBuf[64]; |
785 | 0 | static int count; |
786 | |
|
787 | 0 | if (!name) |
788 | 0 | return X265_PARAM_BAD_NAME; |
789 | | |
790 | 0 | count++; |
791 | | // skip -- prefix if provided |
792 | 0 | if (name[0] == '-' && name[1] == '-') |
793 | 0 | name += 2; |
794 | | |
795 | | // s/_/-/g |
796 | 0 | if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_')) |
797 | 0 | { |
798 | 0 | char *c; |
799 | 0 | strcpy(nameBuf, name); |
800 | 0 | while ((c = strchr(nameBuf, '_')) != 0) |
801 | 0 | *c = '-'; |
802 | |
|
803 | 0 | name = nameBuf; |
804 | 0 | } |
805 | |
|
806 | 0 | if (!strncmp(name, "no-", 3)) |
807 | 0 | { |
808 | 0 | name += 3; |
809 | 0 | value = !value || x265_atobool(value, bError) ? "false" : "true"; |
810 | 0 | } |
811 | 0 | else if (!strncmp(name, "no", 2)) |
812 | 0 | { |
813 | 0 | name += 2; |
814 | 0 | value = !value || x265_atobool(value, bError) ? "false" : "true"; |
815 | 0 | } |
816 | 0 | else if (!value) |
817 | 0 | value = "true"; |
818 | 0 | else if (value[0] == '=') |
819 | 0 | value++; |
820 | |
|
821 | | #if defined(_MSC_VER) |
822 | | #pragma warning(disable: 4127) // conditional expression is constant |
823 | | #endif |
824 | 0 | #define OPT(STR) else if (!strcmp(name, STR)) |
825 | 0 | #define OPT2(STR1, STR2) else if (!strcmp(name, STR1) || !strcmp(name, STR2)) |
826 | |
|
827 | | #ifdef SVT_HEVC |
828 | | if (p->bEnableSvtHevc) |
829 | | { |
830 | | if(svt_param_parse(p, name, value)) |
831 | | { |
832 | | x265_log(p, X265_LOG_ERROR, "Error while parsing params \n"); |
833 | | bError = true; |
834 | | } |
835 | | return bError ? X265_PARAM_BAD_VALUE : 0; |
836 | | } |
837 | | #endif |
838 | |
|
839 | 0 | if (0) ; |
840 | 0 | OPT("asm") |
841 | 0 | { |
842 | 0 | #if X265_ARCH_X86 |
843 | 0 | if (!strcasecmp(value, "avx512")) |
844 | 0 | { |
845 | 0 | p->cpuid = X265_NS::cpu_detect(true); |
846 | 0 | if (!(p->cpuid & X265_CPU_AVX512)) |
847 | 0 | x265_log(p, X265_LOG_WARNING, "AVX512 is not supported\n"); |
848 | 0 | } |
849 | 0 | else |
850 | 0 | { |
851 | 0 | if (bValueWasNull) |
852 | 0 | p->cpuid = atobool(value); |
853 | 0 | else |
854 | 0 | p->cpuid = parseCpuName(value, bError, false); |
855 | 0 | } |
856 | | #else |
857 | | if (bValueWasNull) |
858 | | p->cpuid = atobool(value); |
859 | | else |
860 | | p->cpuid = parseCpuName(value, bError, false); |
861 | | #endif |
862 | 0 | } |
863 | 0 | OPT("fps") |
864 | 0 | { |
865 | 0 | if (sscanf(value, "%u/%u", &p->fpsNum, &p->fpsDenom) == 2) |
866 | 0 | ; |
867 | 0 | else |
868 | 0 | { |
869 | 0 | float fps = (float)atof(value); |
870 | 0 | if (fps > 0 && fps <= INT_MAX / 1000) |
871 | 0 | { |
872 | 0 | p->fpsNum = (int)(fps * 1000 + .5); |
873 | 0 | p->fpsDenom = 1000; |
874 | 0 | } |
875 | 0 | else |
876 | 0 | { |
877 | 0 | p->fpsNum = atoi(value); |
878 | 0 | p->fpsDenom = 1; |
879 | 0 | } |
880 | 0 | } |
881 | 0 | } |
882 | 0 | OPT("frame-threads") p->frameNumThreads = atoi(value); |
883 | 0 | OPT("pmode") p->bDistributeModeAnalysis = atobool(value); |
884 | 0 | OPT("pme") p->bDistributeMotionEstimation = atobool(value); |
885 | 0 | OPT2("level-idc", "level") |
886 | 0 | { |
887 | | /* allow "5.1" or "51", both converted to integer 51 */ |
888 | | /* if level-idc specifies an obviously wrong value in either float or int, |
889 | | throw error consistently. Stronger level checking will be done in encoder_open() */ |
890 | 0 | if (atof(value) < 10) |
891 | 0 | p->levelIdc = (int)(10 * atof(value) + .5); |
892 | 0 | else if (atoi(value) < 100) |
893 | 0 | p->levelIdc = atoi(value); |
894 | 0 | else |
895 | 0 | bError = true; |
896 | 0 | } |
897 | 0 | OPT("high-tier") p->bHighTier = atobool(value); |
898 | 0 | OPT("allow-non-conformance") p->bAllowNonConformance = atobool(value); |
899 | 0 | OPT2("log-level", "log") |
900 | 0 | { |
901 | 0 | p->logLevel = atoi(value); |
902 | 0 | if (bError) |
903 | 0 | { |
904 | 0 | bError = false; |
905 | 0 | p->logLevel = parseName(value, logLevelNames, bError) - 1; |
906 | 0 | } |
907 | 0 | } |
908 | 0 | OPT("cu-stats") p->bLogCuStats = atobool(value); |
909 | 0 | OPT("total-frames") p->totalFrames = atoi(value); |
910 | 0 | OPT("annexb") p->bAnnexB = atobool(value); |
911 | 0 | OPT("repeat-headers") p->bRepeatHeaders = atobool(value); |
912 | 0 | OPT("wpp") p->bEnableWavefront = atobool(value); |
913 | 0 | OPT("ctu") p->maxCUSize = (uint32_t)atoi(value); |
914 | 0 | OPT("min-cu-size") p->minCUSize = (uint32_t)atoi(value); |
915 | 0 | OPT("tu-intra-depth") p->tuQTMaxIntraDepth = (uint32_t)atoi(value); |
916 | 0 | OPT("tu-inter-depth") p->tuQTMaxInterDepth = (uint32_t)atoi(value); |
917 | 0 | OPT("max-tu-size") p->maxTUSize = (uint32_t)atoi(value); |
918 | 0 | OPT("subme") p->subpelRefine = atoi(value); |
919 | 0 | OPT("merange") p->searchRange = atoi(value); |
920 | 0 | OPT("rect") p->bEnableRectInter = atobool(value); |
921 | 0 | OPT("amp") p->bEnableAMP = atobool(value); |
922 | 0 | OPT("max-merge") p->maxNumMergeCand = (uint32_t)atoi(value); |
923 | 0 | OPT("temporal-mvp") p->bEnableTemporalMvp = atobool(value); |
924 | 0 | OPT("early-skip") p->bEnableEarlySkip = atobool(value); |
925 | 0 | OPT("rskip") p->recursionSkipMode = atoi(value); |
926 | 0 | OPT("rdpenalty") p->rdPenalty = atoi(value); |
927 | 0 | OPT("tskip") p->bEnableTransformSkip = atobool(value); |
928 | 0 | OPT("no-tskip-fast") p->bEnableTSkipFast = atobool(value); |
929 | 0 | OPT("tskip-fast") p->bEnableTSkipFast = atobool(value); |
930 | 0 | OPT("strong-intra-smoothing") p->bEnableStrongIntraSmoothing = atobool(value); |
931 | 0 | OPT("lossless") p->bLossless = atobool(value); |
932 | 0 | OPT("cu-lossless") p->bCULossless = atobool(value); |
933 | 0 | OPT2("constrained-intra", "cip") p->bEnableConstrainedIntra = atobool(value); |
934 | 0 | OPT("fast-intra") p->bEnableFastIntra = atobool(value); |
935 | 0 | OPT("open-gop") p->bOpenGOP = atobool(value); |
936 | 0 | OPT("intra-refresh") p->bIntraRefresh = atobool(value); |
937 | 0 | OPT("lookahead-slices") p->lookaheadSlices = atoi(value); |
938 | 0 | OPT("scenecut") |
939 | 0 | { |
940 | 0 | p->scenecutThreshold = atobool(value); |
941 | 0 | if (bError || p->scenecutThreshold) |
942 | 0 | { |
943 | 0 | bError = false; |
944 | 0 | p->scenecutThreshold = atoi(value); |
945 | 0 | p->bHistBasedSceneCut = 0; |
946 | 0 | } |
947 | 0 | } |
948 | 0 | OPT("temporal-layers") p->bEnableTemporalSubLayers = atobool(value); |
949 | 0 | OPT("keyint") p->keyframeMax = atoi(value); |
950 | 0 | OPT("min-keyint") p->keyframeMin = atoi(value); |
951 | 0 | OPT("rc-lookahead") p->lookaheadDepth = atoi(value); |
952 | 0 | OPT("bframes") p->bframes = atoi(value); |
953 | 0 | OPT("bframe-bias") p->bFrameBias = atoi(value); |
954 | 0 | OPT("b-adapt") |
955 | 0 | { |
956 | 0 | p->bFrameAdaptive = atobool(value); |
957 | 0 | if (bError || p->bFrameAdaptive) |
958 | 0 | { |
959 | 0 | bError = false; |
960 | 0 | p->bFrameAdaptive = atoi(value); |
961 | 0 | } |
962 | 0 | } |
963 | 0 | OPT("interlace") |
964 | 0 | { |
965 | 0 | p->interlaceMode = atobool(value); |
966 | 0 | if (bError || p->interlaceMode) |
967 | 0 | { |
968 | 0 | bError = false; |
969 | 0 | p->interlaceMode = parseName(value, x265_interlace_names, bError); |
970 | 0 | } |
971 | 0 | } |
972 | 0 | OPT("ref") p->maxNumReferences = atoi(value); |
973 | 0 | OPT("limit-refs") p->limitReferences = atoi(value); |
974 | 0 | OPT("limit-modes") p->limitModes = atobool(value); |
975 | 0 | OPT("weightp") p->bEnableWeightedPred = atobool(value); |
976 | 0 | OPT("weightb") p->bEnableWeightedBiPred = atobool(value); |
977 | 0 | OPT("cbqpoffs") p->cbQpOffset = atoi(value); |
978 | 0 | OPT("crqpoffs") p->crQpOffset = atoi(value); |
979 | 0 | OPT("rd") p->rdLevel = atoi(value); |
980 | 0 | OPT2("rdoq", "rdoq-level") |
981 | 0 | { |
982 | 0 | int bval = atobool(value); |
983 | 0 | if (bError || bval) |
984 | 0 | { |
985 | 0 | bError = false; |
986 | 0 | p->rdoqLevel = atoi(value); |
987 | 0 | } |
988 | 0 | else |
989 | 0 | p->rdoqLevel = 0; |
990 | 0 | } |
991 | 0 | OPT("psy-rd") |
992 | 0 | { |
993 | 0 | int bval = atobool(value); |
994 | 0 | if (bError || bval) |
995 | 0 | { |
996 | 0 | bError = false; |
997 | 0 | p->psyRd = atof(value); |
998 | 0 | } |
999 | 0 | else |
1000 | 0 | p->psyRd = 0.0; |
1001 | 0 | } |
1002 | 0 | OPT("psy-rdoq") |
1003 | 0 | { |
1004 | 0 | int bval = atobool(value); |
1005 | 0 | if (bError || bval) |
1006 | 0 | { |
1007 | 0 | bError = false; |
1008 | 0 | p->psyRdoq = atof(value); |
1009 | 0 | } |
1010 | 0 | else |
1011 | 0 | p->psyRdoq = 0.0; |
1012 | 0 | } |
1013 | 0 | OPT("rd-refine") p->bEnableRdRefine = atobool(value); |
1014 | 0 | OPT("signhide") p->bEnableSignHiding = atobool(value); |
1015 | 0 | OPT("b-intra") p->bIntraInBFrames = atobool(value); |
1016 | 0 | OPT("lft") p->bEnableLoopFilter = atobool(value); /* DEPRECATED */ |
1017 | 0 | OPT("deblock") |
1018 | 0 | { |
1019 | 0 | if (2 == sscanf(value, "%d:%d", &p->deblockingFilterTCOffset, &p->deblockingFilterBetaOffset) || |
1020 | 0 | 2 == sscanf(value, "%d,%d", &p->deblockingFilterTCOffset, &p->deblockingFilterBetaOffset)) |
1021 | 0 | { |
1022 | 0 | p->bEnableLoopFilter = true; |
1023 | 0 | } |
1024 | 0 | else if (sscanf(value, "%d", &p->deblockingFilterTCOffset)) |
1025 | 0 | { |
1026 | 0 | p->bEnableLoopFilter = 1; |
1027 | 0 | p->deblockingFilterBetaOffset = p->deblockingFilterTCOffset; |
1028 | 0 | } |
1029 | 0 | else |
1030 | 0 | p->bEnableLoopFilter = atobool(value); |
1031 | 0 | } |
1032 | 0 | OPT("sao") p->bEnableSAO = atobool(value); |
1033 | 0 | OPT("sao-non-deblock") p->bSaoNonDeblocked = atobool(value); |
1034 | 0 | OPT("ssim") p->bEnableSsim = atobool(value); |
1035 | 0 | OPT("psnr") p->bEnablePsnr = atobool(value); |
1036 | 0 | OPT("hash") p->decodedPictureHashSEI = atoi(value); |
1037 | 0 | OPT("aud") p->bEnableAccessUnitDelimiters = atobool(value); |
1038 | 0 | OPT("info") p->bEmitInfoSEI = atobool(value); |
1039 | 0 | OPT("b-pyramid") p->bBPyramid = atobool(value); |
1040 | 0 | OPT("hrd") p->bEmitHRDSEI = atobool(value); |
1041 | 0 | OPT2("ipratio", "ip-factor") p->rc.ipFactor = atof(value); |
1042 | 0 | OPT2("pbratio", "pb-factor") p->rc.pbFactor = atof(value); |
1043 | 0 | OPT("qcomp") p->rc.qCompress = atof(value); |
1044 | 0 | OPT("qpstep") p->rc.qpStep = atoi(value); |
1045 | 0 | OPT("cplxblur") p->rc.complexityBlur = atof(value); |
1046 | 0 | OPT("qblur") p->rc.qblur = atof(value); |
1047 | 0 | OPT("aq-mode") p->rc.aqMode = atoi(value); |
1048 | 0 | OPT("aq-strength") p->rc.aqStrength = atof(value); |
1049 | 0 | OPT("vbv-maxrate") p->rc.vbvMaxBitrate = atoi(value); |
1050 | 0 | OPT("vbv-bufsize") p->rc.vbvBufferSize = atoi(value); |
1051 | 0 | OPT("vbv-init") p->rc.vbvBufferInit = atof(value); |
1052 | 0 | OPT("crf-max") p->rc.rfConstantMax = atof(value); |
1053 | 0 | OPT("crf-min") p->rc.rfConstantMin = atof(value); |
1054 | 0 | OPT("qpmax") p->rc.qpMax = atoi(value); |
1055 | 0 | OPT("crf") |
1056 | 0 | { |
1057 | 0 | p->rc.rfConstant = atof(value); |
1058 | 0 | p->rc.rateControlMode = X265_RC_CRF; |
1059 | 0 | } |
1060 | 0 | OPT("bitrate") |
1061 | 0 | { |
1062 | 0 | p->rc.bitrate = atoi(value); |
1063 | 0 | p->rc.rateControlMode = X265_RC_ABR; |
1064 | 0 | } |
1065 | 0 | OPT("qp") |
1066 | 0 | { |
1067 | 0 | p->rc.qp = atoi(value); |
1068 | 0 | p->rc.rateControlMode = X265_RC_CQP; |
1069 | 0 | } |
1070 | 0 | OPT("rc-grain") p->rc.bEnableGrain = atobool(value); |
1071 | 0 | OPT("zones") |
1072 | 0 | { |
1073 | 0 | p->rc.zoneCount = 1; |
1074 | 0 | const char* c; |
1075 | |
|
1076 | 0 | for (c = value; *c; c++) |
1077 | 0 | p->rc.zoneCount += (*c == '/'); |
1078 | |
|
1079 | 0 | p->rc.zones = X265_MALLOC(x265_zone, p->rc.zoneCount); |
1080 | 0 | c = value; |
1081 | 0 | for (int i = 0; i < p->rc.zoneCount; i++ ) |
1082 | 0 | { |
1083 | 0 | int len; |
1084 | 0 | if (3 == sscanf(c, "%d,%d,q=%d%n", &p->rc.zones[i].startFrame, &p->rc.zones[i].endFrame, &p->rc.zones[i].qp, &len)) |
1085 | 0 | p->rc.zones[i].bForceQp = 1; |
1086 | 0 | else if (3 == sscanf(c, "%d,%d,b=%f%n", &p->rc.zones[i].startFrame, &p->rc.zones[i].endFrame, &p->rc.zones[i].bitrateFactor, &len)) |
1087 | 0 | p->rc.zones[i].bForceQp = 0; |
1088 | 0 | else |
1089 | 0 | { |
1090 | 0 | bError = true; |
1091 | 0 | break; |
1092 | 0 | } |
1093 | 0 | c += len + 1; |
1094 | 0 | } |
1095 | 0 | } |
1096 | 0 | OPT("input-res") bError |= sscanf(value, "%dx%d", &p->sourceWidth, &p->sourceHeight) != 2; |
1097 | 0 | OPT("input-csp") p->internalCsp = parseName(value, x265_source_csp_names, bError); |
1098 | 0 | OPT("me") p->searchMethod = parseName(value, x265_motion_est_names, bError); |
1099 | 0 | OPT("cutree") p->rc.cuTree = atobool(value); |
1100 | 0 | OPT("slow-firstpass") p->rc.bEnableSlowFirstPass = atobool(value); |
1101 | 0 | OPT("strict-cbr") |
1102 | 0 | { |
1103 | 0 | p->rc.bStrictCbr = atobool(value); |
1104 | 0 | p->rc.pbFactor = 1.0; |
1105 | 0 | } |
1106 | 0 | OPT("analysis-reuse-mode") p->analysisReuseMode = parseName(value, x265_analysis_names, bError); /*DEPRECATED*/ |
1107 | 0 | OPT("sar") |
1108 | 0 | { |
1109 | 0 | p->vui.aspectRatioIdc = parseName(value, x265_sar_names, bError); |
1110 | 0 | if (bError) |
1111 | 0 | { |
1112 | 0 | p->vui.aspectRatioIdc = X265_EXTENDED_SAR; |
1113 | 0 | bError = sscanf(value, "%d:%d", &p->vui.sarWidth, &p->vui.sarHeight) != 2; |
1114 | 0 | } |
1115 | 0 | } |
1116 | 0 | OPT("overscan") |
1117 | 0 | { |
1118 | 0 | if (!strcmp(value, "show")) |
1119 | 0 | p->vui.bEnableOverscanInfoPresentFlag = 1; |
1120 | 0 | else if (!strcmp(value, "crop")) |
1121 | 0 | { |
1122 | 0 | p->vui.bEnableOverscanInfoPresentFlag = 1; |
1123 | 0 | p->vui.bEnableOverscanAppropriateFlag = 1; |
1124 | 0 | } |
1125 | 0 | else if (!strcmp(value, "undef")) |
1126 | 0 | p->vui.bEnableOverscanInfoPresentFlag = 0; |
1127 | 0 | else |
1128 | 0 | bError = true; |
1129 | 0 | } |
1130 | 0 | OPT("videoformat") |
1131 | 0 | { |
1132 | 0 | p->vui.bEnableVideoSignalTypePresentFlag = 1; |
1133 | 0 | p->vui.videoFormat = parseName(value, x265_video_format_names, bError); |
1134 | 0 | } |
1135 | 0 | OPT("range") |
1136 | 0 | { |
1137 | 0 | p->vui.bEnableVideoSignalTypePresentFlag = 1; |
1138 | 0 | p->vui.bEnableVideoFullRangeFlag = parseName(value, x265_fullrange_names, bError); |
1139 | 0 | } |
1140 | 0 | OPT("colorprim") |
1141 | 0 | { |
1142 | 0 | p->vui.bEnableVideoSignalTypePresentFlag = 1; |
1143 | 0 | p->vui.bEnableColorDescriptionPresentFlag = 1; |
1144 | 0 | p->vui.colorPrimaries = parseName(value, x265_colorprim_names, bError); |
1145 | 0 | } |
1146 | 0 | OPT("transfer") |
1147 | 0 | { |
1148 | 0 | p->vui.bEnableVideoSignalTypePresentFlag = 1; |
1149 | 0 | p->vui.bEnableColorDescriptionPresentFlag = 1; |
1150 | 0 | p->vui.transferCharacteristics = parseName(value, x265_transfer_names, bError); |
1151 | 0 | } |
1152 | 0 | OPT("colormatrix") |
1153 | 0 | { |
1154 | 0 | p->vui.bEnableVideoSignalTypePresentFlag = 1; |
1155 | 0 | p->vui.bEnableColorDescriptionPresentFlag = 1; |
1156 | 0 | p->vui.matrixCoeffs = parseName(value, x265_colmatrix_names, bError); |
1157 | 0 | } |
1158 | 0 | OPT("chromaloc") |
1159 | 0 | { |
1160 | 0 | p->vui.bEnableChromaLocInfoPresentFlag = 1; |
1161 | 0 | p->vui.chromaSampleLocTypeTopField = atoi(value); |
1162 | 0 | p->vui.chromaSampleLocTypeBottomField = p->vui.chromaSampleLocTypeTopField; |
1163 | 0 | } |
1164 | 0 | OPT2("display-window", "crop-rect") |
1165 | 0 | { |
1166 | 0 | p->vui.bEnableDefaultDisplayWindowFlag = 1; |
1167 | 0 | bError |= sscanf(value, "%d,%d,%d,%d", |
1168 | 0 | &p->vui.defDispWinLeftOffset, |
1169 | 0 | &p->vui.defDispWinTopOffset, |
1170 | 0 | &p->vui.defDispWinRightOffset, |
1171 | 0 | &p->vui.defDispWinBottomOffset) != 4; |
1172 | 0 | } |
1173 | 0 | OPT("nr-intra") p->noiseReductionIntra = atoi(value); |
1174 | 0 | OPT("nr-inter") p->noiseReductionInter = atoi(value); |
1175 | 0 | OPT("pass") |
1176 | 0 | { |
1177 | 0 | int pass = x265_clip3(0, 3, atoi(value)); |
1178 | 0 | p->rc.bStatWrite = pass & 1; |
1179 | 0 | p->rc.bStatRead = pass & 2; |
1180 | 0 | } |
1181 | 0 | OPT("stats") p->rc.statFileName = strdup(value); |
1182 | 0 | OPT("scaling-list") p->scalingLists = strdup(value); |
1183 | 0 | OPT2("pools", "numa-pools") p->numaPools = strdup(value); |
1184 | 0 | OPT("lambda-file") p->rc.lambdaFileName = strdup(value); |
1185 | 0 | OPT("analysis-reuse-file") p->analysisReuseFileName = strdup(value); |
1186 | 0 | OPT("qg-size") p->rc.qgSize = atoi(value); |
1187 | 0 | OPT("master-display") p->masteringDisplayColorVolume = strdup(value); |
1188 | 0 | OPT("max-cll") bError |= sscanf(value, "%hu,%hu", &p->maxCLL, &p->maxFALL) != 2; |
1189 | 0 | OPT("min-luma") p->minLuma = (uint16_t)atoi(value); |
1190 | 0 | OPT("max-luma") p->maxLuma = (uint16_t)atoi(value); |
1191 | 0 | OPT("uhd-bd") p->uhdBluray = atobool(value); |
1192 | 0 | else |
1193 | 0 | bExtraParams = true; |
1194 | | |
1195 | | // solve "fatal error C1061: compiler limit : blocks nested too deeply" |
1196 | 0 | if (bExtraParams) |
1197 | 0 | { |
1198 | 0 | if (0) ; |
1199 | 0 | OPT("csv") p->csvfn = strdup(value); |
1200 | 0 | OPT("csv-log-level") p->csvLogLevel = atoi(value); |
1201 | 0 | OPT("qpmin") p->rc.qpMin = atoi(value); |
1202 | 0 | OPT("analyze-src-pics") p->bSourceReferenceEstimation = atobool(value); |
1203 | 0 | OPT("log2-max-poc-lsb") p->log2MaxPocLsb = atoi(value); |
1204 | 0 | OPT("vui-timing-info") p->bEmitVUITimingInfo = atobool(value); |
1205 | 0 | OPT("vui-hrd-info") p->bEmitVUIHRDInfo = atobool(value); |
1206 | 0 | OPT("slices") p->maxSlices = atoi(value); |
1207 | 0 | OPT("limit-tu") p->limitTU = atoi(value); |
1208 | 0 | OPT("opt-qp-pps") p->bOptQpPPS = atobool(value); |
1209 | 0 | OPT("opt-ref-list-length-pps") p->bOptRefListLengthPPS = atobool(value); |
1210 | 0 | OPT("multi-pass-opt-rps") p->bMultiPassOptRPS = atobool(value); |
1211 | 0 | OPT("scenecut-bias") p->scenecutBias = atof(value); |
1212 | 0 | OPT("hist-scenecut") |
1213 | 0 | { |
1214 | 0 | p->bHistBasedSceneCut = atobool(value); |
1215 | 0 | if (bError) |
1216 | 0 | { |
1217 | 0 | bError = false; |
1218 | 0 | p->bHistBasedSceneCut = 0; |
1219 | 0 | } |
1220 | 0 | if (p->bHistBasedSceneCut) |
1221 | 0 | { |
1222 | 0 | bError = false; |
1223 | 0 | p->scenecutThreshold = 0; |
1224 | 0 | } |
1225 | 0 | } |
1226 | 0 | OPT("hist-threshold") p->edgeTransitionThreshold = atof(value); |
1227 | 0 | OPT("rskip-edge-threshold") p->edgeVarThreshold = atoi(value)/100.0f; |
1228 | 0 | OPT("lookahead-threads") p->lookaheadThreads = atoi(value); |
1229 | 0 | OPT("opt-cu-delta-qp") p->bOptCUDeltaQP = atobool(value); |
1230 | 0 | OPT("multi-pass-opt-analysis") p->analysisMultiPassRefine = atobool(value); |
1231 | 0 | OPT("multi-pass-opt-distortion") p->analysisMultiPassDistortion = atobool(value); |
1232 | 0 | OPT("aq-motion") p->bAQMotion = atobool(value); |
1233 | 0 | OPT("dynamic-rd") p->dynamicRd = atof(value); |
1234 | 0 | OPT("analysis-reuse-level") |
1235 | 0 | { |
1236 | 0 | p->analysisReuseLevel = atoi(value); |
1237 | 0 | p->analysisSaveReuseLevel = atoi(value); |
1238 | 0 | p->analysisLoadReuseLevel = atoi(value); |
1239 | 0 | } |
1240 | 0 | OPT("analysis-save-reuse-level") p->analysisSaveReuseLevel = atoi(value); |
1241 | 0 | OPT("analysis-load-reuse-level") p->analysisLoadReuseLevel = atoi(value); |
1242 | 0 | OPT("ssim-rd") |
1243 | 0 | { |
1244 | 0 | int bval = atobool(value); |
1245 | 0 | if (bError || bval) |
1246 | 0 | { |
1247 | 0 | bError = false; |
1248 | 0 | p->psyRd = 0.0; |
1249 | 0 | p->bSsimRd = atobool(value); |
1250 | 0 | } |
1251 | 0 | } |
1252 | 0 | OPT("hdr") p->bEmitHDR10SEI = atobool(value); /*DEPRECATED*/ |
1253 | 0 | OPT("hdr10") p->bEmitHDR10SEI = atobool(value); |
1254 | 0 | OPT("hdr-opt") p->bHDR10Opt = atobool(value); /*DEPRECATED*/ |
1255 | 0 | OPT("hdr10-opt") p->bHDR10Opt = atobool(value); |
1256 | 0 | OPT("limit-sao") p->bLimitSAO = atobool(value); |
1257 | 0 | OPT("dhdr10-info") p->toneMapFile = strdup(value); |
1258 | 0 | OPT("dhdr10-opt") p->bDhdr10opt = atobool(value); |
1259 | 0 | OPT("idr-recovery-sei") p->bEmitIDRRecoverySEI = atobool(value); |
1260 | 0 | OPT("const-vbv") p->rc.bEnableConstVbv = atobool(value); |
1261 | 0 | OPT("ctu-info") p->bCTUInfo = atoi(value); |
1262 | 0 | OPT("scale-factor") p->scaleFactor = atoi(value); |
1263 | 0 | OPT("refine-intra")p->intraRefine = atoi(value); |
1264 | 0 | OPT("refine-inter")p->interRefine = atoi(value); |
1265 | 0 | OPT("refine-mv")p->mvRefine = atoi(value); |
1266 | 0 | OPT("force-flush")p->forceFlush = atoi(value); |
1267 | 0 | OPT("splitrd-skip") p->bEnableSplitRdSkip = atobool(value); |
1268 | 0 | OPT("lowpass-dct") p->bLowPassDct = atobool(value); |
1269 | 0 | OPT("vbv-end") p->vbvBufferEnd = atof(value); |
1270 | 0 | OPT("vbv-end-fr-adj") p->vbvEndFrameAdjust = atof(value); |
1271 | 0 | OPT("copy-pic") p->bCopyPicToFrame = atobool(value); |
1272 | 0 | OPT("refine-analysis-type") |
1273 | 0 | { |
1274 | 0 | if (strcmp(strdup(value), "avc") == 0) |
1275 | 0 | { |
1276 | 0 | p->bAnalysisType = AVC_INFO; |
1277 | 0 | } |
1278 | 0 | else if (strcmp(strdup(value), "hevc") == 0) |
1279 | 0 | { |
1280 | 0 | p->bAnalysisType = HEVC_INFO; |
1281 | 0 | } |
1282 | 0 | else if (strcmp(strdup(value), "off") == 0) |
1283 | 0 | { |
1284 | 0 | p->bAnalysisType = DEFAULT; |
1285 | 0 | } |
1286 | 0 | else |
1287 | 0 | { |
1288 | 0 | bError = true; |
1289 | 0 | } |
1290 | 0 | } |
1291 | 0 | OPT("gop-lookahead") p->gopLookahead = atoi(value); |
1292 | 0 | OPT("analysis-save") p->analysisSave = strdup(value); |
1293 | 0 | OPT("analysis-load") p->analysisLoad = strdup(value); |
1294 | 0 | OPT("radl") p->radl = atoi(value); |
1295 | 0 | OPT("max-ausize-factor") p->maxAUSizeFactor = atof(value); |
1296 | 0 | OPT("dynamic-refine") p->bDynamicRefine = atobool(value); |
1297 | 0 | OPT("single-sei") p->bSingleSeiNal = atobool(value); |
1298 | 0 | OPT("atc-sei") p->preferredTransferCharacteristics = atoi(value); |
1299 | 0 | OPT("pic-struct") p->pictureStructure = atoi(value); |
1300 | 0 | OPT("chunk-start") p->chunkStart = atoi(value); |
1301 | 0 | OPT("chunk-end") p->chunkEnd = atoi(value); |
1302 | 0 | OPT("nalu-file") p->naluFile = strdup(value); |
1303 | 0 | OPT("dolby-vision-profile") |
1304 | 0 | { |
1305 | 0 | if (atof(value) < 10) |
1306 | 0 | p->dolbyProfile = (int)(10 * atof(value) + .5); |
1307 | 0 | else if (atoi(value) < 100) |
1308 | 0 | p->dolbyProfile = atoi(value); |
1309 | 0 | else |
1310 | 0 | bError = true; |
1311 | 0 | } |
1312 | 0 | OPT("hrd-concat") p->bEnableHRDConcatFlag = atobool(value); |
1313 | 0 | OPT("refine-ctu-distortion") p->ctuDistortionRefine = atoi(value); |
1314 | 0 | OPT("hevc-aq") p->rc.hevcAq = atobool(value); |
1315 | 0 | OPT("qp-adaptation-range") p->rc.qpAdaptationRange = atof(value); |
1316 | | #ifdef SVT_HEVC |
1317 | | OPT("svt") |
1318 | | { |
1319 | | p->bEnableSvtHevc = atobool(value); |
1320 | | if (count > 1 && p->bEnableSvtHevc) |
1321 | | { |
1322 | | x265_log(NULL, X265_LOG_ERROR, "Enable SVT should be the first call to x265_parse_parse \n"); |
1323 | | bError = true; |
1324 | | } |
1325 | | } |
1326 | | OPT("svt-hme") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1327 | | OPT("svt-search-width") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1328 | | OPT("svt-search-height") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1329 | | OPT("svt-compressed-ten-bit-format") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1330 | | OPT("svt-speed-control") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1331 | | OPT("input-depth") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1332 | | OPT("svt-preset-tuner") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1333 | | OPT("svt-hierarchical-level") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1334 | | OPT("svt-base-layer-switch-mode") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1335 | | OPT("svt-pred-struct") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1336 | | OPT("svt-fps-in-vps") x265_log(p, X265_LOG_WARNING, "Option %s is SVT-HEVC Encoder specific; Disabling it here \n", name); |
1337 | | #endif |
1338 | 0 | OPT("selective-sao") |
1339 | 0 | { |
1340 | 0 | p->selectiveSAO = atoi(value); |
1341 | 0 | } |
1342 | 0 | OPT("fades") p->bEnableFades = atobool(value); |
1343 | 0 | OPT("scenecut-aware-qp") p->bEnableSceneCutAwareQp = atobool(value); |
1344 | 0 | OPT("scenecut-window") p->scenecutWindow = atoi(value); |
1345 | 0 | OPT("max-qp-delta") p->maxQpDelta = atoi(value); |
1346 | 0 | OPT("field") p->bField = atobool( value ); |
1347 | 0 | OPT("cll") p->bEmitCLL = atobool(value); |
1348 | 0 | OPT("frame-dup") p->bEnableFrameDuplication = atobool(value); |
1349 | 0 | OPT("dup-threshold") p->dupThreshold = atoi(value); |
1350 | 0 | OPT("hme") p->bEnableHME = atobool(value); |
1351 | 0 | OPT("hme-search") |
1352 | 0 | { |
1353 | 0 | char search[3][5]; |
1354 | 0 | memset(search, '\0', 15 * sizeof(char)); |
1355 | 0 | if(3 == sscanf(value, "%d,%d,%d", &p->hmeSearchMethod[0], &p->hmeSearchMethod[1], &p->hmeSearchMethod[2]) || |
1356 | 0 | 3 == sscanf(value, "%4[^,],%4[^,],%4[^,]", search[0], search[1], search[2])) |
1357 | 0 | { |
1358 | 0 | if(search[0][0]) |
1359 | 0 | for(int level = 0; level < 3; level++) |
1360 | 0 | p->hmeSearchMethod[level] = parseName(search[level], x265_motion_est_names, bError); |
1361 | 0 | } |
1362 | 0 | else if (sscanf(value, "%d", &p->hmeSearchMethod[0]) || sscanf(value, "%s", search[0])) |
1363 | 0 | { |
1364 | 0 | if (search[0][0]) { |
1365 | 0 | p->hmeSearchMethod[0] = parseName(search[0], x265_motion_est_names, bError); |
1366 | 0 | p->hmeSearchMethod[1] = p->hmeSearchMethod[2] = p->hmeSearchMethod[0]; |
1367 | 0 | } |
1368 | 0 | } |
1369 | 0 | p->bEnableHME = true; |
1370 | 0 | } |
1371 | 0 | OPT("hme-range") |
1372 | 0 | { |
1373 | 0 | sscanf(value, "%d,%d,%d", &p->hmeRange[0], &p->hmeRange[1], &p->hmeRange[2]); |
1374 | 0 | p->bEnableHME = true; |
1375 | 0 | } |
1376 | 0 | else |
1377 | 0 | return X265_PARAM_BAD_NAME; |
1378 | 0 | } |
1379 | 0 | #undef OPT |
1380 | 0 | #undef atobool |
1381 | 0 | #undef atoi |
1382 | 0 | #undef atof |
1383 | | |
1384 | 0 | bError |= bValueWasNull && !bNameWasBool; |
1385 | 0 | return bError ? X265_PARAM_BAD_VALUE : 0; |
1386 | 0 | } |
1387 | | |
1388 | | } /* end extern "C" or namespace */ |
1389 | | |
1390 | | namespace X265_NS { |
1391 | | // internal encoder functions |
1392 | | |
1393 | | int x265_atoi(const char* str, bool& bError) |
1394 | 0 | { |
1395 | 0 | char *end; |
1396 | 0 | int v = strtol(str, &end, 0); |
1397 | |
|
1398 | 0 | if (end == str || *end != '\0') |
1399 | 0 | bError = true; |
1400 | 0 | return v; |
1401 | 0 | } |
1402 | | |
1403 | | double x265_atof(const char* str, bool& bError) |
1404 | 0 | { |
1405 | 0 | char *end; |
1406 | 0 | double v = strtod(str, &end); |
1407 | |
|
1408 | 0 | if (end == str || *end != '\0') |
1409 | 0 | bError = true; |
1410 | 0 | return v; |
1411 | 0 | } |
1412 | | |
1413 | | /* cpu name can be: |
1414 | | * auto || true - x265::cpu_detect() |
1415 | | * false || no - disabled |
1416 | | * integer bitmap value |
1417 | | * comma separated list of SIMD names, eg: SSE4.1,XOP */ |
1418 | | int parseCpuName(const char* value, bool& bError, bool bEnableavx512) |
1419 | 0 | { |
1420 | 0 | if (!value) |
1421 | 0 | { |
1422 | 0 | bError = 1; |
1423 | 0 | return 0; |
1424 | 0 | } |
1425 | 0 | int cpu; |
1426 | 0 | if (isdigit(value[0])) |
1427 | 0 | cpu = x265_atoi(value, bError); |
1428 | 0 | else |
1429 | 0 | cpu = !strcmp(value, "auto") || x265_atobool(value, bError) ? X265_NS::cpu_detect(bEnableavx512) : 0; |
1430 | |
|
1431 | 0 | if (bError) |
1432 | 0 | { |
1433 | 0 | char *buf = strdup(value); |
1434 | 0 | char *tok, *saveptr = NULL, *init; |
1435 | 0 | bError = 0; |
1436 | 0 | cpu = 0; |
1437 | 0 | for (init = buf; (tok = strtok_r(init, ",", &saveptr)); init = NULL) |
1438 | 0 | { |
1439 | 0 | int i; |
1440 | 0 | for (i = 0; X265_NS::cpu_names[i].flags && strcasecmp(tok, X265_NS::cpu_names[i].name); i++) |
1441 | 0 | { |
1442 | 0 | } |
1443 | |
|
1444 | 0 | cpu |= X265_NS::cpu_names[i].flags; |
1445 | 0 | if (!X265_NS::cpu_names[i].flags) |
1446 | 0 | bError = 1; |
1447 | 0 | } |
1448 | |
|
1449 | 0 | free(buf); |
1450 | 0 | if ((cpu & X265_CPU_SSSE3) && !(cpu & X265_CPU_SSE2_IS_SLOW)) |
1451 | 0 | cpu |= X265_CPU_SSE2_IS_FAST; |
1452 | 0 | } |
1453 | |
|
1454 | 0 | return cpu; |
1455 | 0 | } |
1456 | | |
1457 | | static const int fixedRatios[][2] = |
1458 | | { |
1459 | | { 1, 1 }, |
1460 | | { 12, 11 }, |
1461 | | { 10, 11 }, |
1462 | | { 16, 11 }, |
1463 | | { 40, 33 }, |
1464 | | { 24, 11 }, |
1465 | | { 20, 11 }, |
1466 | | { 32, 11 }, |
1467 | | { 80, 33 }, |
1468 | | { 18, 11 }, |
1469 | | { 15, 11 }, |
1470 | | { 64, 33 }, |
1471 | | { 160, 99 }, |
1472 | | { 4, 3 }, |
1473 | | { 3, 2 }, |
1474 | | { 2, 1 }, |
1475 | | }; |
1476 | | |
1477 | | void setParamAspectRatio(x265_param* p, int width, int height) |
1478 | 0 | { |
1479 | 0 | p->vui.aspectRatioIdc = X265_EXTENDED_SAR; |
1480 | 0 | p->vui.sarWidth = width; |
1481 | 0 | p->vui.sarHeight = height; |
1482 | 0 | for (size_t i = 0; i < sizeof(fixedRatios) / sizeof(fixedRatios[0]); i++) |
1483 | 0 | { |
1484 | 0 | if (width == fixedRatios[i][0] && height == fixedRatios[i][1]) |
1485 | 0 | { |
1486 | 0 | p->vui.aspectRatioIdc = (int)i + 1; |
1487 | 0 | return; |
1488 | 0 | } |
1489 | 0 | } |
1490 | 0 | } |
1491 | | |
1492 | | void getParamAspectRatio(x265_param* p, int& width, int& height) |
1493 | 0 | { |
1494 | 0 | if (!p->vui.aspectRatioIdc) |
1495 | 0 | width = height = 0; |
1496 | 0 | else if ((size_t)p->vui.aspectRatioIdc <= sizeof(fixedRatios) / sizeof(fixedRatios[0])) |
1497 | 0 | { |
1498 | 0 | width = fixedRatios[p->vui.aspectRatioIdc - 1][0]; |
1499 | 0 | height = fixedRatios[p->vui.aspectRatioIdc - 1][1]; |
1500 | 0 | } |
1501 | 0 | else if (p->vui.aspectRatioIdc == X265_EXTENDED_SAR) |
1502 | 0 | { |
1503 | 0 | width = p->vui.sarWidth; |
1504 | 0 | height = p->vui.sarHeight; |
1505 | 0 | } |
1506 | 0 | else |
1507 | 0 | width = height = 0; |
1508 | 0 | } |
1509 | | |
1510 | | static inline int _confirm(x265_param* param, bool bflag, const char* message) |
1511 | 0 | { |
1512 | 0 | if (!bflag) |
1513 | 0 | return 0; |
1514 | | |
1515 | 0 | x265_log(param, X265_LOG_ERROR, "%s\n", message); |
1516 | 0 | return 1; |
1517 | 0 | } |
1518 | | |
1519 | | int x265_check_params(x265_param* param) |
1520 | 0 | { |
1521 | 0 | #define CHECK(expr, msg) check_failed |= _confirm(param, expr, msg) |
1522 | 0 | int check_failed = 0; /* abort if there is a fatal configuration problem */ |
1523 | 0 | CHECK(param->uhdBluray == 1 && (X265_DEPTH != 10 || param->internalCsp != 1 || param->interlaceMode != 0), |
1524 | 0 | "uhd-bd: bit depth, chroma subsample, source picture type must be 10, 4:2:0, progressive"); |
1525 | 0 | CHECK(param->maxCUSize != 64 && param->maxCUSize != 32 && param->maxCUSize != 16, |
1526 | 0 | "max cu size must be 16, 32, or 64"); |
1527 | 0 | if (check_failed == 1) |
1528 | 0 | return check_failed; |
1529 | | |
1530 | 0 | uint32_t maxLog2CUSize = (uint32_t)g_log2Size[param->maxCUSize]; |
1531 | 0 | uint32_t tuQTMaxLog2Size = X265_MIN(maxLog2CUSize, 5); |
1532 | 0 | uint32_t tuQTMinLog2Size = 2; //log2(4) |
1533 | |
|
1534 | 0 | CHECK((param->maxSlices > 1) && !param->bEnableWavefront, |
1535 | 0 | "Multiple-Slices mode must be enable Wavefront Parallel Processing (--wpp)"); |
1536 | 0 | CHECK(param->internalBitDepth != X265_DEPTH, |
1537 | 0 | "internalBitDepth must match compiled bit depth"); |
1538 | 0 | CHECK(param->minCUSize != 32 && param->minCUSize != 16 && param->minCUSize != 8, |
1539 | 0 | "minimim CU size must be 8, 16 or 32"); |
1540 | 0 | CHECK(param->minCUSize > param->maxCUSize, |
1541 | 0 | "min CU size must be less than or equal to max CU size"); |
1542 | 0 | CHECK(param->rc.qp < -6 * (param->internalBitDepth - 8) || param->rc.qp > QP_MAX_SPEC, |
1543 | 0 | "QP exceeds supported range (-QpBDOffsety to 51)"); |
1544 | 0 | CHECK(param->fpsNum == 0 || param->fpsDenom == 0, |
1545 | 0 | "Frame rate numerator and denominator must be specified"); |
1546 | 0 | CHECK(param->interlaceMode < 0 || param->interlaceMode > 2, |
1547 | 0 | "Interlace mode must be 0 (progressive) 1 (top-field first) or 2 (bottom field first)"); |
1548 | 0 | CHECK(param->searchMethod < 0 || param->searchMethod > X265_FULL_SEARCH, |
1549 | 0 | "Search method is not supported value (0:DIA 1:HEX 2:UMH 3:HM 4:SEA 5:FULL)"); |
1550 | 0 | CHECK(param->searchRange < 0, |
1551 | 0 | "Search Range must be more than 0"); |
1552 | 0 | CHECK(param->searchRange >= 32768, |
1553 | 0 | "Search Range must be less than 32768"); |
1554 | 0 | CHECK(param->subpelRefine > X265_MAX_SUBPEL_LEVEL, |
1555 | 0 | "subme must be less than or equal to X265_MAX_SUBPEL_LEVEL (7)"); |
1556 | 0 | CHECK(param->subpelRefine < 0, |
1557 | 0 | "subme must be greater than or equal to 0"); |
1558 | 0 | CHECK(param->limitReferences > 3, |
1559 | 0 | "limitReferences must be 0, 1, 2 or 3"); |
1560 | 0 | CHECK(param->limitModes > 1, |
1561 | 0 | "limitRectAmp must be 0, 1"); |
1562 | 0 | CHECK(param->frameNumThreads < 0 || param->frameNumThreads > X265_MAX_FRAME_THREADS, |
1563 | 0 | "frameNumThreads (--frame-threads) must be [0 .. X265_MAX_FRAME_THREADS)"); |
1564 | 0 | CHECK(param->cbQpOffset < -12, "Min. Chroma Cb QP Offset is -12"); |
1565 | 0 | CHECK(param->cbQpOffset > 12, "Max. Chroma Cb QP Offset is 12"); |
1566 | 0 | CHECK(param->crQpOffset < -12, "Min. Chroma Cr QP Offset is -12"); |
1567 | 0 | CHECK(param->crQpOffset > 12, "Max. Chroma Cr QP Offset is 12"); |
1568 | |
|
1569 | 0 | CHECK(tuQTMaxLog2Size > maxLog2CUSize, |
1570 | 0 | "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller."); |
1571 | |
|
1572 | 0 | CHECK(param->tuQTMaxInterDepth < 1 || param->tuQTMaxInterDepth > 4, |
1573 | 0 | "QuadtreeTUMaxDepthInter must be greater than 0 and less than 5"); |
1574 | 0 | CHECK(maxLog2CUSize < tuQTMinLog2Size + param->tuQTMaxInterDepth - 1, |
1575 | 0 | "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1"); |
1576 | 0 | CHECK(param->tuQTMaxIntraDepth < 1 || param->tuQTMaxIntraDepth > 4, |
1577 | 0 | "QuadtreeTUMaxDepthIntra must be greater 0 and less than 5"); |
1578 | 0 | CHECK(maxLog2CUSize < tuQTMinLog2Size + param->tuQTMaxIntraDepth - 1, |
1579 | 0 | "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1"); |
1580 | 0 | CHECK((param->maxTUSize != 32 && param->maxTUSize != 16 && param->maxTUSize != 8 && param->maxTUSize != 4), |
1581 | 0 | "max TU size must be 4, 8, 16, or 32"); |
1582 | 0 | CHECK(param->limitTU > 4, "Invalid limit-tu option, limit-TU must be between 0 and 4"); |
1583 | 0 | CHECK(param->maxNumMergeCand < 1, "MaxNumMergeCand must be 1 or greater."); |
1584 | 0 | CHECK(param->maxNumMergeCand > 5, "MaxNumMergeCand must be 5 or smaller."); |
1585 | |
|
1586 | 0 | CHECK(param->maxNumReferences < 1, "maxNumReferences must be 1 or greater."); |
1587 | 0 | CHECK(param->maxNumReferences > MAX_NUM_REF, "maxNumReferences must be 16 or smaller."); |
1588 | |
|
1589 | 0 | CHECK(param->sourceWidth < (int)param->maxCUSize || param->sourceHeight < (int)param->maxCUSize, |
1590 | 0 | "Picture size must be at least one CTU"); |
1591 | 0 | CHECK(param->internalCsp < X265_CSP_I400 || X265_CSP_I444 < param->internalCsp, |
1592 | 0 | "chroma subsampling must be i400 (4:0:0 monochrome), i420 (4:2:0 default), i422 (4:2:0), i444 (4:4:4)"); |
1593 | 0 | CHECK(param->sourceWidth & !!CHROMA_H_SHIFT(param->internalCsp), |
1594 | 0 | "Picture width must be an integer multiple of the specified chroma subsampling"); |
1595 | 0 | CHECK(param->sourceHeight & !!CHROMA_V_SHIFT(param->internalCsp), |
1596 | 0 | "Picture height must be an integer multiple of the specified chroma subsampling"); |
1597 | |
|
1598 | 0 | CHECK(param->rc.rateControlMode > X265_RC_CRF || param->rc.rateControlMode < X265_RC_ABR, |
1599 | 0 | "Rate control mode is out of range"); |
1600 | 0 | CHECK(param->rdLevel < 1 || param->rdLevel > 6, |
1601 | 0 | "RD Level is out of range"); |
1602 | 0 | CHECK(param->rdoqLevel < 0 || param->rdoqLevel > 2, |
1603 | 0 | "RDOQ Level is out of range"); |
1604 | 0 | CHECK(param->dynamicRd < 0 || param->dynamicRd > x265_ADAPT_RD_STRENGTH, |
1605 | 0 | "Dynamic RD strength must be between 0 and 4"); |
1606 | 0 | CHECK(param->recursionSkipMode > 2 || param->recursionSkipMode < 0, |
1607 | 0 | "Invalid Recursion skip mode. Valid modes 0,1,2"); |
1608 | 0 | if (param->recursionSkipMode == EDGE_BASED_RSKIP) |
1609 | 0 | { |
1610 | 0 | CHECK(param->edgeVarThreshold < 0.0f || param->edgeVarThreshold > 1.0f, |
1611 | 0 | "Minimum edge density percentage for a CU should be an integer between 0 to 100"); |
1612 | 0 | } |
1613 | 0 | CHECK(param->bframes && param->bframes >= param->lookaheadDepth && !param->rc.bStatRead, |
1614 | 0 | "Lookahead depth must be greater than the max consecutive bframe count"); |
1615 | 0 | CHECK(param->bframes < 0, |
1616 | 0 | "bframe count should be greater than zero"); |
1617 | 0 | CHECK(param->bframes > X265_BFRAME_MAX, |
1618 | 0 | "max consecutive bframe count must be 16 or smaller"); |
1619 | 0 | CHECK(param->lookaheadDepth > X265_LOOKAHEAD_MAX, |
1620 | 0 | "Lookahead depth must be less than 256"); |
1621 | 0 | CHECK(param->lookaheadSlices > 16 || param->lookaheadSlices < 0, |
1622 | 0 | "Lookahead slices must between 0 and 16"); |
1623 | 0 | CHECK(param->rc.aqMode < X265_AQ_NONE || X265_AQ_EDGE < param->rc.aqMode, |
1624 | 0 | "Aq-Mode is out of range"); |
1625 | 0 | CHECK(param->rc.aqStrength < 0 || param->rc.aqStrength > 3, |
1626 | 0 | "Aq-Strength is out of range"); |
1627 | 0 | CHECK(param->rc.qpAdaptationRange < 1.0f || param->rc.qpAdaptationRange > 6.0f, |
1628 | 0 | "qp adaptation range is out of range"); |
1629 | 0 | CHECK(param->deblockingFilterTCOffset < -6 || param->deblockingFilterTCOffset > 6, |
1630 | 0 | "deblocking filter tC offset must be in the range of -6 to +6"); |
1631 | 0 | CHECK(param->deblockingFilterBetaOffset < -6 || param->deblockingFilterBetaOffset > 6, |
1632 | 0 | "deblocking filter Beta offset must be in the range of -6 to +6"); |
1633 | 0 | CHECK(param->psyRd < 0 || 5.0 < param->psyRd, "Psy-rd strength must be between 0 and 5.0"); |
1634 | 0 | CHECK(param->psyRdoq < 0 || 50.0 < param->psyRdoq, "Psy-rdoq strength must be between 0 and 50.0"); |
1635 | 0 | CHECK(param->bEnableWavefront < 0, "WaveFrontSynchro cannot be negative"); |
1636 | 0 | CHECK((param->vui.aspectRatioIdc < 0 |
1637 | 0 | || param->vui.aspectRatioIdc > 16) |
1638 | 0 | && param->vui.aspectRatioIdc != X265_EXTENDED_SAR, |
1639 | 0 | "Sample Aspect Ratio must be 0-16 or 255"); |
1640 | 0 | CHECK(param->vui.aspectRatioIdc == X265_EXTENDED_SAR && param->vui.sarWidth <= 0, |
1641 | 0 | "Sample Aspect Ratio width must be greater than 0"); |
1642 | 0 | CHECK(param->vui.aspectRatioIdc == X265_EXTENDED_SAR && param->vui.sarHeight <= 0, |
1643 | 0 | "Sample Aspect Ratio height must be greater than 0"); |
1644 | 0 | CHECK(param->vui.videoFormat < 0 || param->vui.videoFormat > 5, |
1645 | 0 | "Video Format must be component," |
1646 | 0 | " pal, ntsc, secam, mac or undef"); |
1647 | 0 | CHECK(param->vui.colorPrimaries < 0 |
1648 | 0 | || param->vui.colorPrimaries > 12 |
1649 | 0 | || param->vui.colorPrimaries == 3, |
1650 | 0 | "Color Primaries must be undef, bt709, bt470m," |
1651 | 0 | " bt470bg, smpte170m, smpte240m, film, bt2020, smpte-st-428, smpte-rp-431 or smpte-eg-432"); |
1652 | 0 | CHECK(param->vui.transferCharacteristics < 0 |
1653 | 0 | || param->vui.transferCharacteristics > 18 |
1654 | 0 | || param->vui.transferCharacteristics == 3, |
1655 | 0 | "Transfer Characteristics must be undef, bt709, bt470m, bt470bg," |
1656 | 0 | " smpte170m, smpte240m, linear, log100, log316, iec61966-2-4, bt1361e," |
1657 | 0 | " iec61966-2-1, bt2020-10, bt2020-12, smpte-st-2084, smpte-st-428 or arib-std-b67"); |
1658 | 0 | CHECK(param->vui.matrixCoeffs < 0 |
1659 | 0 | || param->vui.matrixCoeffs > 14 |
1660 | 0 | || param->vui.matrixCoeffs == 3, |
1661 | 0 | "Matrix Coefficients must be undef, bt709, fcc, bt470bg, smpte170m," |
1662 | 0 | " smpte240m, GBR, YCgCo, bt2020nc, bt2020c, smpte-st-2085, chroma-nc, chroma-c or ictcp"); |
1663 | 0 | CHECK(param->vui.chromaSampleLocTypeTopField < 0 |
1664 | 0 | || param->vui.chromaSampleLocTypeTopField > 5, |
1665 | 0 | "Chroma Sample Location Type Top Field must be 0-5"); |
1666 | 0 | CHECK(param->vui.chromaSampleLocTypeBottomField < 0 |
1667 | 0 | || param->vui.chromaSampleLocTypeBottomField > 5, |
1668 | 0 | "Chroma Sample Location Type Bottom Field must be 0-5"); |
1669 | 0 | CHECK(param->vui.defDispWinLeftOffset < 0, |
1670 | 0 | "Default Display Window Left Offset must be 0 or greater"); |
1671 | 0 | CHECK(param->vui.defDispWinRightOffset < 0, |
1672 | 0 | "Default Display Window Right Offset must be 0 or greater"); |
1673 | 0 | CHECK(param->vui.defDispWinTopOffset < 0, |
1674 | 0 | "Default Display Window Top Offset must be 0 or greater"); |
1675 | 0 | CHECK(param->vui.defDispWinBottomOffset < 0, |
1676 | 0 | "Default Display Window Bottom Offset must be 0 or greater"); |
1677 | 0 | CHECK(param->rc.rfConstant < -6 * (param->internalBitDepth - 8) || param->rc.rfConstant > 51, |
1678 | 0 | "Valid quality based range: -qpBDOffsetY to 51"); |
1679 | 0 | CHECK(param->rc.rfConstantMax < -6 * (param->internalBitDepth - 8) || param->rc.rfConstantMax > 51, |
1680 | 0 | "Valid quality based range: -qpBDOffsetY to 51"); |
1681 | 0 | CHECK(param->rc.rfConstantMin < -6 * (param->internalBitDepth - 8) || param->rc.rfConstantMin > 51, |
1682 | 0 | "Valid quality based range: -qpBDOffsetY to 51"); |
1683 | 0 | CHECK(param->bFrameAdaptive < 0 || param->bFrameAdaptive > 2, |
1684 | 0 | "Valid adaptive b scheduling values 0 - none, 1 - fast, 2 - full"); |
1685 | 0 | CHECK(param->logLevel<-1 || param->logLevel> X265_LOG_FULL, |
1686 | 0 | "Valid Logging level -1:none 0:error 1:warning 2:info 3:debug 4:full"); |
1687 | 0 | CHECK(param->scenecutThreshold < 0, |
1688 | 0 | "scenecutThreshold must be greater than 0"); |
1689 | 0 | CHECK(param->scenecutBias < 0 || 100 < param->scenecutBias, |
1690 | 0 | "scenecut-bias must be between 0 and 100"); |
1691 | 0 | CHECK(param->edgeTransitionThreshold < 0.0 || 2.0 < param->edgeTransitionThreshold, |
1692 | 0 | "hist-threshold must be between 0.0 and 2.0"); |
1693 | 0 | CHECK(param->radl < 0 || param->radl > param->bframes, |
1694 | 0 | "radl must be between 0 and bframes"); |
1695 | 0 | CHECK(param->rdPenalty < 0 || param->rdPenalty > 2, |
1696 | 0 | "Valid penalty for 32x32 intra TU in non-I slices. 0:disabled 1:RD-penalty 2:maximum"); |
1697 | 0 | CHECK(param->keyframeMax < -1, |
1698 | 0 | "Invalid max IDR period in frames. value should be greater than -1"); |
1699 | 0 | CHECK(param->gopLookahead < -1, |
1700 | 0 | "GOP lookahead must be greater than -1"); |
1701 | 0 | CHECK(param->decodedPictureHashSEI < 0 || param->decodedPictureHashSEI > 3, |
1702 | 0 | "Invalid hash option. Decoded Picture Hash SEI 0: disabled, 1: MD5, 2: CRC, 3: Checksum"); |
1703 | 0 | CHECK(param->rc.vbvBufferSize < 0, |
1704 | 0 | "Size of the vbv buffer can not be less than zero"); |
1705 | 0 | CHECK(param->rc.vbvMaxBitrate < 0, |
1706 | 0 | "Maximum local bit rate can not be less than zero"); |
1707 | 0 | CHECK(param->rc.vbvBufferInit < 0, |
1708 | 0 | "Valid initial VBV buffer occupancy must be a fraction 0 - 1, or size in kbits"); |
1709 | 0 | CHECK(param->vbvBufferEnd < 0, |
1710 | 0 | "Valid final VBV buffer emptiness must be a fraction 0 - 1, or size in kbits"); |
1711 | 0 | CHECK(param->vbvEndFrameAdjust < 0, |
1712 | 0 | "Valid vbv-end-fr-adj must be a fraction 0 - 1"); |
1713 | 0 | CHECK(!param->totalFrames && param->vbvEndFrameAdjust, |
1714 | 0 | "vbv-end-fr-adj cannot be enabled when total number of frames is unknown"); |
1715 | 0 | CHECK(param->rc.bitrate < 0, |
1716 | 0 | "Target bitrate can not be less than zero"); |
1717 | 0 | CHECK(param->rc.qCompress < 0.5 || param->rc.qCompress > 1.0, |
1718 | 0 | "qCompress must be between 0.5 and 1.0"); |
1719 | 0 | if (param->noiseReductionIntra) |
1720 | 0 | CHECK(0 > param->noiseReductionIntra || param->noiseReductionIntra > 2000, "Valid noise reduction range 0 - 2000"); |
1721 | 0 | if (param->noiseReductionInter) |
1722 | 0 | CHECK(0 > param->noiseReductionInter || param->noiseReductionInter > 2000, "Valid noise reduction range 0 - 2000"); |
1723 | 0 | CHECK(param->rc.rateControlMode == X265_RC_CQP && param->rc.bStatRead, |
1724 | 0 | "Constant QP is incompatible with 2pass"); |
1725 | 0 | CHECK(param->rc.bStrictCbr && (param->rc.bitrate <= 0 || param->rc.vbvBufferSize <=0), |
1726 | 0 | "Strict-cbr cannot be applied without specifying target bitrate or vbv bufsize"); |
1727 | 0 | CHECK(param->analysisSave && (param->analysisSaveReuseLevel < 0 || param->analysisSaveReuseLevel > 10), |
1728 | 0 | "Invalid analysis save refine level. Value must be between 1 and 10 (inclusive)"); |
1729 | 0 | CHECK(param->analysisLoad && (param->analysisLoadReuseLevel < 0 || param->analysisLoadReuseLevel > 10), |
1730 | 0 | "Invalid analysis load refine level. Value must be between 1 and 10 (inclusive)"); |
1731 | 0 | CHECK(param->analysisLoad && (param->mvRefine < 1 || param->mvRefine > 3), |
1732 | 0 | "Invalid mv refinement level. Value must be between 1 and 3 (inclusive)"); |
1733 | 0 | CHECK(param->scaleFactor > 2, "Invalid scale-factor. Supports factor <= 2"); |
1734 | 0 | CHECK(param->rc.qpMax < QP_MIN || param->rc.qpMax > QP_MAX_MAX, |
1735 | 0 | "qpmax exceeds supported range (0 to 69)"); |
1736 | 0 | CHECK(param->rc.qpMin < QP_MIN || param->rc.qpMin > QP_MAX_MAX, |
1737 | 0 | "qpmin exceeds supported range (0 to 69)"); |
1738 | 0 | CHECK(param->log2MaxPocLsb < 4 || param->log2MaxPocLsb > 16, |
1739 | 0 | "Supported range for log2MaxPocLsb is 4 to 16"); |
1740 | 0 | CHECK(param->bCTUInfo < 0 || (param->bCTUInfo != 0 && param->bCTUInfo != 1 && param->bCTUInfo != 2 && param->bCTUInfo != 4 && param->bCTUInfo != 6) || param->bCTUInfo > 6, |
1741 | 0 | "Supported values for bCTUInfo are 0, 1, 2, 4, 6"); |
1742 | 0 | CHECK(param->interRefine > 3 || param->interRefine < 0, |
1743 | 0 | "Invalid refine-inter value, refine-inter levels 0 to 3 supported"); |
1744 | 0 | CHECK(param->intraRefine > 4 || param->intraRefine < 0, |
1745 | 0 | "Invalid refine-intra value, refine-intra levels 0 to 3 supported"); |
1746 | 0 | CHECK(param->ctuDistortionRefine < 0 || param->ctuDistortionRefine > 1, |
1747 | 0 | "Invalid refine-ctu-distortion value, must be either 0 or 1"); |
1748 | 0 | CHECK(param->maxAUSizeFactor < 0.5 || param->maxAUSizeFactor > 1.0, |
1749 | 0 | "Supported factor for controlling max AU size is from 0.5 to 1"); |
1750 | 0 | CHECK((param->dolbyProfile != 0) && (param->dolbyProfile != 50) && (param->dolbyProfile != 81) && (param->dolbyProfile != 82), |
1751 | 0 | "Unsupported Dolby Vision profile, only profile 5, profile 8.1 and profile 8.2 enabled"); |
1752 | 0 | CHECK(param->dupThreshold < 1 || 99 < param->dupThreshold, |
1753 | 0 | "Invalid frame-duplication threshold. Value must be between 1 and 99."); |
1754 | 0 | if (param->dolbyProfile) |
1755 | 0 | { |
1756 | 0 | CHECK((param->rc.vbvMaxBitrate <= 0 || param->rc.vbvBufferSize <= 0), "Dolby Vision requires VBV settings to enable HRD.\n"); |
1757 | 0 | CHECK((param->internalBitDepth != 10), "Dolby Vision profile - 5, profile - 8.1 and profile - 8.2 is Main10 only\n"); |
1758 | 0 | CHECK((param->internalCsp != X265_CSP_I420), "Dolby Vision profile - 5, profile - 8.1 and profile - 8.2 requires YCbCr 4:2:0 color space\n"); |
1759 | |
|
1760 | 0 | if (param->dolbyProfile == 81) |
1761 | 0 | CHECK(!(param->masteringDisplayColorVolume), "Dolby Vision profile - 8.1 requires Mastering display color volume information\n"); |
1762 | 0 | } |
1763 | |
|
1764 | 0 | if (param->bField && param->interlaceMode) |
1765 | 0 | { |
1766 | 0 | CHECK( (param->bFrameAdaptive==0), "Adaptive B-frame decision method should be closed for field feature.\n" ); |
1767 | | // to do |
1768 | 0 | } |
1769 | 0 | CHECK(param->selectiveSAO < 0 || param->selectiveSAO > 4, |
1770 | 0 | "Invalid SAO tune level. Value must be between 0 and 4 (inclusive)"); |
1771 | 0 | CHECK(param->scenecutWindow < 0 || param->scenecutWindow > 1000, |
1772 | 0 | "Invalid scenecut Window duration. Value must be between 0 and 1000(inclusive)"); |
1773 | 0 | CHECK(param->maxQpDelta < 0 || param->maxQpDelta > 10, |
1774 | 0 | "Invalid maxQpDelta value. Value must be between 0 and 10 (inclusive)"); |
1775 | 0 | for(int level = 0; level < 3; level++) |
1776 | 0 | CHECK(param->hmeRange[level] < 0 || param->hmeRange[level] >= 32768, |
1777 | 0 | "Search Range for HME levels must be between 0 and 32768"); |
1778 | | #if !X86_64 |
1779 | | CHECK(param->searchMethod == X265_SEA && (param->sourceWidth > 840 || param->sourceHeight > 480), |
1780 | | "SEA motion search does not support resolutions greater than 480p in 32 bit build"); |
1781 | | #endif |
1782 | |
|
1783 | 0 | if (param->masteringDisplayColorVolume || param->maxFALL || param->maxCLL) |
1784 | 0 | param->bEmitHDR10SEI = 1; |
1785 | |
|
1786 | 0 | bool isSingleSEI = (param->bRepeatHeaders |
1787 | 0 | || param->bEmitHRDSEI |
1788 | 0 | || param->bEmitInfoSEI |
1789 | 0 | || param->bEmitHDR10SEI |
1790 | 0 | || param->bEmitIDRRecoverySEI |
1791 | 0 | || !!param->interlaceMode |
1792 | 0 | || param->preferredTransferCharacteristics > 1 |
1793 | 0 | || param->toneMapFile |
1794 | 0 | || param->naluFile); |
1795 | |
|
1796 | 0 | if (!isSingleSEI && param->bSingleSeiNal) |
1797 | 0 | { |
1798 | 0 | param->bSingleSeiNal = 0; |
1799 | 0 | x265_log(param, X265_LOG_WARNING, "None of the SEI messages are enabled. Disabling Single SEI NAL\n"); |
1800 | 0 | } |
1801 | 0 | CHECK(param->confWinRightOffset < 0, "Conformance Window Right Offset must be 0 or greater"); |
1802 | 0 | CHECK(param->confWinBottomOffset < 0, "Conformance Window Bottom Offset must be 0 or greater"); |
1803 | 0 | CHECK(param->decoderVbvMaxRate < 0, "Invalid Decoder Vbv Maxrate. Value can not be less than zero"); |
1804 | 0 | return check_failed; |
1805 | 0 | } |
1806 | | |
1807 | | void x265_param_apply_fastfirstpass(x265_param* param) |
1808 | 0 | { |
1809 | | /* Set faster options in case of turbo firstpass */ |
1810 | 0 | if (param->rc.bStatWrite && !param->rc.bStatRead) |
1811 | 0 | { |
1812 | 0 | param->maxNumReferences = 1; |
1813 | 0 | param->maxNumMergeCand = 1; |
1814 | 0 | param->bEnableRectInter = 0; |
1815 | 0 | param->bEnableFastIntra = 1; |
1816 | 0 | param->bEnableAMP = 0; |
1817 | 0 | param->searchMethod = X265_DIA_SEARCH; |
1818 | 0 | param->subpelRefine = X265_MIN(2, param->subpelRefine); |
1819 | 0 | param->bEnableEarlySkip = 1; |
1820 | 0 | param->rdLevel = X265_MIN(2, param->rdLevel); |
1821 | 0 | } |
1822 | 0 | } |
1823 | | |
1824 | | static void appendtool(x265_param* param, char* buf, size_t size, const char* toolstr) |
1825 | 0 | { |
1826 | 0 | static const int overhead = (int)strlen("x265 [info]: tools: "); |
1827 | |
|
1828 | 0 | if (strlen(buf) + strlen(toolstr) + overhead >= size) |
1829 | 0 | { |
1830 | 0 | x265_log(param, X265_LOG_INFO, "tools:%s\n", buf); |
1831 | 0 | sprintf(buf, " %s", toolstr); |
1832 | 0 | } |
1833 | 0 | else |
1834 | 0 | { |
1835 | 0 | strcat(buf, " "); |
1836 | 0 | strcat(buf, toolstr); |
1837 | 0 | } |
1838 | 0 | } |
1839 | | |
1840 | | void x265_print_params(x265_param* param) |
1841 | 0 | { |
1842 | 0 | if (param->logLevel < X265_LOG_INFO) |
1843 | 0 | return; |
1844 | | |
1845 | 0 | if (param->interlaceMode) |
1846 | 0 | x265_log(param, X265_LOG_INFO, "Interlaced field inputs : %s\n", x265_interlace_names[param->interlaceMode]); |
1847 | |
|
1848 | 0 | x265_log(param, X265_LOG_INFO, "Coding QT: max CU size, min CU size : %d / %d\n", param->maxCUSize, param->minCUSize); |
1849 | |
|
1850 | 0 | x265_log(param, X265_LOG_INFO, "Residual QT: max TU size, max depth : %d / %d inter / %d intra\n", |
1851 | 0 | param->maxTUSize, param->tuQTMaxInterDepth, param->tuQTMaxIntraDepth); |
1852 | |
|
1853 | 0 | if (param->bEnableHME) |
1854 | 0 | x265_log(param, X265_LOG_INFO, "HME L0,1,2 / range / subpel / merge : %s, %s, %s / %d / %d / %d\n", |
1855 | 0 | x265_motion_est_names[param->hmeSearchMethod[0]], x265_motion_est_names[param->hmeSearchMethod[1]], x265_motion_est_names[param->hmeSearchMethod[2]], param->searchRange, param->subpelRefine, param->maxNumMergeCand); |
1856 | 0 | else |
1857 | 0 | x265_log(param, X265_LOG_INFO, "ME / range / subpel / merge : %s / %d / %d / %d\n", |
1858 | 0 | x265_motion_est_names[param->searchMethod], param->searchRange, param->subpelRefine, param->maxNumMergeCand); |
1859 | |
|
1860 | 0 | if (param->scenecutThreshold && param->keyframeMax != INT_MAX) |
1861 | 0 | x265_log(param, X265_LOG_INFO, "Keyframe min / max / scenecut / bias : %d / %d / %d / %.2lf \n", |
1862 | 0 | param->keyframeMin, param->keyframeMax, param->scenecutThreshold, param->scenecutBias * 100); |
1863 | 0 | else if (param->bHistBasedSceneCut && param->keyframeMax != INT_MAX) |
1864 | 0 | x265_log(param, X265_LOG_INFO, "Keyframe min / max / scenecut / edge threshold : %d / %d / %d / %.2lf\n", |
1865 | 0 | param->keyframeMin, param->keyframeMax, param->bHistBasedSceneCut, param->edgeTransitionThreshold); |
1866 | 0 | else if (param->keyframeMax == INT_MAX) |
1867 | 0 | x265_log(param, X265_LOG_INFO, "Keyframe min / max / scenecut : disabled\n"); |
1868 | |
|
1869 | 0 | if (param->cbQpOffset || param->crQpOffset) |
1870 | 0 | x265_log(param, X265_LOG_INFO, "Cb/Cr QP Offset : %d / %d\n", param->cbQpOffset, param->crQpOffset); |
1871 | |
|
1872 | 0 | if (param->rdPenalty) |
1873 | 0 | x265_log(param, X265_LOG_INFO, "Intra 32x32 TU penalty type : %d\n", param->rdPenalty); |
1874 | |
|
1875 | 0 | x265_log(param, X265_LOG_INFO, "Lookahead / bframes / badapt : %d / %d / %d\n", param->lookaheadDepth, param->bframes, param->bFrameAdaptive); |
1876 | 0 | x265_log(param, X265_LOG_INFO, "b-pyramid / weightp / weightb : %d / %d / %d\n", |
1877 | 0 | param->bBPyramid, param->bEnableWeightedPred, param->bEnableWeightedBiPred); |
1878 | 0 | x265_log(param, X265_LOG_INFO, "References / ref-limit cu / depth : %d / %s / %s\n", |
1879 | 0 | param->maxNumReferences, (param->limitReferences & X265_REF_LIMIT_CU) ? "on" : "off", |
1880 | 0 | (param->limitReferences & X265_REF_LIMIT_DEPTH) ? "on" : "off"); |
1881 | |
|
1882 | 0 | if (param->rc.aqMode) |
1883 | 0 | x265_log(param, X265_LOG_INFO, "AQ: mode / str / qg-size / cu-tree : %d / %0.1f / %d / %d\n", param->rc.aqMode, |
1884 | 0 | param->rc.aqStrength, param->rc.qgSize, param->rc.cuTree); |
1885 | |
|
1886 | 0 | if (param->bLossless) |
1887 | 0 | x265_log(param, X265_LOG_INFO, "Rate Control : Lossless\n"); |
1888 | 0 | else switch (param->rc.rateControlMode) |
1889 | 0 | { |
1890 | 0 | case X265_RC_ABR: |
1891 | 0 | x265_log(param, X265_LOG_INFO, "Rate Control / qCompress : ABR-%d kbps / %0.2f\n", param->rc.bitrate, param->rc.qCompress); break; |
1892 | 0 | case X265_RC_CQP: |
1893 | 0 | x265_log(param, X265_LOG_INFO, "Rate Control : CQP-%d\n", param->rc.qp); break; |
1894 | 0 | case X265_RC_CRF: |
1895 | 0 | x265_log(param, X265_LOG_INFO, "Rate Control / qCompress : CRF-%0.1f / %0.2f\n", param->rc.rfConstant, param->rc.qCompress); break; |
1896 | 0 | } |
1897 | | |
1898 | 0 | if (param->rc.vbvBufferSize) |
1899 | 0 | { |
1900 | 0 | if (param->vbvBufferEnd) |
1901 | 0 | x265_log(param, X265_LOG_INFO, "VBV/HRD buffer / max-rate / init / end / fr-adj: %d / %d / %.3f / %.3f / %.3f\n", |
1902 | 0 | param->rc.vbvBufferSize, param->rc.vbvMaxBitrate, param->rc.vbvBufferInit, param->vbvBufferEnd, param->vbvEndFrameAdjust); |
1903 | 0 | else |
1904 | 0 | x265_log(param, X265_LOG_INFO, "VBV/HRD buffer / max-rate / init : %d / %d / %.3f\n", |
1905 | 0 | param->rc.vbvBufferSize, param->rc.vbvMaxBitrate, param->rc.vbvBufferInit); |
1906 | 0 | } |
1907 | | |
1908 | 0 | char buf[80] = { 0 }; |
1909 | 0 | char tmp[40]; |
1910 | 0 | #define TOOLOPT(FLAG, STR) if (FLAG) appendtool(param, buf, sizeof(buf), STR); |
1911 | 0 | #define TOOLVAL(VAL, STR) if (VAL) { sprintf(tmp, STR, VAL); appendtool(param, buf, sizeof(buf), tmp); } |
1912 | 0 | TOOLOPT(param->bEnableRectInter, "rect"); |
1913 | 0 | TOOLOPT(param->bEnableAMP, "amp"); |
1914 | 0 | TOOLOPT(param->limitModes, "limit-modes"); |
1915 | 0 | TOOLVAL(param->rdLevel, "rd=%d"); |
1916 | 0 | TOOLVAL(param->dynamicRd, "dynamic-rd=%.2f"); |
1917 | 0 | TOOLOPT(param->bSsimRd, "ssim-rd"); |
1918 | 0 | TOOLVAL(param->psyRd, "psy-rd=%.2lf"); |
1919 | 0 | TOOLVAL(param->rdoqLevel, "rdoq=%d"); |
1920 | 0 | TOOLVAL(param->psyRdoq, "psy-rdoq=%.2lf"); |
1921 | 0 | TOOLOPT(param->bEnableRdRefine, "rd-refine"); |
1922 | 0 | TOOLOPT(param->bEnableEarlySkip, "early-skip"); |
1923 | 0 | TOOLVAL(param->recursionSkipMode, "rskip mode=%d"); |
1924 | 0 | if (param->recursionSkipMode == EDGE_BASED_RSKIP) |
1925 | 0 | TOOLVAL(param->edgeVarThreshold, "rskip-edge-threshold=%.2f"); |
1926 | 0 | TOOLOPT(param->bEnableSplitRdSkip, "splitrd-skip"); |
1927 | 0 | TOOLVAL(param->noiseReductionIntra, "nr-intra=%d"); |
1928 | 0 | TOOLVAL(param->noiseReductionInter, "nr-inter=%d"); |
1929 | 0 | TOOLOPT(param->bEnableTSkipFast, "tskip-fast"); |
1930 | 0 | TOOLOPT(!param->bEnableTSkipFast && param->bEnableTransformSkip, "tskip"); |
1931 | 0 | TOOLVAL(param->limitTU , "limit-tu=%d"); |
1932 | 0 | TOOLOPT(param->bCULossless, "cu-lossless"); |
1933 | 0 | TOOLOPT(param->bEnableSignHiding, "signhide"); |
1934 | 0 | TOOLOPT(param->bEnableTemporalMvp, "tmvp"); |
1935 | 0 | TOOLOPT(param->bEnableConstrainedIntra, "cip"); |
1936 | 0 | TOOLOPT(param->bIntraInBFrames, "b-intra"); |
1937 | 0 | TOOLOPT(param->bEnableFastIntra, "fast-intra"); |
1938 | 0 | TOOLOPT(param->bEnableStrongIntraSmoothing, "strong-intra-smoothing"); |
1939 | 0 | TOOLVAL(param->lookaheadSlices, "lslices=%d"); |
1940 | 0 | TOOLVAL(param->lookaheadThreads, "lthreads=%d") |
1941 | 0 | TOOLVAL(param->bCTUInfo, "ctu-info=%d"); |
1942 | 0 | if (param->bAnalysisType == AVC_INFO) |
1943 | 0 | { |
1944 | 0 | TOOLOPT(param->bAnalysisType, "refine-analysis-type=avc"); |
1945 | 0 | } |
1946 | 0 | else if (param->bAnalysisType == HEVC_INFO) |
1947 | 0 | TOOLOPT(param->bAnalysisType, "refine-analysis-type=hevc"); |
1948 | 0 | TOOLOPT(param->bDynamicRefine, "dynamic-refine"); |
1949 | 0 | if (param->maxSlices > 1) |
1950 | 0 | TOOLVAL(param->maxSlices, "slices=%d"); |
1951 | 0 | if (param->bEnableLoopFilter) |
1952 | 0 | { |
1953 | 0 | if (param->deblockingFilterBetaOffset || param->deblockingFilterTCOffset) |
1954 | 0 | { |
1955 | 0 | sprintf(tmp, "deblock(tC=%d:B=%d)", param->deblockingFilterTCOffset, param->deblockingFilterBetaOffset); |
1956 | 0 | appendtool(param, buf, sizeof(buf), tmp); |
1957 | 0 | } |
1958 | 0 | else |
1959 | 0 | TOOLOPT(param->bEnableLoopFilter, "deblock"); |
1960 | 0 | } |
1961 | 0 | TOOLOPT(param->bSaoNonDeblocked, "sao-non-deblock"); |
1962 | 0 | TOOLOPT(!param->bSaoNonDeblocked && param->bEnableSAO, "sao"); |
1963 | 0 | if (param->selectiveSAO && param->selectiveSAO != 4) |
1964 | 0 | TOOLOPT(param->selectiveSAO, "selective-sao"); |
1965 | 0 | TOOLOPT(param->rc.bStatWrite, "stats-write"); |
1966 | 0 | TOOLOPT(param->rc.bStatRead, "stats-read"); |
1967 | 0 | TOOLOPT(param->bSingleSeiNal, "single-sei"); |
1968 | | #if ENABLE_HDR10_PLUS |
1969 | | TOOLOPT(param->toneMapFile != NULL, "dhdr10-info"); |
1970 | | #endif |
1971 | 0 | x265_log(param, X265_LOG_INFO, "tools:%s\n", buf); |
1972 | 0 | fflush(stderr); |
1973 | 0 | } |
1974 | | |
1975 | | char *x265_param2string(x265_param* p, int padx, int pady) |
1976 | 0 | { |
1977 | 0 | char *buf, *s; |
1978 | 0 | size_t bufSize = 4000 + p->rc.zoneCount * 64; |
1979 | 0 | if (p->numaPools) |
1980 | 0 | bufSize += strlen(p->numaPools); |
1981 | 0 | if (p->masteringDisplayColorVolume) |
1982 | 0 | bufSize += strlen(p->masteringDisplayColorVolume); |
1983 | |
|
1984 | 0 | buf = s = X265_MALLOC(char, bufSize); |
1985 | 0 | if (!buf) |
1986 | 0 | return NULL; |
1987 | 0 | #define BOOL(param, cliopt) \ |
1988 | 0 | s += sprintf(s, " %s", (param) ? cliopt : "no-" cliopt); |
1989 | | |
1990 | 0 | s += sprintf(s, "cpuid=%d", p->cpuid); |
1991 | 0 | s += sprintf(s, " frame-threads=%d", p->frameNumThreads); |
1992 | 0 | if (p->numaPools) |
1993 | 0 | s += sprintf(s, " numa-pools=%s", p->numaPools); |
1994 | 0 | BOOL(p->bEnableWavefront, "wpp"); |
1995 | 0 | BOOL(p->bDistributeModeAnalysis, "pmode"); |
1996 | 0 | BOOL(p->bDistributeMotionEstimation, "pme"); |
1997 | 0 | BOOL(p->bEnablePsnr, "psnr"); |
1998 | 0 | BOOL(p->bEnableSsim, "ssim"); |
1999 | 0 | s += sprintf(s, " log-level=%d", p->logLevel); |
2000 | 0 | if (p->csvfn) |
2001 | 0 | s += sprintf(s, " csv csv-log-level=%d", p->csvLogLevel); |
2002 | 0 | s += sprintf(s, " bitdepth=%d", p->internalBitDepth); |
2003 | 0 | s += sprintf(s, " input-csp=%d", p->internalCsp); |
2004 | 0 | s += sprintf(s, " fps=%u/%u", p->fpsNum, p->fpsDenom); |
2005 | 0 | s += sprintf(s, " input-res=%dx%d", p->sourceWidth - padx, p->sourceHeight - pady); |
2006 | 0 | s += sprintf(s, " interlace=%d", p->interlaceMode); |
2007 | 0 | s += sprintf(s, " total-frames=%d", p->totalFrames); |
2008 | 0 | if (p->chunkStart) |
2009 | 0 | s += sprintf(s, " chunk-start=%d", p->chunkStart); |
2010 | 0 | if (p->chunkEnd) |
2011 | 0 | s += sprintf(s, " chunk-end=%d", p->chunkEnd); |
2012 | 0 | s += sprintf(s, " level-idc=%d", p->levelIdc); |
2013 | 0 | s += sprintf(s, " high-tier=%d", p->bHighTier); |
2014 | 0 | s += sprintf(s, " uhd-bd=%d", p->uhdBluray); |
2015 | 0 | s += sprintf(s, " ref=%d", p->maxNumReferences); |
2016 | 0 | BOOL(p->bAllowNonConformance, "allow-non-conformance"); |
2017 | 0 | BOOL(p->bRepeatHeaders, "repeat-headers"); |
2018 | 0 | BOOL(p->bAnnexB, "annexb"); |
2019 | 0 | BOOL(p->bEnableAccessUnitDelimiters, "aud"); |
2020 | 0 | BOOL(p->bEmitHRDSEI, "hrd"); |
2021 | 0 | BOOL(p->bEmitInfoSEI, "info"); |
2022 | 0 | s += sprintf(s, " hash=%d", p->decodedPictureHashSEI); |
2023 | 0 | BOOL(p->bEnableTemporalSubLayers, "temporal-layers"); |
2024 | 0 | BOOL(p->bOpenGOP, "open-gop"); |
2025 | 0 | s += sprintf(s, " min-keyint=%d", p->keyframeMin); |
2026 | 0 | s += sprintf(s, " keyint=%d", p->keyframeMax); |
2027 | 0 | s += sprintf(s, " gop-lookahead=%d", p->gopLookahead); |
2028 | 0 | s += sprintf(s, " bframes=%d", p->bframes); |
2029 | 0 | s += sprintf(s, " b-adapt=%d", p->bFrameAdaptive); |
2030 | 0 | BOOL(p->bBPyramid, "b-pyramid"); |
2031 | 0 | s += sprintf(s, " bframe-bias=%d", p->bFrameBias); |
2032 | 0 | s += sprintf(s, " rc-lookahead=%d", p->lookaheadDepth); |
2033 | 0 | s += sprintf(s, " lookahead-slices=%d", p->lookaheadSlices); |
2034 | 0 | s += sprintf(s, " scenecut=%d", p->scenecutThreshold); |
2035 | 0 | s += sprintf(s, " hist-scenecut=%d", p->bHistBasedSceneCut); |
2036 | 0 | s += sprintf(s, " radl=%d", p->radl); |
2037 | 0 | BOOL(p->bEnableHRDConcatFlag, "splice"); |
2038 | 0 | BOOL(p->bIntraRefresh, "intra-refresh"); |
2039 | 0 | s += sprintf(s, " ctu=%d", p->maxCUSize); |
2040 | 0 | s += sprintf(s, " min-cu-size=%d", p->minCUSize); |
2041 | 0 | BOOL(p->bEnableRectInter, "rect"); |
2042 | 0 | BOOL(p->bEnableAMP, "amp"); |
2043 | 0 | s += sprintf(s, " max-tu-size=%d", p->maxTUSize); |
2044 | 0 | s += sprintf(s, " tu-inter-depth=%d", p->tuQTMaxInterDepth); |
2045 | 0 | s += sprintf(s, " tu-intra-depth=%d", p->tuQTMaxIntraDepth); |
2046 | 0 | s += sprintf(s, " limit-tu=%d", p->limitTU); |
2047 | 0 | s += sprintf(s, " rdoq-level=%d", p->rdoqLevel); |
2048 | 0 | s += sprintf(s, " dynamic-rd=%.2f", p->dynamicRd); |
2049 | 0 | BOOL(p->bSsimRd, "ssim-rd"); |
2050 | 0 | BOOL(p->bEnableSignHiding, "signhide"); |
2051 | 0 | BOOL(p->bEnableTransformSkip, "tskip"); |
2052 | 0 | s += sprintf(s, " nr-intra=%d", p->noiseReductionIntra); |
2053 | 0 | s += sprintf(s, " nr-inter=%d", p->noiseReductionInter); |
2054 | 0 | BOOL(p->bEnableConstrainedIntra, "constrained-intra"); |
2055 | 0 | BOOL(p->bEnableStrongIntraSmoothing, "strong-intra-smoothing"); |
2056 | 0 | s += sprintf(s, " max-merge=%d", p->maxNumMergeCand); |
2057 | 0 | s += sprintf(s, " limit-refs=%d", p->limitReferences); |
2058 | 0 | BOOL(p->limitModes, "limit-modes"); |
2059 | 0 | s += sprintf(s, " me=%d", p->searchMethod); |
2060 | 0 | s += sprintf(s, " subme=%d", p->subpelRefine); |
2061 | 0 | s += sprintf(s, " merange=%d", p->searchRange); |
2062 | 0 | BOOL(p->bEnableTemporalMvp, "temporal-mvp"); |
2063 | 0 | BOOL(p->bEnableFrameDuplication, "frame-dup"); |
2064 | 0 | if(p->bEnableFrameDuplication) |
2065 | 0 | s += sprintf(s, " dup-threshold=%d", p->dupThreshold); |
2066 | 0 | BOOL(p->bEnableHME, "hme"); |
2067 | 0 | if (p->bEnableHME) |
2068 | 0 | { |
2069 | 0 | s += sprintf(s, " Level 0,1,2=%d,%d,%d", p->hmeSearchMethod[0], p->hmeSearchMethod[1], p->hmeSearchMethod[2]); |
2070 | 0 | s += sprintf(s, " merange L0,L1,L2=%d,%d,%d", p->hmeRange[0], p->hmeRange[1], p->hmeRange[2]); |
2071 | 0 | } |
2072 | 0 | BOOL(p->bEnableWeightedPred, "weightp"); |
2073 | 0 | BOOL(p->bEnableWeightedBiPred, "weightb"); |
2074 | 0 | BOOL(p->bSourceReferenceEstimation, "analyze-src-pics"); |
2075 | 0 | BOOL(p->bEnableLoopFilter, "deblock"); |
2076 | 0 | if (p->bEnableLoopFilter) |
2077 | 0 | s += sprintf(s, "=%d:%d", p->deblockingFilterTCOffset, p->deblockingFilterBetaOffset); |
2078 | 0 | BOOL(p->bEnableSAO, "sao"); |
2079 | 0 | BOOL(p->bSaoNonDeblocked, "sao-non-deblock"); |
2080 | 0 | s += sprintf(s, " rd=%d", p->rdLevel); |
2081 | 0 | s += sprintf(s, " selective-sao=%d", p->selectiveSAO); |
2082 | 0 | BOOL(p->bEnableEarlySkip, "early-skip"); |
2083 | 0 | BOOL(p->recursionSkipMode, "rskip"); |
2084 | 0 | if (p->recursionSkipMode == EDGE_BASED_RSKIP) |
2085 | 0 | s += sprintf(s, " rskip-edge-threshold=%f", p->edgeVarThreshold); |
2086 | |
|
2087 | 0 | BOOL(p->bEnableFastIntra, "fast-intra"); |
2088 | 0 | BOOL(p->bEnableTSkipFast, "tskip-fast"); |
2089 | 0 | BOOL(p->bCULossless, "cu-lossless"); |
2090 | 0 | BOOL(p->bIntraInBFrames, "b-intra"); |
2091 | 0 | BOOL(p->bEnableSplitRdSkip, "splitrd-skip"); |
2092 | 0 | s += sprintf(s, " rdpenalty=%d", p->rdPenalty); |
2093 | 0 | s += sprintf(s, " psy-rd=%.2f", p->psyRd); |
2094 | 0 | s += sprintf(s, " psy-rdoq=%.2f", p->psyRdoq); |
2095 | 0 | BOOL(p->bEnableRdRefine, "rd-refine"); |
2096 | 0 | BOOL(p->bLossless, "lossless"); |
2097 | 0 | s += sprintf(s, " cbqpoffs=%d", p->cbQpOffset); |
2098 | 0 | s += sprintf(s, " crqpoffs=%d", p->crQpOffset); |
2099 | 0 | s += sprintf(s, " rc=%s", p->rc.rateControlMode == X265_RC_ABR ? ( |
2100 | 0 | p->rc.bitrate == p->rc.vbvMaxBitrate ? "cbr" : "abr") |
2101 | 0 | : p->rc.rateControlMode == X265_RC_CRF ? "crf" : "cqp"); |
2102 | 0 | if (p->rc.rateControlMode == X265_RC_ABR || p->rc.rateControlMode == X265_RC_CRF) |
2103 | 0 | { |
2104 | 0 | if (p->rc.rateControlMode == X265_RC_CRF) |
2105 | 0 | s += sprintf(s, " crf=%.1f", p->rc.rfConstant); |
2106 | 0 | else |
2107 | 0 | s += sprintf(s, " bitrate=%d", p->rc.bitrate); |
2108 | 0 | s += sprintf(s, " qcomp=%.2f qpstep=%d", p->rc.qCompress, p->rc.qpStep); |
2109 | 0 | s += sprintf(s, " stats-write=%d", p->rc.bStatWrite); |
2110 | 0 | s += sprintf(s, " stats-read=%d", p->rc.bStatRead); |
2111 | 0 | if (p->rc.bStatRead) |
2112 | 0 | s += sprintf(s, " cplxblur=%.1f qblur=%.1f", |
2113 | 0 | p->rc.complexityBlur, p->rc.qblur); |
2114 | 0 | if (p->rc.bStatWrite && !p->rc.bStatRead) |
2115 | 0 | BOOL(p->rc.bEnableSlowFirstPass, "slow-firstpass"); |
2116 | 0 | if (p->rc.vbvBufferSize) |
2117 | 0 | { |
2118 | 0 | s += sprintf(s, " vbv-maxrate=%d vbv-bufsize=%d vbv-init=%.1f", |
2119 | 0 | p->rc.vbvMaxBitrate, p->rc.vbvBufferSize, p->rc.vbvBufferInit); |
2120 | 0 | if (p->vbvBufferEnd) |
2121 | 0 | s += sprintf(s, " vbv-end=%.1f vbv-end-fr-adj=%.1f", p->vbvBufferEnd, p->vbvEndFrameAdjust); |
2122 | 0 | if (p->rc.rateControlMode == X265_RC_CRF) |
2123 | 0 | s += sprintf(s, " crf-max=%.1f crf-min=%.1f", p->rc.rfConstantMax, p->rc.rfConstantMin); |
2124 | 0 | } |
2125 | 0 | } |
2126 | 0 | else if (p->rc.rateControlMode == X265_RC_CQP) |
2127 | 0 | s += sprintf(s, " qp=%d", p->rc.qp); |
2128 | 0 | if (!(p->rc.rateControlMode == X265_RC_CQP && p->rc.qp == 0)) |
2129 | 0 | { |
2130 | 0 | s += sprintf(s, " ipratio=%.2f", p->rc.ipFactor); |
2131 | 0 | if (p->bframes) |
2132 | 0 | s += sprintf(s, " pbratio=%.2f", p->rc.pbFactor); |
2133 | 0 | } |
2134 | 0 | s += sprintf(s, " aq-mode=%d", p->rc.aqMode); |
2135 | 0 | s += sprintf(s, " aq-strength=%.2f", p->rc.aqStrength); |
2136 | 0 | BOOL(p->rc.cuTree, "cutree"); |
2137 | 0 | s += sprintf(s, " zone-count=%d", p->rc.zoneCount); |
2138 | 0 | if (p->rc.zoneCount) |
2139 | 0 | { |
2140 | 0 | for (int i = 0; i < p->rc.zoneCount; ++i) |
2141 | 0 | { |
2142 | 0 | s += sprintf(s, " zones: start-frame=%d end-frame=%d", |
2143 | 0 | p->rc.zones[i].startFrame, p->rc.zones[i].endFrame); |
2144 | 0 | if (p->rc.zones[i].bForceQp) |
2145 | 0 | s += sprintf(s, " qp=%d", p->rc.zones[i].qp); |
2146 | 0 | else |
2147 | 0 | s += sprintf(s, " bitrate-factor=%f", p->rc.zones[i].bitrateFactor); |
2148 | 0 | } |
2149 | 0 | } |
2150 | 0 | BOOL(p->rc.bStrictCbr, "strict-cbr"); |
2151 | 0 | s += sprintf(s, " qg-size=%d", p->rc.qgSize); |
2152 | 0 | BOOL(p->rc.bEnableGrain, "rc-grain"); |
2153 | 0 | s += sprintf(s, " qpmax=%d qpmin=%d", p->rc.qpMax, p->rc.qpMin); |
2154 | 0 | BOOL(p->rc.bEnableConstVbv, "const-vbv"); |
2155 | 0 | s += sprintf(s, " sar=%d", p->vui.aspectRatioIdc); |
2156 | 0 | if (p->vui.aspectRatioIdc == X265_EXTENDED_SAR) |
2157 | 0 | s += sprintf(s, " sar-width : sar-height=%d:%d", p->vui.sarWidth, p->vui.sarHeight); |
2158 | 0 | s += sprintf(s, " overscan=%d", p->vui.bEnableOverscanInfoPresentFlag); |
2159 | 0 | if (p->vui.bEnableOverscanInfoPresentFlag) |
2160 | 0 | s += sprintf(s, " overscan-crop=%d", p->vui.bEnableOverscanAppropriateFlag); |
2161 | 0 | s += sprintf(s, " videoformat=%d", p->vui.videoFormat); |
2162 | 0 | s += sprintf(s, " range=%d", p->vui.bEnableVideoFullRangeFlag); |
2163 | 0 | s += sprintf(s, " colorprim=%d", p->vui.colorPrimaries); |
2164 | 0 | s += sprintf(s, " transfer=%d", p->vui.transferCharacteristics); |
2165 | 0 | s += sprintf(s, " colormatrix=%d", p->vui.matrixCoeffs); |
2166 | 0 | s += sprintf(s, " chromaloc=%d", p->vui.bEnableChromaLocInfoPresentFlag); |
2167 | 0 | if (p->vui.bEnableChromaLocInfoPresentFlag) |
2168 | 0 | s += sprintf(s, " chromaloc-top=%d chromaloc-bottom=%d", |
2169 | 0 | p->vui.chromaSampleLocTypeTopField, p->vui.chromaSampleLocTypeBottomField); |
2170 | 0 | s += sprintf(s, " display-window=%d", p->vui.bEnableDefaultDisplayWindowFlag); |
2171 | 0 | if (p->vui.bEnableDefaultDisplayWindowFlag) |
2172 | 0 | s += sprintf(s, " left=%d top=%d right=%d bottom=%d", |
2173 | 0 | p->vui.defDispWinLeftOffset, p->vui.defDispWinTopOffset, |
2174 | 0 | p->vui.defDispWinRightOffset, p->vui.defDispWinBottomOffset); |
2175 | 0 | if (p->masteringDisplayColorVolume) |
2176 | 0 | s += sprintf(s, " master-display=%s", p->masteringDisplayColorVolume); |
2177 | 0 | if (p->bEmitCLL) |
2178 | 0 | s += sprintf(s, " cll=%hu,%hu", p->maxCLL, p->maxFALL); |
2179 | 0 | s += sprintf(s, " min-luma=%hu", p->minLuma); |
2180 | 0 | s += sprintf(s, " max-luma=%hu", p->maxLuma); |
2181 | 0 | s += sprintf(s, " log2-max-poc-lsb=%d", p->log2MaxPocLsb); |
2182 | 0 | BOOL(p->bEmitVUITimingInfo, "vui-timing-info"); |
2183 | 0 | BOOL(p->bEmitVUIHRDInfo, "vui-hrd-info"); |
2184 | 0 | s += sprintf(s, " slices=%d", p->maxSlices); |
2185 | 0 | BOOL(p->bOptQpPPS, "opt-qp-pps"); |
2186 | 0 | BOOL(p->bOptRefListLengthPPS, "opt-ref-list-length-pps"); |
2187 | 0 | BOOL(p->bMultiPassOptRPS, "multi-pass-opt-rps"); |
2188 | 0 | s += sprintf(s, " scenecut-bias=%.2f", p->scenecutBias); |
2189 | 0 | s += sprintf(s, " hist-threshold=%.2f", p->edgeTransitionThreshold); |
2190 | 0 | BOOL(p->bOptCUDeltaQP, "opt-cu-delta-qp"); |
2191 | 0 | BOOL(p->bAQMotion, "aq-motion"); |
2192 | 0 | BOOL(p->bEmitHDR10SEI, "hdr10"); |
2193 | 0 | BOOL(p->bHDR10Opt, "hdr10-opt"); |
2194 | 0 | BOOL(p->bDhdr10opt, "dhdr10-opt"); |
2195 | 0 | BOOL(p->bEmitIDRRecoverySEI, "idr-recovery-sei"); |
2196 | 0 | if (p->analysisSave) |
2197 | 0 | s += sprintf(s, " analysis-save"); |
2198 | 0 | if (p->analysisLoad) |
2199 | 0 | s += sprintf(s, " analysis-load"); |
2200 | 0 | s += sprintf(s, " analysis-reuse-level=%d", p->analysisReuseLevel); |
2201 | 0 | s += sprintf(s, " analysis-save-reuse-level=%d", p->analysisSaveReuseLevel); |
2202 | 0 | s += sprintf(s, " analysis-load-reuse-level=%d", p->analysisLoadReuseLevel); |
2203 | 0 | s += sprintf(s, " scale-factor=%d", p->scaleFactor); |
2204 | 0 | s += sprintf(s, " refine-intra=%d", p->intraRefine); |
2205 | 0 | s += sprintf(s, " refine-inter=%d", p->interRefine); |
2206 | 0 | s += sprintf(s, " refine-mv=%d", p->mvRefine); |
2207 | 0 | s += sprintf(s, " refine-ctu-distortion=%d", p->ctuDistortionRefine); |
2208 | 0 | BOOL(p->bLimitSAO, "limit-sao"); |
2209 | 0 | s += sprintf(s, " ctu-info=%d", p->bCTUInfo); |
2210 | 0 | BOOL(p->bLowPassDct, "lowpass-dct"); |
2211 | 0 | s += sprintf(s, " refine-analysis-type=%d", p->bAnalysisType); |
2212 | 0 | s += sprintf(s, " copy-pic=%d", p->bCopyPicToFrame); |
2213 | 0 | s += sprintf(s, " max-ausize-factor=%.1f", p->maxAUSizeFactor); |
2214 | 0 | BOOL(p->bDynamicRefine, "dynamic-refine"); |
2215 | 0 | BOOL(p->bSingleSeiNal, "single-sei"); |
2216 | 0 | BOOL(p->rc.hevcAq, "hevc-aq"); |
2217 | 0 | BOOL(p->bEnableSvtHevc, "svt"); |
2218 | 0 | BOOL(p->bField, "field"); |
2219 | 0 | s += sprintf(s, " qp-adaptation-range=%.2f", p->rc.qpAdaptationRange); |
2220 | 0 | BOOL(p->bEnableSceneCutAwareQp, "scenecut-aware-qp"); |
2221 | 0 | if (p->bEnableSceneCutAwareQp) |
2222 | 0 | s += sprintf(s, " scenecut-window=%d max-qp-delta=%d", p->scenecutWindow, p->maxQpDelta); |
2223 | 0 | s += sprintf(s, "conformance-window-offsets right=%d bottom=%d", p->confWinRightOffset, p->confWinBottomOffset); |
2224 | 0 | s += sprintf(s, " decoder-max-rate=%d", p->decoderVbvMaxRate); |
2225 | 0 | #undef BOOL |
2226 | 0 | return buf; |
2227 | 0 | } |
2228 | | |
2229 | | bool parseLambdaFile(x265_param* param) |
2230 | 0 | { |
2231 | 0 | if (!param->rc.lambdaFileName) |
2232 | 0 | return false; |
2233 | | |
2234 | 0 | FILE *lfn = x265_fopen(param->rc.lambdaFileName, "r"); |
2235 | 0 | if (!lfn) |
2236 | 0 | { |
2237 | 0 | x265_log_file(param, X265_LOG_ERROR, "unable to read lambda file <%s>\n", param->rc.lambdaFileName); |
2238 | 0 | return true; |
2239 | 0 | } |
2240 | | |
2241 | 0 | char line[2048]; |
2242 | 0 | char *toksave = NULL, *tok = NULL, *buf = NULL; |
2243 | |
|
2244 | 0 | for (int t = 0; t < 3; t++) |
2245 | 0 | { |
2246 | 0 | double *table = t ? x265_lambda2_tab : x265_lambda_tab; |
2247 | |
|
2248 | 0 | for (int i = 0; i < QP_MAX_MAX + 1; i++) |
2249 | 0 | { |
2250 | 0 | double value; |
2251 | |
|
2252 | 0 | do |
2253 | 0 | { |
2254 | 0 | if (!tok) |
2255 | 0 | { |
2256 | | /* consume a line of text file */ |
2257 | 0 | if (!fgets(line, sizeof(line), lfn)) |
2258 | 0 | { |
2259 | 0 | fclose(lfn); |
2260 | |
|
2261 | 0 | if (t < 2) |
2262 | 0 | { |
2263 | 0 | x265_log(param, X265_LOG_ERROR, "lambda file is incomplete\n"); |
2264 | 0 | return true; |
2265 | 0 | } |
2266 | 0 | else |
2267 | 0 | return false; |
2268 | 0 | } |
2269 | | |
2270 | | /* truncate at first hash */ |
2271 | 0 | char *hash = strchr(line, '#'); |
2272 | 0 | if (hash) *hash = 0; |
2273 | 0 | buf = line; |
2274 | 0 | } |
2275 | | |
2276 | 0 | tok = strtok_r(buf, " ,", &toksave); |
2277 | 0 | buf = NULL; |
2278 | 0 | if (tok && sscanf(tok, "%lf", &value) == 1) |
2279 | 0 | break; |
2280 | 0 | } |
2281 | 0 | while (1); |
2282 | | |
2283 | 0 | if (t == 2) |
2284 | 0 | { |
2285 | 0 | x265_log(param, X265_LOG_ERROR, "lambda file contains too many values\n"); |
2286 | 0 | fclose(lfn); |
2287 | 0 | return true; |
2288 | 0 | } |
2289 | 0 | else |
2290 | 0 | x265_log(param, X265_LOG_DEBUG, "lambda%c[%d] = %lf\n", t ? '2' : ' ', i, value); |
2291 | 0 | table[i] = value; |
2292 | 0 | } |
2293 | 0 | } |
2294 | | |
2295 | 0 | fclose(lfn); |
2296 | 0 | return false; |
2297 | 0 | } |
2298 | | |
2299 | | void x265_copy_params(x265_param* dst, x265_param* src) |
2300 | 0 | { |
2301 | 0 | dst->cpuid = src->cpuid; |
2302 | 0 | dst->frameNumThreads = src->frameNumThreads; |
2303 | 0 | if (src->numaPools) dst->numaPools = strdup(src->numaPools); |
2304 | 0 | else dst->numaPools = NULL; |
2305 | |
|
2306 | 0 | dst->bEnableWavefront = src->bEnableWavefront; |
2307 | 0 | dst->bDistributeModeAnalysis = src->bDistributeModeAnalysis; |
2308 | 0 | dst->bDistributeMotionEstimation = src->bDistributeMotionEstimation; |
2309 | 0 | dst->bLogCuStats = src->bLogCuStats; |
2310 | 0 | dst->bEnablePsnr = src->bEnablePsnr; |
2311 | 0 | dst->bEnableSsim = src->bEnableSsim; |
2312 | 0 | dst->logLevel = src->logLevel; |
2313 | 0 | dst->csvLogLevel = src->csvLogLevel; |
2314 | 0 | if (src->csvfn) dst->csvfn = strdup(src->csvfn); |
2315 | 0 | else dst->csvfn = NULL; |
2316 | 0 | dst->internalBitDepth = src->internalBitDepth; |
2317 | 0 | dst->sourceBitDepth = src->sourceBitDepth; |
2318 | 0 | dst->internalCsp = src->internalCsp; |
2319 | 0 | dst->fpsNum = src->fpsNum; |
2320 | 0 | dst->fpsDenom = src->fpsDenom; |
2321 | 0 | dst->sourceHeight = src->sourceHeight; |
2322 | 0 | dst->sourceWidth = src->sourceWidth; |
2323 | 0 | dst->interlaceMode = src->interlaceMode; |
2324 | 0 | dst->totalFrames = src->totalFrames; |
2325 | 0 | dst->levelIdc = src->levelIdc; |
2326 | 0 | dst->bHighTier = src->bHighTier; |
2327 | 0 | dst->uhdBluray = src->uhdBluray; |
2328 | 0 | dst->maxNumReferences = src->maxNumReferences; |
2329 | 0 | dst->bAllowNonConformance = src->bAllowNonConformance; |
2330 | 0 | dst->bRepeatHeaders = src->bRepeatHeaders; |
2331 | 0 | dst->bAnnexB = src->bAnnexB; |
2332 | 0 | dst->bEnableAccessUnitDelimiters = src->bEnableAccessUnitDelimiters; |
2333 | 0 | dst->bEmitInfoSEI = src->bEmitInfoSEI; |
2334 | 0 | dst->decodedPictureHashSEI = src->decodedPictureHashSEI; |
2335 | 0 | dst->bEnableTemporalSubLayers = src->bEnableTemporalSubLayers; |
2336 | 0 | dst->bOpenGOP = src->bOpenGOP; |
2337 | 0 | dst->keyframeMax = src->keyframeMax; |
2338 | 0 | dst->keyframeMin = src->keyframeMin; |
2339 | 0 | dst->bframes = src->bframes; |
2340 | 0 | dst->bFrameAdaptive = src->bFrameAdaptive; |
2341 | 0 | dst->bFrameBias = src->bFrameBias; |
2342 | 0 | dst->bBPyramid = src->bBPyramid; |
2343 | 0 | dst->lookaheadDepth = src->lookaheadDepth; |
2344 | 0 | dst->lookaheadSlices = src->lookaheadSlices; |
2345 | 0 | dst->lookaheadThreads = src->lookaheadThreads; |
2346 | 0 | dst->scenecutThreshold = src->scenecutThreshold; |
2347 | 0 | dst->bHistBasedSceneCut = src->bHistBasedSceneCut; |
2348 | 0 | dst->bIntraRefresh = src->bIntraRefresh; |
2349 | 0 | dst->maxCUSize = src->maxCUSize; |
2350 | 0 | dst->minCUSize = src->minCUSize; |
2351 | 0 | dst->bEnableRectInter = src->bEnableRectInter; |
2352 | 0 | dst->bEnableAMP = src->bEnableAMP; |
2353 | 0 | dst->maxTUSize = src->maxTUSize; |
2354 | 0 | dst->tuQTMaxInterDepth = src->tuQTMaxInterDepth; |
2355 | 0 | dst->tuQTMaxIntraDepth = src->tuQTMaxIntraDepth; |
2356 | 0 | dst->limitTU = src->limitTU; |
2357 | 0 | dst->rdoqLevel = src->rdoqLevel; |
2358 | 0 | dst->bEnableSignHiding = src->bEnableSignHiding; |
2359 | 0 | dst->bEnableTransformSkip = src->bEnableTransformSkip; |
2360 | 0 | dst->noiseReductionInter = src->noiseReductionInter; |
2361 | 0 | dst->noiseReductionIntra = src->noiseReductionIntra; |
2362 | 0 | if (src->scalingLists) dst->scalingLists = strdup(src->scalingLists); |
2363 | 0 | else dst->scalingLists = NULL; |
2364 | 0 | dst->bEnableStrongIntraSmoothing = src->bEnableStrongIntraSmoothing; |
2365 | 0 | dst->bEnableConstrainedIntra = src->bEnableConstrainedIntra; |
2366 | 0 | dst->maxNumMergeCand = src->maxNumMergeCand; |
2367 | 0 | dst->limitReferences = src->limitReferences; |
2368 | 0 | dst->limitModes = src->limitModes; |
2369 | 0 | dst->searchMethod = src->searchMethod; |
2370 | 0 | dst->subpelRefine = src->subpelRefine; |
2371 | 0 | dst->searchRange = src->searchRange; |
2372 | 0 | dst->bEnableTemporalMvp = src->bEnableTemporalMvp; |
2373 | 0 | dst->bEnableFrameDuplication = src->bEnableFrameDuplication; |
2374 | 0 | dst->dupThreshold = src->dupThreshold; |
2375 | 0 | dst->bEnableHME = src->bEnableHME; |
2376 | 0 | if (src->bEnableHME) |
2377 | 0 | { |
2378 | 0 | for (int level = 0; level < 3; level++) |
2379 | 0 | { |
2380 | 0 | dst->hmeSearchMethod[level] = src->hmeSearchMethod[level]; |
2381 | 0 | dst->hmeRange[level] = src->hmeRange[level]; |
2382 | 0 | } |
2383 | 0 | } |
2384 | 0 | dst->bEnableWeightedBiPred = src->bEnableWeightedBiPred; |
2385 | 0 | dst->bEnableWeightedPred = src->bEnableWeightedPred; |
2386 | 0 | dst->bSourceReferenceEstimation = src->bSourceReferenceEstimation; |
2387 | 0 | dst->bEnableLoopFilter = src->bEnableLoopFilter; |
2388 | 0 | dst->deblockingFilterBetaOffset = src->deblockingFilterBetaOffset; |
2389 | 0 | dst->deblockingFilterTCOffset = src->deblockingFilterTCOffset; |
2390 | 0 | dst->bEnableSAO = src->bEnableSAO; |
2391 | 0 | dst->bSaoNonDeblocked = src->bSaoNonDeblocked; |
2392 | 0 | dst->rdLevel = src->rdLevel; |
2393 | 0 | dst->bEnableEarlySkip = src->bEnableEarlySkip; |
2394 | 0 | dst->recursionSkipMode = src->recursionSkipMode; |
2395 | 0 | dst->edgeVarThreshold = src->edgeVarThreshold; |
2396 | 0 | dst->bEnableFastIntra = src->bEnableFastIntra; |
2397 | 0 | dst->bEnableTSkipFast = src->bEnableTSkipFast; |
2398 | 0 | dst->bCULossless = src->bCULossless; |
2399 | 0 | dst->bIntraInBFrames = src->bIntraInBFrames; |
2400 | 0 | dst->rdPenalty = src->rdPenalty; |
2401 | 0 | dst->psyRd = src->psyRd; |
2402 | 0 | dst->psyRdoq = src->psyRdoq; |
2403 | 0 | dst->bEnableRdRefine = src->bEnableRdRefine; |
2404 | 0 | dst->analysisReuseMode = src->analysisReuseMode; |
2405 | 0 | if (src->analysisReuseFileName) dst->analysisReuseFileName=strdup(src->analysisReuseFileName); |
2406 | 0 | else dst->analysisReuseFileName = NULL; |
2407 | 0 | dst->bLossless = src->bLossless; |
2408 | 0 | dst->cbQpOffset = src->cbQpOffset; |
2409 | 0 | dst->crQpOffset = src->crQpOffset; |
2410 | 0 | dst->preferredTransferCharacteristics = src->preferredTransferCharacteristics; |
2411 | 0 | dst->pictureStructure = src->pictureStructure; |
2412 | |
|
2413 | 0 | dst->rc.rateControlMode = src->rc.rateControlMode; |
2414 | 0 | dst->rc.qp = src->rc.qp; |
2415 | 0 | dst->rc.bitrate = src->rc.bitrate; |
2416 | 0 | dst->rc.qCompress = src->rc.qCompress; |
2417 | 0 | dst->rc.ipFactor = src->rc.ipFactor; |
2418 | 0 | dst->rc.pbFactor = src->rc.pbFactor; |
2419 | 0 | dst->rc.rfConstant = src->rc.rfConstant; |
2420 | 0 | dst->rc.qpStep = src->rc.qpStep; |
2421 | 0 | dst->rc.aqMode = src->rc.aqMode; |
2422 | 0 | dst->rc.aqStrength = src->rc.aqStrength; |
2423 | 0 | dst->rc.vbvBufferSize = src->rc.vbvBufferSize; |
2424 | 0 | dst->rc.vbvMaxBitrate = src->rc.vbvMaxBitrate; |
2425 | |
|
2426 | 0 | dst->rc.vbvBufferInit = src->rc.vbvBufferInit; |
2427 | 0 | dst->rc.cuTree = src->rc.cuTree; |
2428 | 0 | dst->rc.rfConstantMax = src->rc.rfConstantMax; |
2429 | 0 | dst->rc.rfConstantMin = src->rc.rfConstantMin; |
2430 | 0 | dst->rc.bStatWrite = src->rc.bStatWrite; |
2431 | 0 | dst->rc.bStatRead = src->rc.bStatRead; |
2432 | 0 | if (src->rc.statFileName) dst->rc.statFileName=strdup(src->rc.statFileName); |
2433 | 0 | else dst->rc.statFileName = NULL; |
2434 | 0 | dst->rc.qblur = src->rc.qblur; |
2435 | 0 | dst->rc.complexityBlur = src->rc.complexityBlur; |
2436 | 0 | dst->rc.bEnableSlowFirstPass = src->rc.bEnableSlowFirstPass; |
2437 | 0 | dst->rc.zoneCount = src->rc.zoneCount; |
2438 | 0 | dst->rc.zonefileCount = src->rc.zonefileCount; |
2439 | 0 | dst->reconfigWindowSize = src->reconfigWindowSize; |
2440 | 0 | dst->bResetZoneConfig = src->bResetZoneConfig; |
2441 | 0 | dst->decoderVbvMaxRate = src->decoderVbvMaxRate; |
2442 | |
|
2443 | 0 | if (src->rc.zonefileCount && src->rc.zones && src->bResetZoneConfig) |
2444 | 0 | { |
2445 | 0 | for (int i = 0; i < src->rc.zonefileCount; i++) |
2446 | 0 | { |
2447 | 0 | dst->rc.zones[i].startFrame = src->rc.zones[i].startFrame; |
2448 | 0 | memcpy(dst->rc.zones[i].zoneParam, src->rc.zones[i].zoneParam, sizeof(x265_param)); |
2449 | 0 | } |
2450 | 0 | } |
2451 | 0 | else if (src->rc.zoneCount && src->rc.zones) |
2452 | 0 | { |
2453 | 0 | for (int i = 0; i < src->rc.zoneCount; i++) |
2454 | 0 | { |
2455 | 0 | dst->rc.zones[i].startFrame = src->rc.zones[i].startFrame; |
2456 | 0 | dst->rc.zones[i].endFrame = src->rc.zones[i].endFrame; |
2457 | 0 | dst->rc.zones[i].bForceQp = src->rc.zones[i].bForceQp; |
2458 | 0 | dst->rc.zones[i].qp = src->rc.zones[i].qp; |
2459 | 0 | dst->rc.zones[i].bitrateFactor = src->rc.zones[i].bitrateFactor; |
2460 | 0 | } |
2461 | 0 | } |
2462 | 0 | else |
2463 | 0 | dst->rc.zones = NULL; |
2464 | |
|
2465 | 0 | if (src->rc.lambdaFileName) dst->rc.lambdaFileName = strdup(src->rc.lambdaFileName); |
2466 | 0 | else dst->rc.lambdaFileName = NULL; |
2467 | 0 | dst->rc.bStrictCbr = src->rc.bStrictCbr; |
2468 | 0 | dst->rc.qgSize = src->rc.qgSize; |
2469 | 0 | dst->rc.bEnableGrain = src->rc.bEnableGrain; |
2470 | 0 | dst->rc.qpMax = src->rc.qpMax; |
2471 | 0 | dst->rc.qpMin = src->rc.qpMin; |
2472 | 0 | dst->rc.bEnableConstVbv = src->rc.bEnableConstVbv; |
2473 | 0 | dst->rc.hevcAq = src->rc.hevcAq; |
2474 | 0 | dst->rc.qpAdaptationRange = src->rc.qpAdaptationRange; |
2475 | |
|
2476 | 0 | dst->vui.aspectRatioIdc = src->vui.aspectRatioIdc; |
2477 | 0 | dst->vui.sarWidth = src->vui.sarWidth; |
2478 | 0 | dst->vui.sarHeight = src->vui.sarHeight; |
2479 | 0 | dst->vui.bEnableOverscanAppropriateFlag = src->vui.bEnableOverscanAppropriateFlag; |
2480 | 0 | dst->vui.bEnableOverscanInfoPresentFlag = src->vui.bEnableOverscanInfoPresentFlag; |
2481 | 0 | dst->vui.bEnableVideoSignalTypePresentFlag = src->vui.bEnableVideoSignalTypePresentFlag; |
2482 | 0 | dst->vui.videoFormat = src->vui.videoFormat; |
2483 | 0 | dst->vui.bEnableVideoFullRangeFlag = src->vui.bEnableVideoFullRangeFlag; |
2484 | 0 | dst->vui.bEnableColorDescriptionPresentFlag = src->vui.bEnableColorDescriptionPresentFlag; |
2485 | 0 | dst->vui.colorPrimaries = src->vui.colorPrimaries; |
2486 | 0 | dst->vui.transferCharacteristics = src->vui.transferCharacteristics; |
2487 | 0 | dst->vui.matrixCoeffs = src->vui.matrixCoeffs; |
2488 | 0 | dst->vui.bEnableChromaLocInfoPresentFlag = src->vui.bEnableChromaLocInfoPresentFlag; |
2489 | 0 | dst->vui.chromaSampleLocTypeTopField = src->vui.chromaSampleLocTypeTopField; |
2490 | 0 | dst->vui.chromaSampleLocTypeBottomField = src->vui.chromaSampleLocTypeBottomField; |
2491 | 0 | dst->vui.bEnableDefaultDisplayWindowFlag = src->vui.bEnableDefaultDisplayWindowFlag; |
2492 | 0 | dst->vui.defDispWinBottomOffset = src->vui.defDispWinBottomOffset; |
2493 | 0 | dst->vui.defDispWinLeftOffset = src->vui.defDispWinLeftOffset; |
2494 | 0 | dst->vui.defDispWinRightOffset = src->vui.defDispWinRightOffset; |
2495 | 0 | dst->vui.defDispWinTopOffset = src->vui.defDispWinTopOffset; |
2496 | |
|
2497 | 0 | if (src->masteringDisplayColorVolume) dst->masteringDisplayColorVolume=strdup( src->masteringDisplayColorVolume); |
2498 | 0 | else dst->masteringDisplayColorVolume = NULL; |
2499 | 0 | dst->maxLuma = src->maxLuma; |
2500 | 0 | dst->minLuma = src->minLuma; |
2501 | 0 | dst->bEmitCLL = src->bEmitCLL; |
2502 | 0 | dst->maxCLL = src->maxCLL; |
2503 | 0 | dst->maxFALL = src->maxFALL; |
2504 | 0 | dst->log2MaxPocLsb = src->log2MaxPocLsb; |
2505 | 0 | dst->bEmitVUIHRDInfo = src->bEmitVUIHRDInfo; |
2506 | 0 | dst->bEmitVUITimingInfo = src->bEmitVUITimingInfo; |
2507 | 0 | dst->maxSlices = src->maxSlices; |
2508 | 0 | dst->bOptQpPPS = src->bOptQpPPS; |
2509 | 0 | dst->bOptRefListLengthPPS = src->bOptRefListLengthPPS; |
2510 | 0 | dst->bMultiPassOptRPS = src->bMultiPassOptRPS; |
2511 | 0 | dst->scenecutBias = src->scenecutBias; |
2512 | 0 | dst->edgeTransitionThreshold = src->edgeTransitionThreshold; |
2513 | 0 | dst->gopLookahead = src->lookaheadDepth; |
2514 | 0 | dst->bOptCUDeltaQP = src->bOptCUDeltaQP; |
2515 | 0 | dst->analysisMultiPassDistortion = src->analysisMultiPassDistortion; |
2516 | 0 | dst->analysisMultiPassRefine = src->analysisMultiPassRefine; |
2517 | 0 | dst->bAQMotion = src->bAQMotion; |
2518 | 0 | dst->bSsimRd = src->bSsimRd; |
2519 | 0 | dst->dynamicRd = src->dynamicRd; |
2520 | 0 | dst->bEmitHDR10SEI = src->bEmitHDR10SEI; |
2521 | 0 | dst->bEmitHRDSEI = src->bEmitHRDSEI; |
2522 | 0 | dst->bHDROpt = src->bHDROpt; /*DEPRECATED*/ |
2523 | 0 | dst->bHDR10Opt = src->bHDR10Opt; |
2524 | 0 | dst->analysisReuseLevel = src->analysisReuseLevel; |
2525 | 0 | dst->analysisSaveReuseLevel = src->analysisSaveReuseLevel; |
2526 | 0 | dst->analysisLoadReuseLevel = src->analysisLoadReuseLevel; |
2527 | 0 | dst->bLimitSAO = src->bLimitSAO; |
2528 | 0 | if (src->toneMapFile) dst->toneMapFile = strdup(src->toneMapFile); |
2529 | 0 | else dst->toneMapFile = NULL; |
2530 | 0 | dst->bDhdr10opt = src->bDhdr10opt; |
2531 | 0 | dst->bCTUInfo = src->bCTUInfo; |
2532 | 0 | dst->bUseRcStats = src->bUseRcStats; |
2533 | 0 | dst->interRefine = src->interRefine; |
2534 | 0 | dst->intraRefine = src->intraRefine; |
2535 | 0 | dst->mvRefine = src->mvRefine; |
2536 | 0 | dst->maxLog2CUSize = src->maxLog2CUSize; |
2537 | 0 | dst->maxCUDepth = src->maxCUDepth; |
2538 | 0 | dst->unitSizeDepth = src->unitSizeDepth; |
2539 | 0 | dst->num4x4Partitions = src->num4x4Partitions; |
2540 | |
|
2541 | 0 | dst->csvfpt = src->csvfpt; |
2542 | 0 | dst->bEnableSplitRdSkip = src->bEnableSplitRdSkip; |
2543 | 0 | dst->bUseAnalysisFile = src->bUseAnalysisFile; |
2544 | 0 | dst->forceFlush = src->forceFlush; |
2545 | 0 | dst->bDisableLookahead = src->bDisableLookahead; |
2546 | 0 | dst->bLowPassDct = src->bLowPassDct; |
2547 | 0 | dst->vbvBufferEnd = src->vbvBufferEnd; |
2548 | 0 | dst->vbvEndFrameAdjust = src->vbvEndFrameAdjust; |
2549 | 0 | dst->bAnalysisType = src->bAnalysisType; |
2550 | 0 | dst->bCopyPicToFrame = src->bCopyPicToFrame; |
2551 | 0 | if (src->analysisSave) dst->analysisSave=strdup(src->analysisSave); |
2552 | 0 | else dst->analysisSave = NULL; |
2553 | 0 | if (src->analysisLoad) dst->analysisLoad=strdup(src->analysisLoad); |
2554 | 0 | else dst->analysisLoad = NULL; |
2555 | 0 | dst->gopLookahead = src->gopLookahead; |
2556 | 0 | dst->radl = src->radl; |
2557 | 0 | dst->selectiveSAO = src->selectiveSAO; |
2558 | 0 | dst->maxAUSizeFactor = src->maxAUSizeFactor; |
2559 | 0 | dst->bEmitIDRRecoverySEI = src->bEmitIDRRecoverySEI; |
2560 | 0 | dst->bDynamicRefine = src->bDynamicRefine; |
2561 | 0 | dst->bSingleSeiNal = src->bSingleSeiNal; |
2562 | 0 | dst->chunkStart = src->chunkStart; |
2563 | 0 | dst->chunkEnd = src->chunkEnd; |
2564 | 0 | if (src->naluFile) dst->naluFile=strdup(src->naluFile); |
2565 | 0 | else dst->naluFile = NULL; |
2566 | 0 | dst->scaleFactor = src->scaleFactor; |
2567 | 0 | dst->ctuDistortionRefine = src->ctuDistortionRefine; |
2568 | 0 | dst->bEnableHRDConcatFlag = src->bEnableHRDConcatFlag; |
2569 | 0 | dst->dolbyProfile = src->dolbyProfile; |
2570 | 0 | dst->bEnableSvtHevc = src->bEnableSvtHevc; |
2571 | 0 | dst->bEnableFades = src->bEnableFades; |
2572 | 0 | dst->bEnableSceneCutAwareQp = src->bEnableSceneCutAwareQp; |
2573 | 0 | dst->scenecutWindow = src->scenecutWindow; |
2574 | 0 | dst->maxQpDelta = src->maxQpDelta; |
2575 | 0 | dst->bField = src->bField; |
2576 | |
|
2577 | 0 | dst->confWinRightOffset = src->confWinRightOffset; |
2578 | 0 | dst->confWinBottomOffset = src->confWinBottomOffset; |
2579 | | #ifdef SVT_HEVC |
2580 | | memcpy(dst->svtHevcParam, src->svtHevcParam, sizeof(EB_H265_ENC_CONFIGURATION)); |
2581 | | #endif |
2582 | 0 | } |
2583 | | |
2584 | | #ifdef SVT_HEVC |
2585 | | |
2586 | | void svt_param_default(x265_param* param) |
2587 | | { |
2588 | | EB_H265_ENC_CONFIGURATION* svtHevcParam = (EB_H265_ENC_CONFIGURATION*)param->svtHevcParam; |
2589 | | |
2590 | | // Channel info |
2591 | | svtHevcParam->channelId = 0; |
2592 | | svtHevcParam->activeChannelCount = 0; |
2593 | | |
2594 | | // GOP Structure |
2595 | | svtHevcParam->intraPeriodLength = -2; |
2596 | | svtHevcParam->intraRefreshType = 1; |
2597 | | svtHevcParam->predStructure = 2; |
2598 | | svtHevcParam->baseLayerSwitchMode = 0; |
2599 | | svtHevcParam->hierarchicalLevels = 3; |
2600 | | svtHevcParam->sourceWidth = 0; |
2601 | | svtHevcParam->sourceHeight = 0; |
2602 | | svtHevcParam->latencyMode = 0; |
2603 | | |
2604 | | //Preset & Tune |
2605 | | svtHevcParam->encMode = 7; |
2606 | | svtHevcParam->tune = 1; |
2607 | | |
2608 | | // Interlaced Video |
2609 | | svtHevcParam->interlacedVideo = 0; |
2610 | | |
2611 | | // Quantization |
2612 | | svtHevcParam->qp = 32; |
2613 | | svtHevcParam->useQpFile = 0; |
2614 | | |
2615 | | // Deblock Filter |
2616 | | svtHevcParam->disableDlfFlag = 0; |
2617 | | |
2618 | | // SAO |
2619 | | svtHevcParam->enableSaoFlag = 1; |
2620 | | |
2621 | | // ME Tools |
2622 | | svtHevcParam->useDefaultMeHme = 1; |
2623 | | svtHevcParam->enableHmeFlag = 1; |
2624 | | |
2625 | | // ME Parameters |
2626 | | svtHevcParam->searchAreaWidth = 16; |
2627 | | svtHevcParam->searchAreaHeight = 7; |
2628 | | |
2629 | | // MD Parameters |
2630 | | svtHevcParam->constrainedIntra = 0; |
2631 | | |
2632 | | // Rate Control |
2633 | | svtHevcParam->frameRate = 60; |
2634 | | svtHevcParam->frameRateNumerator = 0; |
2635 | | svtHevcParam->frameRateDenominator = 0; |
2636 | | svtHevcParam->encoderBitDepth = 8; |
2637 | | svtHevcParam->encoderColorFormat = EB_YUV420; |
2638 | | svtHevcParam->compressedTenBitFormat = 0; |
2639 | | svtHevcParam->rateControlMode = 0; |
2640 | | svtHevcParam->sceneChangeDetection = 1; |
2641 | | svtHevcParam->lookAheadDistance = (uint32_t)~0; |
2642 | | svtHevcParam->framesToBeEncoded = 0; |
2643 | | svtHevcParam->targetBitRate = 7000000; |
2644 | | svtHevcParam->maxQpAllowed = 48; |
2645 | | svtHevcParam->minQpAllowed = 10; |
2646 | | svtHevcParam->bitRateReduction = 0; |
2647 | | |
2648 | | // Thresholds |
2649 | | svtHevcParam->improveSharpness = 0; |
2650 | | svtHevcParam->videoUsabilityInfo = 0; |
2651 | | svtHevcParam->highDynamicRangeInput = 0; |
2652 | | svtHevcParam->accessUnitDelimiter = 0; |
2653 | | svtHevcParam->bufferingPeriodSEI = 0; |
2654 | | svtHevcParam->pictureTimingSEI = 0; |
2655 | | svtHevcParam->registeredUserDataSeiFlag = 0; |
2656 | | svtHevcParam->unregisteredUserDataSeiFlag = 0; |
2657 | | svtHevcParam->recoveryPointSeiFlag = 0; |
2658 | | svtHevcParam->enableTemporalId = 1; |
2659 | | svtHevcParam->profile = 1; |
2660 | | svtHevcParam->tier = 0; |
2661 | | svtHevcParam->level = 0; |
2662 | | |
2663 | | svtHevcParam->injectorFrameRate = 60 << 16; |
2664 | | svtHevcParam->speedControlFlag = 0; |
2665 | | |
2666 | | // ASM Type |
2667 | | svtHevcParam->asmType = 1; |
2668 | | |
2669 | | svtHevcParam->codeVpsSpsPps = 1; |
2670 | | svtHevcParam->codeEosNal = 0; |
2671 | | svtHevcParam->reconEnabled = 0; |
2672 | | svtHevcParam->maxCLL = 0; |
2673 | | svtHevcParam->maxFALL = 0; |
2674 | | svtHevcParam->useMasteringDisplayColorVolume = 0; |
2675 | | svtHevcParam->useNaluFile = 0; |
2676 | | svtHevcParam->whitePointX = 0; |
2677 | | svtHevcParam->whitePointY = 0; |
2678 | | svtHevcParam->maxDisplayMasteringLuminance = 0; |
2679 | | svtHevcParam->minDisplayMasteringLuminance = 0; |
2680 | | svtHevcParam->dolbyVisionProfile = 0; |
2681 | | svtHevcParam->targetSocket = -1; |
2682 | | svtHevcParam->logicalProcessors = 0; |
2683 | | svtHevcParam->switchThreadsToRtPriority = 1; |
2684 | | svtHevcParam->fpsInVps = 0; |
2685 | | |
2686 | | svtHevcParam->tileColumnCount = 1; |
2687 | | svtHevcParam->tileRowCount = 1; |
2688 | | svtHevcParam->tileSliceMode = 0; |
2689 | | svtHevcParam->unrestrictedMotionVector = 1; |
2690 | | svtHevcParam->threadCount = 0; |
2691 | | |
2692 | | // vbv |
2693 | | svtHevcParam->hrdFlag = 0; |
2694 | | svtHevcParam->vbvMaxrate = 0; |
2695 | | svtHevcParam->vbvBufsize = 0; |
2696 | | svtHevcParam->vbvBufInit = 90; |
2697 | | } |
2698 | | |
2699 | | int svt_set_preset(x265_param* param, const char* preset) |
2700 | | { |
2701 | | EB_H265_ENC_CONFIGURATION* svtHevcParam = (EB_H265_ENC_CONFIGURATION*)param->svtHevcParam; |
2702 | | |
2703 | | if (preset) |
2704 | | { |
2705 | | if (!strcmp(preset, "ultrafast")) svtHevcParam->encMode = 11; |
2706 | | else if (!strcmp(preset, "superfast")) svtHevcParam->encMode = 10; |
2707 | | else if (!strcmp(preset, "veryfast")) svtHevcParam->encMode = 9; |
2708 | | else if (!strcmp(preset, "faster")) svtHevcParam->encMode = 8; |
2709 | | else if (!strcmp(preset, "fast")) svtHevcParam->encMode = 7; |
2710 | | else if (!strcmp(preset, "medium")) svtHevcParam->encMode = 6; |
2711 | | else if (!strcmp(preset, "slow")) svtHevcParam->encMode = 5; |
2712 | | else if (!strcmp(preset, "slower")) svtHevcParam->encMode =4; |
2713 | | else if (!strcmp(preset, "veryslow")) svtHevcParam->encMode = 3; |
2714 | | else if (!strcmp(preset, "placebo")) svtHevcParam->encMode = 2; |
2715 | | else return -1; |
2716 | | } |
2717 | | return 0; |
2718 | | } |
2719 | | |
2720 | | int svt_param_parse(x265_param* param, const char* name, const char* value) |
2721 | | { |
2722 | | bool bError = false; |
2723 | | #define OPT(STR) else if (!strcmp(name, STR)) |
2724 | | |
2725 | | EB_H265_ENC_CONFIGURATION* svtHevcParam = (EB_H265_ENC_CONFIGURATION*)param->svtHevcParam; |
2726 | | if (0); |
2727 | | OPT("input-res") bError |= sscanf(value, "%dx%d", &svtHevcParam->sourceWidth, &svtHevcParam->sourceHeight) != 2; |
2728 | | OPT("input-depth") svtHevcParam->encoderBitDepth = atoi(value); |
2729 | | OPT("total-frames") svtHevcParam->framesToBeEncoded = atoi(value); |
2730 | | OPT("frames") svtHevcParam->framesToBeEncoded = atoi(value); |
2731 | | OPT("fps") |
2732 | | { |
2733 | | if (sscanf(value, "%u/%u", &svtHevcParam->frameRateNumerator, &svtHevcParam->frameRateDenominator) == 2) |
2734 | | ; |
2735 | | else |
2736 | | { |
2737 | | int fps = atoi(value); |
2738 | | svtHevcParam->frameRateDenominator = 1; |
2739 | | |
2740 | | if (fps < 1000) |
2741 | | svtHevcParam->frameRate = fps << 16; |
2742 | | else |
2743 | | svtHevcParam->frameRate = fps; |
2744 | | } |
2745 | | } |
2746 | | OPT2("level-idc", "level") |
2747 | | { |
2748 | | /* allow "5.1" or "51", both converted to integer 51 */ |
2749 | | /* if level-idc specifies an obviously wrong value in either float or int, |
2750 | | throw error consistently. Stronger level checking will be done in encoder_open() */ |
2751 | | if (atof(value) < 10) |
2752 | | svtHevcParam->level = (int)(10 * atof(value) + .5); |
2753 | | else if (atoi(value) < 100) |
2754 | | svtHevcParam->level = atoi(value); |
2755 | | else |
2756 | | bError = true; |
2757 | | } |
2758 | | OPT2("pools", "numa-pools") |
2759 | | { |
2760 | | char *pools = strdup(value); |
2761 | | char *temp1, *temp2; |
2762 | | int count = 0; |
2763 | | |
2764 | | for (temp1 = strstr(pools, ","); temp1 != NULL; temp1 = strstr(temp2, ",")) |
2765 | | { |
2766 | | temp2 = ++temp1; |
2767 | | count++; |
2768 | | } |
2769 | | |
2770 | | if (count > 1) |
2771 | | x265_log(param, X265_LOG_WARNING, "SVT-HEVC Encoder supports pools option only upto 2 sockets \n"); |
2772 | | else if (count == 1) |
2773 | | { |
2774 | | temp1 = strtok(pools, ","); |
2775 | | temp2 = strtok(NULL, ","); |
2776 | | |
2777 | | if (!strcmp(temp1, "+")) |
2778 | | { |
2779 | | if (!strcmp(temp2, "+")) svtHevcParam->targetSocket = -1; |
2780 | | else if (!strcmp(temp2, "-")) svtHevcParam->targetSocket = 0; |
2781 | | else svtHevcParam->targetSocket = -1; |
2782 | | } |
2783 | | else if (!strcmp(temp1, "-")) |
2784 | | { |
2785 | | if (!strcmp(temp2, "+")) svtHevcParam->targetSocket = 1; |
2786 | | else if (!strcmp(temp2, "-")) x265_log(param, X265_LOG_ERROR, "Shouldn't exclude both sockets for pools option %s \n", pools); |
2787 | | else if (!strcmp(temp2, "*")) svtHevcParam->targetSocket = 1; |
2788 | | else |
2789 | | { |
2790 | | svtHevcParam->targetSocket = 1; |
2791 | | svtHevcParam->logicalProcessors = atoi(temp2); |
2792 | | } |
2793 | | } |
2794 | | else svtHevcParam->targetSocket = -1; |
2795 | | } |
2796 | | else |
2797 | | { |
2798 | | if (!strcmp(temp1, "*")) svtHevcParam->targetSocket = -1; |
2799 | | else |
2800 | | { |
2801 | | svtHevcParam->targetSocket = 0; |
2802 | | svtHevcParam->logicalProcessors = atoi(temp1); |
2803 | | } |
2804 | | } |
2805 | | } |
2806 | | OPT("high-tier") svtHevcParam->tier = x265_atobool(value, bError); |
2807 | | OPT("qpmin") svtHevcParam->minQpAllowed = atoi(value); |
2808 | | OPT("qpmax") svtHevcParam->maxQpAllowed = atoi(value); |
2809 | | OPT("rc-lookahead") svtHevcParam->lookAheadDistance = atoi(value); |
2810 | | OPT("scenecut") |
2811 | | { |
2812 | | svtHevcParam->sceneChangeDetection = x265_atobool(value, bError); |
2813 | | if (bError || svtHevcParam->sceneChangeDetection) |
2814 | | { |
2815 | | bError = false; |
2816 | | svtHevcParam->sceneChangeDetection = 1; |
2817 | | } |
2818 | | } |
2819 | | OPT("open-gop") |
2820 | | { |
2821 | | if (x265_atobool(value, bError)) |
2822 | | svtHevcParam->intraRefreshType = 1; |
2823 | | else |
2824 | | svtHevcParam->intraRefreshType = 2; |
2825 | | } |
2826 | | OPT("deblock") |
2827 | | { |
2828 | | if (strtol(value, NULL, 0)) |
2829 | | svtHevcParam->disableDlfFlag = 0; |
2830 | | else if (x265_atobool(value, bError) == 0 && !bError) |
2831 | | svtHevcParam->disableDlfFlag = 1; |
2832 | | } |
2833 | | OPT("sao") svtHevcParam->enableSaoFlag = (uint8_t)x265_atobool(value, bError); |
2834 | | OPT("keyint") svtHevcParam->intraPeriodLength = atoi(value); |
2835 | | OPT2("constrained-intra", "cip") svtHevcParam->constrainedIntra = (uint8_t)x265_atobool(value, bError); |
2836 | | OPT("vui-timing-info") svtHevcParam->videoUsabilityInfo = x265_atobool(value, bError); |
2837 | | OPT("hdr") svtHevcParam->highDynamicRangeInput = x265_atobool(value, bError); |
2838 | | OPT("aud") svtHevcParam->accessUnitDelimiter = x265_atobool(value, bError); |
2839 | | OPT("qp") |
2840 | | { |
2841 | | svtHevcParam->rateControlMode = 0; |
2842 | | svtHevcParam->qp = atoi(value); |
2843 | | } |
2844 | | OPT("bitrate") |
2845 | | { |
2846 | | svtHevcParam->rateControlMode = 1; |
2847 | | svtHevcParam->targetBitRate = atoi(value); |
2848 | | } |
2849 | | OPT("interlace") |
2850 | | { |
2851 | | svtHevcParam->interlacedVideo = (uint8_t)x265_atobool(value, bError); |
2852 | | if (bError || svtHevcParam->interlacedVideo) |
2853 | | { |
2854 | | bError = false; |
2855 | | svtHevcParam->interlacedVideo = 1; |
2856 | | } |
2857 | | } |
2858 | | OPT("svt-hme") |
2859 | | { |
2860 | | svtHevcParam->enableHmeFlag = (uint8_t)x265_atobool(value, bError); |
2861 | | if (svtHevcParam->enableHmeFlag) svtHevcParam->useDefaultMeHme = 1; |
2862 | | } |
2863 | | OPT("svt-search-width") svtHevcParam->searchAreaWidth = atoi(value); |
2864 | | OPT("svt-search-height") svtHevcParam->searchAreaHeight = atoi(value); |
2865 | | OPT("svt-compressed-ten-bit-format") svtHevcParam->compressedTenBitFormat = x265_atobool(value, bError); |
2866 | | OPT("svt-speed-control") svtHevcParam->speedControlFlag = x265_atobool(value, bError); |
2867 | | OPT("svt-preset-tuner") |
2868 | | { |
2869 | | if (svtHevcParam->encMode == 2) |
2870 | | { |
2871 | | if (!strcmp(value, "0")) svtHevcParam->encMode = 0; |
2872 | | else if (!strcmp(value, "1")) svtHevcParam->encMode = 1; |
2873 | | else |
2874 | | { |
2875 | | x265_log(param, X265_LOG_ERROR, " Unsupported value=%s for svt-preset-tuner \n", value); |
2876 | | bError = true; |
2877 | | } |
2878 | | } |
2879 | | else |
2880 | | x265_log(param, X265_LOG_WARNING, " svt-preset-tuner should be used only with ultrafast preset; Ignoring it \n"); |
2881 | | } |
2882 | | OPT("svt-hierarchical-level") svtHevcParam->hierarchicalLevels = atoi(value); |
2883 | | OPT("svt-base-layer-switch-mode") svtHevcParam->baseLayerSwitchMode = atoi(value); |
2884 | | OPT("svt-pred-struct") svtHevcParam->predStructure = (uint8_t)atoi(value); |
2885 | | OPT("svt-fps-in-vps") svtHevcParam->fpsInVps = (uint8_t)x265_atobool(value, bError); |
2886 | | OPT("master-display") svtHevcParam->useMasteringDisplayColorVolume = (uint8_t)atoi(value); |
2887 | | OPT("max-cll") bError |= sscanf(value, "%hu,%hu", &svtHevcParam->maxCLL, &svtHevcParam->maxFALL) != 2; |
2888 | | OPT("nalu-file") svtHevcParam->useNaluFile = (uint8_t)atoi(value); |
2889 | | OPT("dolby-vision-profile") |
2890 | | { |
2891 | | if (atof(value) < 10) |
2892 | | svtHevcParam->dolbyVisionProfile = (int)(10 * atof(value) + .5); |
2893 | | else if (atoi(value) < 100) |
2894 | | svtHevcParam->dolbyVisionProfile = atoi(value); |
2895 | | else |
2896 | | bError = true; |
2897 | | } |
2898 | | OPT("hrd") |
2899 | | svtHevcParam->hrdFlag = (uint32_t)x265_atobool(value, bError); |
2900 | | OPT("vbv-maxrate") |
2901 | | svtHevcParam->vbvMaxrate = (uint32_t)x265_atoi(value, bError); |
2902 | | OPT("vbv-bufsize") |
2903 | | svtHevcParam->vbvBufsize = (uint32_t)x265_atoi(value, bError); |
2904 | | OPT("vbv-init") |
2905 | | svtHevcParam->vbvBufInit = (uint64_t)x265_atof(value, bError); |
2906 | | OPT("frame-threads") |
2907 | | svtHevcParam->threadCount = (uint32_t)x265_atoi(value, bError); |
2908 | | else |
2909 | | x265_log(param, X265_LOG_INFO, "SVT doesn't support %s param; Disabling it \n", name); |
2910 | | |
2911 | | |
2912 | | return bError ? X265_PARAM_BAD_VALUE : 0; |
2913 | | } |
2914 | | |
2915 | | #endif //ifdef SVT_HEVC |
2916 | | |
2917 | | } |