Coverage Report

Created: 2026-12-01 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/source/Lib/apputils/VVEncAppCfg.h
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
------------------------------------------------------------------------------------------- */
41
/** \file     VVEncAppCfg.h
42
    \brief    Handle encoder configuration parameters (header)
43
*/
44
45
#pragma once
46
47
#include "vvenc/vvencCfg.h"
48
#include "vvenc/vvenc.h"
49
50
51
#include <string>
52
#include <vector>
53
#include <tuple>
54
#include <functional>
55
56
#include <cstring>
57
#include <fstream>
58
#include <sstream>
59
#include <algorithm>
60
#include <cstdarg>
61
62
#include "IStreamIO.h"
63
#include "ParseArg.h"
64
#include "YuvFileIO.h"
65
66
#define MACRO_TO_STRING_HELPER(val) #val
67
#define MACRO_TO_STRING(val) MACRO_TO_STRING_HELPER(val)
68
69
using namespace std;
70
namespace po = apputils::program_options;
71
72
namespace apputils {
73
74
//! \ingroup apputils
75
//! \{
76
77
78
// ====================================================================================================================
79
// enums
80
// ====================================================================================================================
81
enum BitDepthAndColorSpace
82
{
83
  YUV420_8,
84
  YUV420_10,
85
  YUV422_8,
86
  YUV422_10,
87
  YUV444_8,
88
  YUV444_10,
89
  YUV400_8,
90
  YUV400_10,
91
  YUV420_10_PACKED
92
};
93
94
// ====================================================================================================================
95
// string <-> enum fixed mappings
96
// ====================================================================================================================
97
const std::vector<SVPair<vvencMsgLevel>> MsgLevelToEnumMap =
98
{
99
  { "silent",  vvencMsgLevel::VVENC_SILENT  },
100
  { "error",   vvencMsgLevel::VVENC_ERROR   },
101
  { "warning", vvencMsgLevel::VVENC_WARNING },
102
  { "info",    vvencMsgLevel::VVENC_INFO    },
103
  { "notice",  vvencMsgLevel::VVENC_NOTICE  },
104
  { "verbose", vvencMsgLevel::VVENC_VERBOSE },
105
  { "details", vvencMsgLevel::VVENC_DETAILS },
106
  { "0",       vvencMsgLevel::VVENC_SILENT  },
107
  { "1",       vvencMsgLevel::VVENC_ERROR   },
108
  { "2",       vvencMsgLevel::VVENC_WARNING },
109
  { "3",       vvencMsgLevel::VVENC_INFO    },
110
  { "4",       vvencMsgLevel::VVENC_NOTICE  },
111
  { "5",       vvencMsgLevel::VVENC_VERBOSE },
112
  { "6",       vvencMsgLevel::VVENC_DETAILS },
113
};
114
115
116
const std::vector<SVPair<vvencPresetMode>> PresetToEnumMap =
117
{
118
  { "none",      vvencPresetMode::VVENC_NONE },
119
  { "faster",    vvencPresetMode::VVENC_FASTER },
120
  { "fast",      vvencPresetMode::VVENC_FAST },
121
  { "medium",    vvencPresetMode::VVENC_MEDIUM },
122
  { "slow",      vvencPresetMode::VVENC_SLOW },
123
  { "slower",    vvencPresetMode::VVENC_SLOWER },
124
  { "0",         vvencPresetMode::VVENC_FASTER },
125
  { "1",         vvencPresetMode::VVENC_FAST },
126
  { "2",         vvencPresetMode::VVENC_MEDIUM },
127
  { "3",         vvencPresetMode::VVENC_SLOW },
128
  { "4",         vvencPresetMode::VVENC_SLOWER },
129
  { "medium_lowDecEnergy", vvencPresetMode::VVENC_MEDIUM_LOWDECNRG },
130
  { "medium_lowdecenergy", vvencPresetMode::VVENC_MEDIUM_LOWDECNRG },
131
  { "firstpass", vvencPresetMode::VVENC_FIRSTPASS },
132
  { "tooltest",  vvencPresetMode::VVENC_TOOLTEST },
133
};
134
135
const std::vector<SVPair<vvencSegmentMode>> SegmentToEnumMap =
136
{
137
  { "off",      vvencSegmentMode::VVENC_SEG_OFF },
138
  { "first",    vvencSegmentMode::VVENC_SEG_FIRST },
139
  { "mid",      vvencSegmentMode::VVENC_SEG_MID },
140
  { "last",     vvencSegmentMode::VVENC_SEG_LAST },
141
};
142
143
144
const std::vector<SVPair<vvencProfile>> ProfileToEnumMap =
145
{
146
  { "main_10",                               vvencProfile::VVENC_MAIN_10 },
147
  { "main_10_444",                           vvencProfile::VVENC_MAIN_10_444 },
148
  { "main_10_still_picture",                 vvencProfile::VVENC_MAIN_10_STILL_PICTURE },
149
  { "main_10_444_still_picture",             vvencProfile::VVENC_MAIN_10_444_STILL_PICTURE },
150
  { "multilayer_main_10",                    vvencProfile::VVENC_MULTILAYER_MAIN_10 },
151
  { "multilayer_main_10_444",                vvencProfile::VVENC_MULTILAYER_MAIN_10_444 },
152
  { "multilayer_main_10_still_picture",      vvencProfile::VVENC_MULTILAYER_MAIN_10_STILL_PICTURE },
153
  { "multilayer_main_10_444_still_picture",  vvencProfile::VVENC_MULTILAYER_MAIN_10_444_STILL_PICTURE },
154
  { "auto",                                  vvencProfile::VVENC_PROFILE_AUTO },
155
};
156
157
const std::vector<SVPair<vvencLevel>> LevelToEnumMap =
158
{
159
  { "auto",                    VVENC_LEVEL_AUTO},
160
  { "1",                       VVENC_LEVEL1    },
161
  { "1.0",                     VVENC_LEVEL1    },
162
  { "2",                       VVENC_LEVEL2    },
163
  { "2.0",                     VVENC_LEVEL2    },
164
  { "2.1",                     VVENC_LEVEL2_1  },
165
  { "3",                       VVENC_LEVEL3    },
166
  { "3.0",                     VVENC_LEVEL3    },
167
  { "3.1",                     VVENC_LEVEL3_1  },
168
  { "4",                       VVENC_LEVEL4    },
169
  { "4.0",                     VVENC_LEVEL4    },
170
  { "4.1",                     VVENC_LEVEL4_1  },
171
  { "5",                       VVENC_LEVEL5    },
172
  { "5.0",                     VVENC_LEVEL5    },
173
  { "5.1",                     VVENC_LEVEL5_1  },
174
  { "5.2",                     VVENC_LEVEL5_2  },
175
  { "6",                       VVENC_LEVEL6    },
176
  { "6.0",                     VVENC_LEVEL6    },
177
  { "6.1",                     VVENC_LEVEL6_1  },
178
  { "6.2",                     VVENC_LEVEL6_2  },
179
  { "6.3",                     VVENC_LEVEL6_3  },
180
  { "15.5",                    VVENC_LEVEL15_5 },
181
};
182
183
const std::vector<SVPair<vvencTier>> TierToEnumMap =
184
{
185
  { "main",                    vvencTier::VVENC_TIER_MAIN },
186
  { "high",                    vvencTier::VVENC_TIER_HIGH },
187
};
188
189
const std::vector<SVPair<vvencCostMode>> CostModeToEnumMap =
190
{
191
  { "lossy",                   VVENC_COST_STANDARD_LOSSY              },
192
  { "sequence_level_lossless", VVENC_COST_SEQUENCE_LEVEL_LOSSLESS     },
193
  { "lossless",                VVENC_COST_LOSSLESS_CODING             },
194
  { "mixed_lossless_lossy",    VVENC_COST_MIXED_LOSSLESS_LOSSY_CODING }
195
};
196
197
const std::vector<SVPair<vvencChromaFormat>> ChromaFormatToEnumMap =
198
{
199
  { "400",                     VVENC_CHROMA_400 },
200
  { "420",                     VVENC_CHROMA_420 },
201
  { "422",                     VVENC_CHROMA_422 },
202
  { "444",                     VVENC_CHROMA_444 },
203
  { "0",                       VVENC_NUM_CHROMA_FORMAT }
204
};
205
206
const std::vector<SVPair<vvencHashType>> HashTypeToEnumMap =
207
{
208
  { "md5",                     VVENC_HASHTYPE_MD5          },
209
  { "crc",                     VVENC_HASHTYPE_CRC          },
210
  { "checksum",                VVENC_HASHTYPE_CHECKSUM     },
211
  { "log_md5",                 VVENC_HASHTYPE_MD5_LOG      },
212
  { "log_crc",                 VVENC_HASHTYPE_CRC_LOG      },
213
  { "log_checksum",            VVENC_HASHTYPE_CHECKSUM_LOG },
214
  { "off",                     VVENC_HASHTYPE_NONE         },
215
  // for backward compatibility support values as well
216
  { "1",                       VVENC_HASHTYPE_MD5          },
217
  { "2",                       VVENC_HASHTYPE_CRC          },
218
  { "3",                       VVENC_HASHTYPE_CHECKSUM     },
219
  { "11",                      VVENC_HASHTYPE_MD5_LOG      },
220
  { "12",                      VVENC_HASHTYPE_CRC_LOG      },
221
  { "13",                      VVENC_HASHTYPE_CHECKSUM_LOG },
222
  { "0",                       VVENC_HASHTYPE_NONE         }
223
};
224
225
const std::vector<SVPair<vvencDecodingRefreshType>> DecodingRefreshTypeToEnumMap =
226
{
227
  { "none",                  VVENC_DRT_NONE },
228
  { "cra",                   VVENC_DRT_CRA },
229
  { "idr",                   VVENC_DRT_IDR },
230
  { "rpsei",                 VVENC_DRT_RECOVERY_POINT_SEI },
231
  { "idr2",                  VVENC_DRT_IDR2 }, //deprecated
232
  { "cra_cre",               VVENC_DRT_CRA_CRE },
233
  { "idr_no_radl",           VVENC_DRT_IDR_NO_RADL },
234
  { "0",                     VVENC_DRT_NONE },
235
  { "1",                     VVENC_DRT_CRA },
236
  { "2",                     VVENC_DRT_IDR },
237
  { "3",                     VVENC_DRT_RECOVERY_POINT_SEI },
238
  { "4",                     VVENC_DRT_IDR2 },  //deprecated
239
  { "5",                     VVENC_DRT_CRA_CRE },
240
  { "6",                     VVENC_DRT_IDR_NO_RADL },
241
};
242
243
const std::vector<SVPair<BitDepthAndColorSpace>> BitColorSpaceToIntMap =
244
{
245
  { "yuv420",                    YUV420_8 },
246
  { "yuv420_10",                 YUV420_10 },
247
  { "yuv420_10_packed",          YUV420_10_PACKED },
248
  { "yuv400",                    YUV400_8 },
249
  { "gray",                      YUV400_8 },
250
  { "yuv400_10",                 YUV400_10 },
251
  { "gray10",                    YUV400_10 },
252
};
253
254
const std::vector<SVPair<int>> SaoToIntMap =
255
{
256
  { "0", 0 },
257
  { "1", 1 },
258
  { "2", 2 },
259
};
260
261
const std::vector<SVPair<vvencHDRMode>> SdrModeToIntMap =
262
{
263
  { "off",                 VVENC_HDR_OFF },
264
  { "sdr",                 VVENC_SDR_BT709},
265
  { "sdr_709",             VVENC_SDR_BT709},
266
  { "sdr709",              VVENC_SDR_BT709},
267
  { "sdr_2020",            VVENC_SDR_BT2020},
268
  { "sdr2020",             VVENC_SDR_BT2020},
269
  { "sdr_470bg",           VVENC_SDR_BT470BG},
270
  { "sdr470bg",            VVENC_SDR_BT470BG},
271
};
272
273
const std::vector<SVPair<vvencHDRMode>> HdrModeToIntMap =
274
{
275
  { "off",                 VVENC_HDR_OFF },
276
  { "pq",                  VVENC_HDR_PQ},
277
  { "hdr10",               VVENC_HDR_PQ},
278
  { "pq_2020",             VVENC_HDR_PQ_BT2020},
279
  { "hdr10_2020",          VVENC_HDR_PQ_BT2020},
280
  { "hlg",                 VVENC_HDR_HLG},
281
  { "hlg_2020",            VVENC_HDR_HLG_BT2020},
282
};
283
284
285
const std::vector<SVPair<int>> ColourPrimariesToIntMap =
286
{
287
  { "reserved",            0 },
288
  { "bt709",               1 },
289
  { "unknown",             2 },
290
  { "empty",               3 },
291
  { "bt470m",              4 },
292
  { "bt470bg",             5 },
293
  { "smpte170m",           6 },
294
  { "smpte240m",           7 },
295
  { "film",                8 },
296
  { "bt2020",              9 },
297
  { "smpte428",           10 },
298
  { "smpte431",           11 },
299
  { "smpte432",           12 },
300
  { "0", 0 }, { "1", 1 }, { "2", 2 }, { "3", 3 }, { "4", 4 }, { "5", 5 },
301
  { "6", 6 }, { "7", 7 }, { "8", 8 }, { "9", 9 }, { "10",10 }, { "11",11 }, { "12",12 }
302
};
303
304
const std::vector<SVPair<int>> TransferCharacteristicsToIntMap =
305
{
306
  { "auto",               -1 },
307
  { "reserved",            0 },
308
  { "bt709",               1 },
309
  { "unknown",             2 },
310
  { "empty",               3 },
311
  { "bt470m",              4 },
312
  { "bt470bg",             5 },
313
  { "smpte170m",           6 },
314
  { "smpte240m",           7 },
315
  { "linear",              8 },
316
  { "log100",              9 },
317
  { "log316",             10 },
318
  { "iec61966",           11 },
319
  { "bt1361e",            12 },
320
  { "iec61966-2-1",       13 },
321
  { "bt2020-10",          14 },
322
  { "bt2020-12",          15 },
323
  { "smpte2084",          16 },
324
  { "smpte428",           17 },
325
  { "arib-std-b67",       18 },
326
  { "0", 0 }, { "1", 1 }, { "2", 2 }, { "3", 3 }, { "4", 4 }, { "5", 5 },
327
  { "6", 6 }, { "7", 7 }, { "8", 8 }, { "9", 9 }, { "10",10 }, { "11",11 },
328
  { "12",12 },{ "13",13 },{ "14",14 },{ "15",15 },{ "16",16 },{ "17",17 },{ "18",18 }
329
};
330
331
const std::vector<SVPair<int>> ColourMatrixToIntMap =
332
{
333
  { "gbr",              0 },
334
  { "bt709",            1 },
335
  { "unknown",          2 },
336
  { "empty",            3 },
337
  { "fcc",              4 },
338
  { "bt470bg",          5 },
339
  { "smpte170m",        6 },
340
  { "smpte240m",        7 },
341
  { "ycgco",            8 },
342
  { "bt2020nc",         9 },
343
  { "bt2020c",          10 },
344
  { "smpte2085",        11 },
345
  { "chroma-derived-nc",12 },
346
  { "chroma-derived-c", 13 },
347
  { "ictcp",            14 },
348
  { "0", 0 }, { "1", 1 }, { "2", 2 }, { "3", 3 }, { "4", 4 }, { "5", 5 },
349
  { "6", 6 }, { "7", 7 }, { "8", 8 }, { "9", 9 }, { "10",10 }, { "11",11 },
350
  { "12",12 },{ "13",13 },{ "14",14 }
351
};
352
353
template<typename T>
354
const std::vector<SVPair<T>> FlagToIntMap =
355
{
356
  { "auto",        T(-1) },
357
  { "-1",          T(-1) },
358
359
  { "off",         T( 0) },
360
  { "disable",     T( 0) },
361
  { "0",           T( 0) },
362
363
  { "on",          T( 1) },
364
  { "enable",      T( 1) },
365
  { "1",           T( 1) },
366
};
367
368
// this is only needed for backward compatibility and will be removed in the next release
369
const std::vector<SVPair<bool>> QPAToIntMap =
370
{
371
  { "off",          0 },
372
  { "disable",      0 },
373
  { "0",            0 },
374
375
  { "on",           1 },
376
  { "enable",       1 },
377
  { "1",            1 },
378
  { "2",            1 }, // map deprecated modes 2-5 to qpa enabled
379
  { "3",            1 },
380
  { "4",            1 },
381
  { "5",            1 },
382
};
383
384
// abbreviations for target bitrates that are converted into bps internally (lower/upper case independent)
385
const std::vector<SVPair<int>> BitrateAbrevToIntMap =
386
{
387
  { "Mbps",         1000000 },  // mega bit/sec
388
  { "M",            1000000 },
389
  { "kbps",            1000 },  // kilo bit/sec
390
  { "k",               1000 },
391
  { "bps",                1 }   // bit/sec
392
};
393
394
const std::vector<SVPair<int>> BitrateOrScaleAbrevToIntMap =
395
{
396
  { "Mbps",         1000000 },  // mega bit/sec
397
  { "M",            1000000 },
398
  { "kbps",            1000 },  // kilo bit/sec
399
  { "k",               1000 },
400
  { "bps",                1 },  //      bit/sec
401
  { "x",                -16 }   // negative value: multiplier of target bitrate, with a fixed-point accuracy of 4 bit
402
};
403
404
const std::vector<SVPair<int8_t>> MtAbrevToIntMap =
405
{
406
  { "auto",     -1 },
407
  { "-1",       -1 },
408
409
  { "off",       0 },
410
  { "disable",   0 },
411
  { "0",         0 },
412
413
  { "1",         1 },
414
  { "2",         2 },
415
  { "3",         3 }
416
};
417
418
const std::vector<SVPair<int>> RangeToFullRangeFlagMap =
419
{
420
  { "unknown",     0 },
421
  { "unspecified", 0 },
422
  { "limited",     1 },
423
  { "mpeg",        1 },
424
  { "tv",          1 },
425
  { "0",           1 },
426
  { "full",        2 },
427
  { "jpeg",        2 },
428
  { "pc",          2 },
429
  { "1",           2 },
430
};
431
432
//// ====================================================================================================================
433
//// string <-> enum
434
//// ====================================================================================================================
435
436
class VVEncAppCfg;
437
438
static void setPresets( VVEncAppCfg* appcfg, vvenc_config* cfg,  int preset );
439
440
static void setInputBitDepthAndColorSpace( VVEncAppCfg* appcfg, vvenc_config* cfg, int dbcs );
441
442
static void setSAO( VVEncAppCfg *appcfg, vvenc_config *cfg, int saoVal );
443
444
static void setColourRange( VVEncAppCfg* appcfg, vvenc_config *cfg, int colourRange );
445
446
447
// ====================================================================================================================
448
// Class definition
449
// ====================================================================================================================
450
451
/// application params and parser class for app+lib options
452
class VVEncAppCfg
453
{
454
public:
455
  typedef std::function<void( vvenc_config*, vvencPresetMode ) > presetChangeCallback;
456
457
public:
458
  std::string  m_inputFileName;                                ///< source file name
459
  std::string  m_bitstreamFileName;                            ///< output bitstream file
460
  std::string  m_reconFileName;                                ///< output reconstruction file
461
  std::string  m_RCStatsFileName;                              ///< rate control statistics file
462
  vvencChromaFormat m_inputFileChromaFormat    = VVENC_CHROMA_420;
463
  int          m_FrameSkip                     = 0;            ///< number of skipped frames from the beginning
464
  bool         m_bClipInputVideoToRec709Range  = false;
465
  bool         m_bClipOutputVideoToRec709Range = false;
466
  bool         m_packedYUVInput                = false;        ///< If true, packed 10-bit YUV ( 4 samples packed into 5-bytes consecutively )
467
  bool         m_packedYUVOutput               = false;        ///< If true, output 10-bit and 12-bit YUV data as 5-byte and 3-byte (respectively) packed YUV data
468
  bool         m_forceY4mInput                 = false;        ///< If true, y4m input file syntax is forced (only needed for input via std::cin)
469
  bool         m_showVersion                   = false;
470
  bool         m_showHelp                      = false;
471
  bool         m_printStats                    = true;
472
473
  std::string  m_additionalSettings;                           ///< set additional settings (always parsed and set after other params are set)
474
                                                               ///< options must be defined as tuple key=value, entries must be separated by space' ' or colon ':'
475
                                                               ///< values that are not arbitrary must be quoted "\"values\""
476
                                                               ///< e.b. "bitrate=1000000 passes=1 QpInValCb=\"17 22 34 42\"" 
477
  std::string  m_logoFileName;                                 ///< logo overlay file
478
private:
479
  const bool   m_easyMode                      = false;        ///< internal state flag, if expert or easy mode
480
481
  presetChangeCallback  m_changePresetCallback = nullptr;
482
public:
483
484
  VVEncAppCfg( bool easyMode = false )
485
0
  : m_easyMode (easyMode )
486
0
  {
487
488
0
  }
489
0
  virtual ~VVEncAppCfg(){}
490
491
  void setPresetChangeCallback( presetChangeCallback callback )
492
0
  {
493
0
    m_changePresetCallback = callback;
494
0
  }
495
496
  presetChangeCallback getPresetChangeCallback( )
497
0
  {
498
0
    return m_changePresetCallback ;
499
0
  }
500
501
public:
502
503
/* parse
504
  This method parses a list of command line arguments and sets them in the vvenc_config
505
  \param[in]  argc number or arguments in argv string list
506
  \param[in]  argv list of char* (argv[]); option name must be defined by prefix -- or -
507
  \param[in]  vvenc_config* pointer to vvenc_config struct that contains encoder parameters
508
  \param[in]  std::ostream& reference to ostream where info,warnings and errors are written to
509
  \retval     returns 0 on success,
510
              < o on error
511
              > 0 :  1 when information is printed into ostream (help)
512
                      2 when warning is printed into ostream
513
*/
514
int parse( int argc, char* argv[], vvenc_config* c, std::ostream& rcOstr )
515
0
{
516
0
  int ret = 0;
517
518
  //
519
  // setup configuration parameters
520
  //
521
0
  bool do_help                = false;
522
0
  bool do_full_help           = false;
523
524
0
  int  warnUnknowParameter    = 0;
525
0
  std::string ignoreParams;
526
527
0
  std::string writeCfg = "";
528
529
0
  vvencHDRMode hdrMode = c->m_HdrMode;
530
0
  vvencHDRMode sdrMode = c->m_HdrMode;
531
532
0
  IStreamToEnum<vvencMsgLevel>      toMsgLevel                   ( &c->m_verbosity,   &MsgLevelToEnumMap );
533
0
  IStreamToFunc<vvencPresetMode>    toPreset                     ( setPresets, this, c, &PresetToEnumMap,vvencPresetMode::VVENC_MEDIUM);
534
0
  IStreamToRefVec<int>              toSourceSize                 ( { &c->m_SourceWidth, &c->m_SourceHeight }, true, 'x' );
535
0
  IStreamToRefVec<int>              toMaxPicSize                 ( { &c->m_maxPicWidth, &c->m_maxPicHeight }, true, 'x' );
536
0
  IStreamToRefVec<int>              toSarSize                    ( { &c->m_sarWidth, &c->m_sarHeight }, true, 'x' );
537
0
  IStreamToRefVec<int>              toFps                        ( { &c->m_FrameRate, &c->m_FrameScale }, false, '/' );
538
539
0
  IStreamToEnum<vvencProfile>       toProfile                    ( &c->m_profile,                     &ProfileToEnumMap      );
540
0
  IStreamToEnum<vvencTier>          toLevelTier                  ( &c->m_levelTier,                   &TierToEnumMap         );
541
0
  IStreamToEnum<vvencLevel>         toLevel                      ( &c->m_level,                       &LevelToEnumMap        );
542
0
  IStreamToEnum<vvencSegmentMode>   toSegment                    ( &c->m_SegmentMode,                 &SegmentToEnumMap      );
543
0
  IStreamToEnum<vvencHDRMode>       toSDRMode                    ( &sdrMode,                          &SdrModeToIntMap       );
544
0
  IStreamToEnum<vvencHDRMode>       toHDRMode                    ( &hdrMode,                          &HdrModeToIntMap       );
545
0
  IStreamToFunc<int>                toColourRangeMode            ( setColourRange, this, c, &RangeToFullRangeFlagMap, 0 );
546
547
0
  IStreamToRefVec<int32_t>          toNumTiles                   ( { &c->m_numTileCols, &c->m_numTileRows }, true, 'x'       );
548
549
0
  IStreamToFunc<BitDepthAndColorSpace>    toInputFormatBitdepth  ( setInputBitDepthAndColorSpace, this, c, &BitColorSpaceToIntMap, YUV420_8 );
550
0
  IStreamToAbbr<int,int>                  toBitrate              ( &c->m_RCTargetBitrate,             &BitrateAbrevToIntMap );
551
0
  IStreamToAbbr<int,int>                  toMaxRate              ( &c->m_RCMaxBitrate,                &BitrateOrScaleAbrevToIntMap );
552
0
  IStreamToEnum<vvencDecodingRefreshType> toDecRefreshType       ( &c->m_DecodingRefreshType,         &DecodingRefreshTypeToEnumMap );
553
554
0
  IStreamToEnum<int>                toAud                        ( &c->m_AccessUnitDelimiter,         &FlagToIntMap<int> );
555
0
  IStreamToEnum<int>                toVui                        ( &c->m_vuiParametersPresent,        &FlagToIntMap<int> );
556
0
  IStreamToEnum<int8_t>             toGOPQPA                     ( &c->m_GOPQPA,                      &FlagToIntMap<int8_t> );
557
0
  IStreamToEnum<int>                toMCTFLevelTilt              ( &c->m_vvencMCTF.MCTFLevelTilt,     &FlagToIntMap<int> );
558
0
  IStreamToEnum<bool>               toQPA                        ( &c->m_usePerceptQPA,               &QPAToIntMap );
559
  
560
561
0
  IStreamToRefVec<double>           toLambdaModifier             ( { &c->m_adLambdaModifier[0], &c->m_adLambdaModifier[1], &c->m_adLambdaModifier[2], &c->m_adLambdaModifier[3], &c->m_adLambdaModifier[4], &c->m_adLambdaModifier[5], &c->m_adLambdaModifier[6] }, false );
562
0
  IStreamToEnum<vvencCostMode>      toCostMode                   ( &c->m_costMode,                    &CostModeToEnumMap     );
563
0
  IStreamToEnum<vvencChromaFormat>  toInputFileChromaFormat      ( &m_inputFileChromaFormat,       &ChromaFormatToEnumMap  );
564
0
  IStreamToEnum<vvencChromaFormat>  toInternChromaFormat         ( &c->m_internChromaFormat,          &ChromaFormatToEnumMap  );
565
0
  IStreamToEnum<vvencHashType>      toHashType                   ( &c->m_decodedPictureHashSEIType,   &HashTypeToEnumMap     );
566
0
  IStreamToArr<int>                 toQpInCb                     ( &c->m_qpInValsCb[0], VVENC_MAX_QP_VALS_CHROMA            );
567
0
  IStreamToArr<int>                 toQpOutCb                    ( &c->m_qpOutValsCb[0], VVENC_MAX_QP_VALS_CHROMA           );
568
0
  IStreamToArr<int>                 toQpInCr                     ( &c->m_qpInValsCr[0], VVENC_MAX_QP_VALS_CHROMA            );
569
0
  IStreamToArr<int>                 toQpOutCr                    ( &c->m_qpOutValsCr[0], VVENC_MAX_QP_VALS_CHROMA           );
570
0
  IStreamToArr<int>                 toQpInCbCr                   ( &c->m_qpInValsCbCr[0], VVENC_MAX_QP_VALS_CHROMA          );
571
0
  IStreamToArr<int>                 toQpOutCbCr                  ( &c->m_qpOutValsCbCr[0], VVENC_MAX_QP_VALS_CHROMA         );
572
0
  IStreamToArr<double>              toIntraLambdaModifier        ( &c->m_adIntraLambdaModifier[0], VVENC_MAX_TLAYER );
573
574
0
  IStreamToArr<unsigned int>        toTileColumnWidth            ( &c->m_tileColumnWidth[0], 10 );
575
0
  IStreamToArr<unsigned int>        toTileRowHeight              ( &c->m_tileRowHeight[0], 10 );
576
577
0
  IStreamToArr<int>                 toMCTFFrames                 ( &c->m_vvencMCTF.MCTFFrames[0], VVENC_MAX_MCTF_FRAMES, &c->m_vvencMCTF.numFrames );
578
0
  IStreamToArr<double>              toMCTFStrengths              ( &c->m_vvencMCTF.MCTFStrengths[0], VVENC_MAX_MCTF_FRAMES, &c->m_vvencMCTF.numStrength );
579
0
  IStreamToEnum<int>                toColourPrimaries            ( &c->m_colourPrimaries,        &ColourPrimariesToIntMap );
580
0
  IStreamToEnum<int>                toTransferCharacteristics    ( &c->m_transferCharacteristics,&TransferCharacteristicsToIntMap );
581
0
  IStreamToEnum<int>                toColourMatrix               ( &c->m_matrixCoefficients,     &ColourMatrixToIntMap );
582
0
  IStreamToEnum<int>                toPrefTransferCharacteristics( &c->m_preferredTransferCharacteristics, &TransferCharacteristicsToIntMap );
583
584
0
  IStreamToArr<unsigned int>        toMasteringDisplay            ( &c->m_masteringDisplay[0], 10  );
585
0
  IStreamToArr<unsigned int>        toContentLightLevel           ( &c->m_contentLightLevel[0], 2 );
586
587
0
  IStreamToArr<char>                toTraceRule                   ( &c->m_traceRule[0], VVENC_MAX_STRING_LEN  );
588
0
  IStreamToArr<char>                toTraceFile                   ( &c->m_traceFile[0], VVENC_MAX_STRING_LEN  );
589
0
  IStreamToArr<char>                toSummaryOutFilename          ( &c->m_summaryOutFilename[0], VVENC_MAX_STRING_LEN  );
590
0
  IStreamToArr<char>                toSummaryPicFilenameBase      ( &c->m_summaryPicFilenameBase[0], VVENC_MAX_STRING_LEN  );
591
592
0
  IStreamToFunc<int>                toSaoWithScc                  ( setSAO, this, c, &SaoToIntMap, 0 );
593
594
0
  IStreamToInt8                     toSliceTypeAdapt              ( &c->m_sliceTypeAdapt );
595
0
  IStreamToInt8                     toSelectiveRDOQ               ( &c->m_useSelectiveRDOQ );
596
0
  IStreamToInt8                     toForceScc                    ( &c->m_forceScc );
597
0
  IStreamToInt8                     toIfpLines                    ( &c->m_ifpLines );
598
0
  IStreamToInt8                     toPOC0IDR                     ( &c->m_poc0idr );
599
0
  IStreamToInt8                     toFga                         ( &c->m_fga );
600
0
  IStreamToInt8                     toMaxDeltaQP                  ( &c->m_maxDeltaQP );
601
0
  IStreamToInt8                     toBIM                         ( &c->m_blockImportanceMapping );
602
0
  IStreamToInt8                     toFastAMVR                    ( &c->m_fastAMVR );
603
0
  IStreamToFixedPointU8             toCuTreeStrength              ( &c->m_cuTreeStrength, 5 );
604
0
  IStreamToInt8                     toCuTreeBlockSize             ( &c->m_cuTreeBlockSize );
605
0
  IStreamToQP                       toQP                          ( &c->m_QP, &c->m_QPFractionVal );
606
0
  IStreamToInt8                     toLumaLevelToDeltaQP          ( &c->m_lumaLevelToDeltaQPEnabled );
607
608
0
  IStreamToEnum<int8_t>             toUseWpp                      ( &c->m_entropyCodingSyncEnabled,    &FlagToIntMap<int8_t> );
609
0
  IStreamToEnum<int8_t>             toUseIfp                      ( &c->m_ifp,                         &FlagToIntMap<int8_t> );
610
0
  IStreamToEnum<int8_t>             toChromaLocInfo               ( &c->m_chromaLocInfoPresent,        &FlagToIntMap<int8_t> );
611
0
  IStreamToEnum<int8_t>             toMtProfile                   ( &c->m_mtProfile,                   &MtAbrevToIntMap );
612
0
  IStreamToInt8                     toNumParallelGOPs             ( &c->m_numParallelGOPs );
613
0
  IStreamToFixedPointU8             toFgaStrength                 ( &c->m_fgaStrengthVal, 6 );
614
0
  IStreamToFixedPointU8             toSbbSkipThr                  ( &c->m_sbbSkipThrVal, 6 );
615
616
0
  po::Options opts;
617
0
  if( m_easyMode )
618
0
  {
619
0
    opts.setLowerCaseOnly(); // easy app uses lower case option names only
620
0
  }
621
622
0
  opts.setSubSection("General Options");
623
0
  opts.addOptions()
624
0
  ("help,h",                                          do_help,                                             "show default help")
625
0
  ("fullhelp",                                        do_full_help,                                        "show full help")
626
0
  ("Verbosity,v",                                     toMsgLevel,                                          "verbosity level (0: silent, 1: error, 2: warning, 3: info, 4: notice, 5: verbose, 6: debug)")
627
0
  ("stats",                                           m_printStats,                                        "enable or disable printing of statistics (fps, bitrate, estimation of encoding time)")
628
0
  ("version",                                         m_showVersion,                                       "show version ")
629
0
  ;
630
631
0
  opts.setSubSection("Input Options");
632
0
  if( m_easyMode)
633
0
  {
634
0
    opts.addOptions()
635
0
    ("input,i",                                         m_inputFileName,                                     "original YUV input file name or '-' for reading from stdin")
636
0
    ("size,s",                                          toSourceSize,                                        "specify input resolution (WidthxHeight)")
637
0
    ("format,c",                                        toInputFormatBitdepth,                               "set input format (yuv420, yuv420_10, yuv420_10_packed, yuv400 (gray), yuv400_10 (gray10)")
638
0
    ("framerate,r",                                     c->m_FrameRate,                                      "temporal rate (framerate numerator) e.g. 25,30, 30000, 50,60, 60000 ")
639
0
    ("framescale",                                      c->m_FrameScale,                                     "temporal scale (framerate denominator) e.g. 1, 1001 ")
640
0
    ("fps",                                             toFps,                                               "framerate as int or fraction (num/denom) ")
641
642
0
    ("tickspersec",                                     c->m_TicksPerSecond,                                 "ticks per second for dts generation, (1..27000000, -1: ticks per frame=1)")
643
0
    ("frames,f",                                        c->m_framesToBeEncoded,                              "max. frames to encode [all]")
644
0
    ;
645
0
  }
646
0
  else
647
0
  {
648
0
    opts.addOptions()
649
0
    ("InputFile,i",                                     m_inputFileName,                                     "Original YUV input file name or '-' for reading from stdin")
650
0
    ("Size,s",                                          toSourceSize,                                        "Input resolution (WidthxHeight)")
651
0
    ("InputBitDepth",                                   c->m_inputBitDepth[ 0 ],                             "Bit-depth of input file")
652
0
    ("FramesToBeEncoded,f",                             c->m_framesToBeEncoded,                              "Number of frames to be encoded (default=all)")
653
0
    ("FrameRate,-fr",                                   c->m_FrameRate,                                      "Temporal rate (framerate numerator) e.g. 25,30, 30000, 50,60, 60000")
654
0
    ("FrameScale",                                      c->m_FrameScale,                                     "Temporal scale (framerate denominator) e.g. 1, 1001")
655
0
    ("fps",                                             toFps,                                               "Framerate as int or fraction (num/denom) ")
656
0
    ("TicksPerSecond",                                  c->m_TicksPerSecond,                                 "Ticks Per Second for dts generation, (1..27000000, -1: ticks per frame=1)")
657
0
    ("LeadFrames",                                      c->m_leadFrames,                                     "Number of leading frames to be read before starting the encoding, use when splitting the video into overlapping segments")
658
0
    ("TrailFrames",                                     c->m_trailFrames,                                    "Number of trailing frames to be read after frames to be encoded, use when splitting the video into overlapping segments")
659
0
    ;
660
0
  }
661
662
0
  opts.addOptions()
663
0
  ("FrameSkip,-fs",                                     m_FrameSkip,                                         "number of frames to skip at start of input YUV [off]")
664
0
  ;
665
666
0
  if( m_easyMode )
667
0
  {
668
0
    opts.setSubSection("Output Options");
669
0
    opts.addOptions()
670
0
    ("output,o",                                        m_bitstreamFileName,                                 "bitstream output file name")
671
0
    ;
672
0
  }
673
0
  else
674
0
  {
675
0
    opts.setSubSection("Output options");
676
0
    opts.addOptions()
677
0
    ("BitstreamFile,b",                                 m_bitstreamFileName,                                 "Bitstream output file name")
678
0
    ("ReconFile,o",                                     m_reconFileName,                                     "Reconstructed YUV output file name")
679
0
    ("OutputBitDepth",                                  c->m_outputBitDepth[ 0 ],                            "Bit-depth of output file")
680
0
    ;
681
0
  }
682
683
0
  if( m_easyMode )
684
0
  {
685
0
    opts.setSubSection("Encoder Options");
686
0
    opts.addOptions()
687
0
    ("preset",                                          toPreset,                                            "preset for detailed parameter configuration (faster, fast, medium, slow, slower, medium_lowDecEnergy)")
688
0
    ("bitrate,b",                                       toBitrate,                                           "bitrate for rate control (0: constant-QP encoding without rate control; otherwise\n"
689
0
                                                                                                             "bits/second; use e.g. 1.5M, 1.5Mbps, 1500k, 1500kbps, 1500000bps, 1500000)")
690
0
    ("maxrate,m",                                       toMaxRate,                                           "approximate maximum instantaneous bitrate for constrained VBR in rate control (0:\n"
691
0
                                                                                                             "no rate cap; use e.g. 3.5M, 3.5Mbps, 3500k, 3500kbps, 3500000bps, 3500000), use suffix 'x' "
692
0
                                                                                                             "to specify as a multiple of target bitrate")
693
0
    ("passes,p",                                        c->m_RCNumPasses,                                    "number of encoding passes with rate control (1: single-pass, -1, 2: two-pass RC)")
694
0
    ("pass",                                            c->m_RCPass,                                         "rate control pass for two-pass rate control (-1: both, 1: first, 2: second pass)")
695
0
    ("rcstatsfile",                                     m_RCStatsFileName,                                   "rate control statistics file name")
696
0
    ("qp,q",                                            toQP,                                                "quantization parameter, QP (0, 1, .. 63), a fractional QP such as 27.5 encodes between QPs 27 and 28")
697
0
    ("qpa",                                             toQPA,                                               "enable perceptually motivated QP adaptation based on XPSNR model (0: off, 1: on)", true)
698
0
    ("threads,t",                                       c->m_numThreads,                                     "number of threads (multithreading; -1: resolution < 720p: 4, < 5K 2880p: 8, >= 5K 2880p: 12 threads)")
699
0
    ("mtprofile",                                       toMtProfile,                                         "set automatic multi-threading setting (-1: auto, 0: off, 1,2,3: on, enables tiles, IFP and WPP automatically depending on the number of threads)")
700
0
    ("refreshtype,-rt",                                 toDecRefreshType,                                    "intra refresh type (none, cra, idr, rpsei: Recovery Point SEI, cra_cre: CRA, constrained RASL picture encoding, idr_no_radl: IDR w/o leading pictures, use for DASH, implies POC0IDR)")
701
0
    ("refreshsec,-rs",                                  c->m_IntraPeriodSec,                                 "intra period/refresh in seconds")
702
0
    ("intraperiod,-ip",                                 c->m_IntraPeriod,                                    "intra period in frames (0: specify intra period in seconds instead, see -refreshsec)")
703
0
    ;
704
0
  }
705
0
  else
706
0
  {
707
0
    opts.setSubSection("Threading, performance");
708
0
    opts.addOptions()
709
0
    ("Threads,t",                                       c->m_numThreads,                                     "number of threads (multithreading; -1: resolution < 720p: 4, < 5K 2880p: 8, >= 5K 2880p: 12 threads)")
710
0
    ("MTProfile",                                       toMtProfile,                                         "set automatic multi-threading setting (-1: auto, 0: off, 1,2,3: on, enables tiles, IFP and WPP automatically depending on the number of threads)")
711
0
    ("preset",                                          toPreset,                                            "select preset for specific encoding setting (faster, fast, medium, slow, slower, medium_lowDecEnergy)")
712
0
    ("Tiles",                                           toNumTiles,                                          "Set number of tile columns and rows")
713
0
    ;
714
715
0
    opts.setSubSection("Slice decision options");
716
0
    opts.addOptions()
717
0
    ("IntraPeriod,-ip",                                c->m_IntraPeriod,                                     "Intra period in frames (0: use intra period in seconds (refreshsec), else: n*gopsize)")
718
0
    ("RefreshSec,-rs",                                 c->m_IntraPeriodSec,                                  "Intra period/refresh in seconds")
719
0
    ("DecodingRefreshType,-dr",                        toDecRefreshType,                                     "intra refresh type (none, cra, idr, rpsei: Recovery Point SEI, cra_cre: CRA, constrained RASL picture encoding, idr_no_radl: IDR w/o leading pictures, use for DASH, implies POC0IDR)")
720
0
    ("GOPSize,g",                                      c->m_GOPSize,                                         "GOP size of temporal structure (16,32)")
721
0
    ("PicReordering",                                  c->m_picReordering,                                   "Allow reordering of pictures (0:off, 1:on), should be disabled for low delay requirements")
722
0
    ("POC0IDR",                                        toPOC0IDR,                                            "encoding with first IRAP at POC 0 (0: off, 1: on, -1: default automatic setting (on for idr_no_radl, disabled picture reorderding and non-first segments; off otherwise))" )
723
0
    ;
724
725
0
    opts.setSubSection("Rate control, Perceptual Quantization");
726
0
    opts.addOptions()
727
0
    ("NumPasses",                                       c->m_RCNumPasses,                                    "number of rate control passes (1,2)" )
728
0
    ("Passes",                                          c->m_RCNumPasses,                                    "number of rate control passes (1,2)" )
729
0
    ("Pass",                                            c->m_RCPass,                                         "rate control pass for two-pass rate control (-1,1,2)" )
730
0
    ("LookAhead",                                       c->m_LookAhead,                                      "Enable pre-analysis pass with picture look-ahead (-1,0,1)")
731
0
    ("RCStatsFile",                                     m_RCStatsFileName,                                   "rate control statistics file" )
732
0
    ("TargetBitrate",                                   toBitrate,                                           "Rate control: target bitrate [bits/second], use e.g. 1.5M, 1.5Mbps, 1500k, 1500kbps, 1500000bps, 1500000" )
733
0
    ("MaxBitrate",                                      toMaxRate,                                           "Rate control: approximate maximum instantaneous bitrate [bits/second] (0: no rate cap; least constraint)" )
734
0
    ("PerceptQPA,-qpa",                                 c->m_usePerceptQPA,                                  "Enable perceptually motivated QP adaptation, XPSNR based (0:off, 1:on)", true)
735
0
    ("MaxDeltaQP",                                      toMaxDeltaQP,                                        "QPA: set lambda - limit delta QP (-2: set depending on base QP, -1: max QP, 0 .. max QP)")
736
0
    ("STA",                                             toSliceTypeAdapt,                                    "Enable slice type adaptation at GOPSize>8 (-1: auto, 0: off, 1: adapt slice type, 2: adapt NAL unit type)")
737
0
    ("MinIntraDistance",                                c->m_minIntraDist,                                   "With STA: set a minimum coded frame distance to the previous intra frame (-1: GOPSize)" )
738
0
    ;
739
740
0
    opts.setSubSection("Quantization parameters");
741
0
    opts.addOptions()
742
0
    ("QP,q",                                            toQP,                                                "Qp value (0-63), a fractional QP such as 27.5 encodes between QPs 27 and 28")
743
0
    ;
744
0
  }
745
746
0
  opts.setSubSection("Profile, Level, Tier");
747
0
  opts.addOptions()
748
0
  ("Profile",                                           toProfile,                                           "profile (auto, main_10, main_10_still_picture)")
749
0
  ("Level",                                             toLevel,                                             "level limit (auto, 1.0, 2.0,2.1, 3.0,3.1, 4.0,4.1, 5.0,5.1,5.2, 6.0,6.1,6.2,6.3, 15.5)")
750
0
  ("Tier",                                              toLevelTier,                                         "tier for interpretation of level (main, high)")
751
0
  ;
752
753
0
  opts.setSubSection("HDR/SDR and Color Options");
754
0
  if( m_easyMode )
755
0
  {
756
0
    opts.addOptions()
757
0
    ("sdr",                                             toSDRMode,                                           "set SDR mode + BT.709, BT.2020, BT.470 color space. "
758
0
                                                                                                             "use: off, sdr|sdr_709, sdr_2020, sdr_470bg")
759
0
    ("hdr",                                             toHDRMode,                                           "set HDR mode + BT.709 or BT.2020 color space (+ SEI messages for hlg) "
760
0
                                                                                                             "use: off, pq|hdr10, pq_2020|hdr10_2020, hlg, hlg_2020")
761
0
    ("range",                                           toColourRangeMode,                                   "set colour range: unknown, limited | mpeg | tv, full | jpeg | pc")
762
0
    ;
763
0
  }
764
0
  else
765
0
  {
766
0
    opts.addOptions()
767
0
    ("Sdr",                                             toSDRMode,                                           "set SDR mode + BT.709, BT.2020, BT.470 color space. "
768
0
                                                                                                             "use: off, sdr|sdr_709, sdr_2020, sdr_470bg")
769
0
    ("Hdr",                                             toHDRMode,                                           "set HDR mode + BT.709 or BT.2020 color space (+SEI messages for hlg) "
770
0
                                                                                                             "If maxcll or masteringdisplay is set, HDR10/PQ is enabled. use: off, pq|hdr10, pq_2020|hdr10_2020, hlg, hlg_2020")
771
0
    ;
772
773
0
    opts.setSubSection("SEI and auxiliary options");
774
0
    opts.setSubSection("VUI options");
775
0
  }
776
777
778
0
  std::ostringstream easyOpts;
779
0
  po::doHelp( easyOpts, opts );
780
  // ---------------------------------------------------
781
782
0
  if( m_easyMode )
783
0
  {
784
0
    opts.setSubSection("Encoder Options");
785
0
    opts.addOptions()
786
0
    ("internal-bitdepth",                               c->m_internalBitDepth[0],                           "internal bitdepth (8, 10)")
787
0
    ("ifp",                                             toUseIfp,                                           "inter-frame parallelization(IFP) (-1: auto, 0: off, 1: on, with sync. offset of two CTU lines)")
788
0
    ("tiles",                                           toNumTiles,                                         "number of tile columns and rows")
789
0
    ("accessunitdelimiter,-aud",                        toAud,                                              "emit Access Unit Delimiter NALUs (-1: auto, 0: off, 1: on; default: auto - only if needed by dependent options)", true)
790
0
    ("vuiparameterspresent,-vui",                       toVui,                                              "emit VUI information (-1: auto, 0: off, 1: on; default: auto - only if needed by dependent options)", true)
791
0
    ("hrdparameterspresent,-hrd",                       c->m_hrdParametersPresent,                          "emit VUI HRD information (0: off, 1: on)")
792
0
    ("decodedpicturehash,-dph",                         toHashType,                                         "control generation of decode picture hash SEI messages, (0: off, 1: md5, 2: crc, 3: checksum)")
793
0
    ;
794
0
  }
795
796
  // ---------------------------------------------------
797
798
0
  opts.setSubSection("General Options");
799
0
  opts.addOptions()
800
0
  ("additional",                                        m_additionalSettings,                               "additional options as string (e.g: \"bitrate=1000000 passes=1\")")
801
0
  ;
802
803
0
  opts.setSubSection("Input Options");
804
0
  opts.addOptions()
805
0
  ("segment",                                           toSegment,                                         "when encoding multiple separate segments, specify segment position to enable segment concatenation (first, mid, last) [off]\n"
806
0
                                                                                                           " first: first segment           \n"
807
0
                                                                                                           " mid  : all segments between first and last segment\n"
808
0
                                                                                                           " last : last segment")
809
0
  ("y4m",                                               m_forceY4mInput,                                   "force y4m input (only needed for input pipe, else enabled by .y4m file extension)")
810
0
  ("logofile",                                          m_logoFileName,                                    "set logo overlay filename (json)")
811
0
  ;
812
813
0
  if( !m_easyMode )
814
0
  {
815
0
    opts.setSubSection("General Options");
816
0
    opts.addOptions()
817
0
    ("c",                                               po::parseConfigFile,                                "configuration file name")
818
0
    ("WriteConfig",                                     writeCfg,                                           "write the encoder config into configuration file")
819
0
    ("WarnUnknowParameter,w",                           warnUnknowParameter,                                "warn for unknown configuration parameters instead of failing")
820
0
#if defined( __x86_64__ ) || defined( _M_X64 ) || defined( __i386__ ) || defined( __i386 ) || defined( _M_IX86 )
821
0
    ("SIMD",                                            ignoreParams,                                       "SIMD extension to use (SCALAR, SSE41, SSE42, AVX, AVX2, AVX512), default: the highest supported extension")
822
#elif defined( __aarch64__ ) || defined( _M_ARM64 ) || defined( __arm__ ) || defined( _M_ARM )
823
    ("SIMD",                                            ignoreParams,                                       "SIMD extension to use (SCALAR, NEON), default: the highest supported extension")
824
#elif defined( __wasm__ ) || defined( __wasm32__ )
825
    ("SIMD",                                            ignoreParams,                                       "SIMD extension to use (SCALAR, WASM), default: the highest supported extension")
826
#elif defined( __loongarch__ )
827
    ("SIMD",                                            ignoreParams,                                       "SIMD extension to use (SCALAR, LSX), default: the highest supported extension")
828
#else
829
    ("SIMD",                                            ignoreParams,                                       "SIMD extension to use (SCALAR, SIMDE), default: the highest supported extension")
830
#  endif
831
0
    ;
832
833
0
    opts.setSubSection("Input Options");
834
0
    opts.addOptions()
835
0
    ("SourceWidth",                                     c->m_SourceWidth,                                    "Source picture width")
836
0
    ("SourceHeight",                                    c->m_SourceHeight,                                   "Source picture height")
837
0
    ("ConformanceWindowMode",                           c->m_conformanceWindowMode,                          "Window conformance mode (0:off, 1:automatic padding, 2:padding, 3:conformance")
838
0
    ("ConfWinLeft",                                     c->m_confWinLeft,                                    "Left offset for window conformance mode 3")
839
0
    ("ConfWinRight",                                    c->m_confWinRight,                                   "Right offset for window conformance mode 3")
840
0
    ("ConfWinTop",                                      c->m_confWinTop,                                     "Top offset for window conformance mode 3")
841
0
    ("ConfWinBottom",                                   c->m_confWinBottom,                                  "Bottom offset for window conformance mode 3")
842
0
    ("HorizontalPadding",                               c->m_aiPad[0],                                       "Horizontal source padding for conformance window mode 2")
843
0
    ("VerticalPadding",                                 c->m_aiPad[1],                                       "Vertical source padding for conformance window mode 2")
844
0
    ("InputChromaFormat",                               toInputFileChromaFormat,                             "input file chroma format (400, 420, 422, 444)")
845
0
    ("PackedInput",                                     m_packedYUVInput,                                    "Enable 10-bit packed YUV input data ( pack 4 samples( 8-byte) into 5-bytes consecutively.")
846
847
0
    ("MaxPicSize",                                      toMaxPicSize,                                        "Maximum resolution (maxWidth x maxHeight)")
848
0
    ("MaxPicWidth",                                     c->m_maxPicWidth,                                    "Maximum picture width")
849
0
    ("MaxPicHeight",                                    c->m_maxPicHeight,                                   "Maximum picture height")
850
0
    ;
851
852
0
    opts.setSubSection("Profile, Level, Tier");
853
0
    opts.addOptions()
854
0
    ("SubProfile",                                      c->m_subProfile,                                     "Sub-profile idc")
855
0
    ("MaxBitDepthConstraint",                           c->m_bitDepthConstraintValue,                        "Bit depth to use for profile-constraint for RExt profiles. (0: automatically choose based upon other parameters)")
856
0
    ("IntraConstraintFlag",                             c->m_intraOnlyConstraintFlag,                        "Value of general_intra_constraint_flag to use for RExt profiles (not used if an explicit RExt sub-profile is specified)")
857
0
    ;
858
0
    ;
859
860
0
    opts.setSubSection("Quality reporting metrics");
861
0
    opts.addOptions()
862
0
    ("MSEBasedSequencePSNR",                            c->m_printMSEBasedSequencePSNR,                      "Emit sequence PSNR (0: only as a linear average of the frame PSNRs, 1: also based on an average of the frame MSEs")
863
0
    ("PrintHexPSNR",                                    c->m_printHexPsnr,                                   "Emit hexadecimal PSNR for each frame (0: off , 1:on")
864
0
    ("PrintFrameMSE",                                   c->m_printFrameMSE,                                  "Emit MSE values for each frame (0: off , 1:on")
865
0
    ("PrintSequenceMSE",                                c->m_printSequenceMSE,                               "Emit MSE values for the whole sequence (0: off , 1:on)")
866
0
    ;
867
868
0
    opts.setSubSection("Bitstream options");
869
0
    opts.addOptions()
870
0
    ("CabacZeroWordPaddingEnabled",                     c->m_cabacZeroWordPaddingEnabled,                    "Add conforming cabac-zero-words to bit streams (0: do not add, 1: add as required)")
871
0
    ;
872
873
0
    opts.setSubSection("Rate control, Perceptual Quantization");
874
0
    opts.addOptions()
875
0
    ("RCInitialQP",                                     c->m_RCInitialQP,                                    "Rate control: initial QP. With two-pass encoding, this specifies the first-pass base QP (instead of using a default QP). Activated if value is greater than zero" )
876
0
    ("PerceptQPATempFiltIPic",                          c->m_usePerceptQPATempFiltISlice,                    "Temporal high-pass filter in QPA activity calculation for key pictures (0:off, 1:on, 2:on incl. temporal pumping reduction, 3:mode 1 without force 2nd order filter in key frames, 4:mode 2 without force 2nd order filter in key frames, -1:auto, -2:auto without force 2nd order filter in key frames)")
877
0
    ;
878
879
    // Coding structure parameters
880
0
    opts.setSubSection("Coding structure parameters");
881
0
    opts.addOptions()
882
0
    ("ReWriteParamSets",                                c->m_rewriteParamSets,                               "Enable rewriting of Parameter sets before every (intra) random access point")
883
0
    ("IDRRefParamList",                                 c->m_idrRefParamList,                                "Enable indication of reference picture list syntax elements in slice headers of IDR pictures")
884
0
    ;
885
886
    /* Quantization parameters */
887
0
    opts.setSubSection("Quantization parameters");
888
0
    opts.addOptions()
889
0
    ("SameCQPTablesForAllChroma",                       c->m_useSameChromaQPTables,                          "0: Different tables for Cb, Cr and joint Cb-Cr components, 1 (default): Same tables for all three chroma components")
890
0
    ("IntraQPOffset",                                   c->m_intraQPOffset,                                  "Qp offset value for intra slice, typically determined based on GOP size")
891
0
    ("LambdaFromQpEnable",                              c->m_lambdaFromQPEnable,                             "Enable flag for derivation of lambda from QP")
892
0
    ("LambdaModifier",                                  toLambdaModifier,                                    "Lambda modifier list for temporal layers. If LambdaModifierI is used, this will not affect intra pictures")
893
0
    ("LambdaModifierI",                                 toIntraLambdaModifier,                               "Lambda modifiers for Intra pictures, comma separated, up to one the number of temporal layer. If entry for temporalLayer exists, then use it, else if some are specified, use the last, else use the standard LambdaModifiers.")
894
0
    ("IQPFactor",                                       c->m_dIntraQpFactor,                                 "Intra QP Factor for Lambda Computation. If negative, the default will scale lambda based on GOP size (unless LambdaFromQpEnable then IntraQPOffset is used instead)")
895
0
    ("QpInValCb",                                       toQpInCb,                                            "Input coordinates for the QP table for Cb component")
896
0
    ("QpInValCr",                                       toQpInCr,                                            "Input coordinates for the QP table for Cr component")
897
0
    ("QpInValCbCr",                                     toQpInCbCr,                                          "Input coordinates for the QP table for joint Cb-Cr component")
898
0
    ("QpOutValCb",                                      toQpOutCb,                                           "Output coordinates for the QP table for Cb component")
899
0
    ("QpOutValCr",                                      toQpOutCr,                                           "Output coordinates for the QP table for Cr component")
900
0
    ("QpOutValCbCr",                                    toQpOutCbCr,                                         "Output coordinates for the QP table for joint Cb-Cr component")
901
0
    ("MaxCuDQPSubdiv",                                  c->m_cuQpDeltaSubdiv,                                "Maximum subdiv for CU luma Qp adjustment")
902
0
    ("MaxCuChromaQpOffsetSubdiv",                       c->m_cuChromaQpOffsetSubdiv,                         "Maximum subdiv for CU chroma Qp adjustment - set less than 0 to disable")
903
0
    ("CbQpOffset",                                      c->m_chromaCbQpOffset,                               "Chroma Cb QP Offset")
904
0
    ("CrQpOffset",                                      c->m_chromaCrQpOffset,                               "Chroma Cr QP Offset")
905
0
    ("CbQpOffsetDualTree",                              c->m_chromaCbQpOffsetDualTree,                       "Chroma Cb QP Offset for dual tree")
906
0
    ("CrQpOffsetDualTree",                              c->m_chromaCrQpOffsetDualTree,                       "Chroma Cr QP Offset for dual tree")
907
0
    ("CbCrQpOffset",                                    c->m_chromaCbCrQpOffset,                             "QP Offset for joint Cb-Cr mode")
908
0
    ("CbCrQpOffsetDualTree",                            c->m_chromaCbCrQpOffsetDualTree,                     "QP Offset for joint Cb-Cr mode in dual tree")
909
0
    ("SliceChromaQPOffsetPeriodicity",                  c->m_sliceChromaQpOffsetPeriodicity,                 "Used in conjunction with Slice Cb/Cr QpOffsetIntraOrPeriodic. Use 0 (default) to disable periodic nature.")
910
0
    ("SliceCbQpOffsetIntraOrPeriodic",                  c->m_sliceChromaQpOffsetIntraOrPeriodic[0],          "Chroma Cb QP Offset at slice level for I slice or for periodic inter slices as defined by SliceChromaQPOffsetPeriodicity. Replaces offset in the GOP table.")
911
0
    ("SliceCrQpOffsetIntraOrPeriodic",                  c->m_sliceChromaQpOffsetIntraOrPeriodic[1],          "Chroma Cr QP Offset at slice level for I slice or for periodic inter slices as defined by SliceChromaQPOffsetPeriodicity. Replaces offset in the GOP table.")
912
913
0
    ("LumaLevelToDeltaQPMode",                          toLumaLevelToDeltaQP,                                "Luma based Delta QP 0(default): not used. 1: Based on CTU average. -1: auto - enable for HDR PQ")
914
0
    ("GOPQPA",                                          toGOPQPA,                                            "Enable GOP QP-cascade (0: off, 1: on, -1: auto - enable when QPA is disabled); acts only with MCTF on, whose analysis gives the noise levels it reads")
915
0
    ; 
916
917
0
    opts.setSubSection("Misc. options");
918
0
    opts.addOptions()
919
0
    ("ChromaFormatIDC,-cf",                             toInternChromaFormat,                                "intern chroma format (400, 420, 422, 444) or set to 0 (default), same as InputChromaFormat")
920
0
    ("UseIdentityTableForNon420Chroma",                 c->m_useIdentityTableForNon420Chroma,                "True: Indicates that 422/444 chroma uses identity chroma QP mapping tables; False: explicit Qp table may be specified in config")
921
0
    ("InputBitDepthC",                                  c->m_inputBitDepth[ 1 ],                             "As per InputBitDepth but for chroma component. (default:InputBitDepth)")
922
0
    ("InternalBitDepth",                                c->m_internalBitDepth[ 0 ],                          "Bit-depth the codec operates at. (default: MSBExtendedBitDepth). If different to MSBExtendedBitDepth, source data will be converted")
923
0
    ("OutputBitDepthC",                                 c->m_outputBitDepth[ 1 ],                            "As per OutputBitDepth but for chroma component. (default: use luma output bit-depth)")
924
0
    ("MSBExtendedBitDepth",                             c->m_MSBExtendedBitDepth[ 0 ],                       "bit depth of luma component after addition of MSBs of value 0 (used for synthesising High Dynamic Range source material). (default:InputBitDepth)")
925
0
    ("MSBExtendedBitDepthC",                            c->m_MSBExtendedBitDepth[ 1 ],                       "As per MSBExtendedBitDepth but for chroma component. (default:MSBExtendedBitDepth)")
926
927
0
    ("WaveFrontSynchro",                                toUseWpp,                                            "Enable entropy coding sync (WPP) (-1: auto, 0: off, 1: on)")
928
0
    ("EntryPointsPresent",                              c->m_entryPointsPresent,                             "Enable entry points in slice header")
929
930
0
    ("TreatAsSubPic",                                   c->m_treatAsSubPic,                                  "Allow generation of subpicture streams, AlfTempPred and JCCR")
931
0
    ("ExplicitAPSid",                                   c->m_explicitAPSid,                                  "Set ALF APS id")
932
    
933
0
    ("AddGOP32refPics",                                 c->m_addGOP32refPics,                                "Use different QP offsets and reference pictures in GOP structure")
934
0
    ("NumRefPics",                                      c->m_numRefPics,                                     "Number of reference pictures in RPL (0: default for RPL, <10: apply for all temporal layers, >=10: each decimal digit specifies the number for a temporal layer, last digit applying to the highest TL)" )
935
0
    ("NumRefPicsSCC",                                   c->m_numRefPicsSCC,                                  "Number of reference pictures in RPL for SCC pictures (semantic analogue to NumRefPics, -1: equal to NumRefPics)" )
936
0
    ("ForceSCC",                                        toForceScc,                                          "Force SCC treatment, instead of detection (<=0: use detection, 1: treat all frames as not SCC, 2: treat all frames as weak SCC, 3: treat all frames as strong SCC)" )
937
0
    ;
938
939
0
    opts.setSubSection("Low-level QT-BTT partitioning options");
940
0
    opts.addOptions()
941
0
    ("CTUSize",                                         c->m_CTUSize,                                        "CTU size")
942
0
    ("MinQTISlice",                                     c->m_MinQT[0],                                       "Min QT size for (luma in) I slices")
943
0
    ("MinQTLumaISlice",                                 c->m_MinQT[0],                                       "Min QT size for (luma in) I slices")
944
0
    ("MinQTNonISlice",                                  c->m_MinQT[1],                                       "Min QT size for P/B slices")
945
0
    ("MinQTChromaISliceInChromaSamples",                c->m_MinQT[2],                                       "Min QT size for chroma in I slices (in chroma samples, i.e. inclusive subsampling)")
946
0
    ("MaxMTTDepth",                                     c->m_maxMTTDepth,                                    "Max MTT depth for P/B slices (<10: apply for all temporal layers, >=10: each decimal digit specifies the depth for a temporal layer, last digit applying to the highest TL)")
947
0
    ("MaxMTTDepthI",                                    c->m_maxMTTDepthI,                                   "Max MTT depth for (luma in) I slices")
948
0
    ("MaxMTTDepthISliceL",                              c->m_maxMTTDepthI,                                   "Max MTT depth for (luma in) I slices")
949
0
    ("MaxMTTDepthISliceC",                              c->m_maxMTTDepthIChroma,                             "Max MTT depth for chroma in I slices")
950
0
    ("MaxBTLumaISlice",                                 c->m_maxBT[0],                                       "Max BT size for (luma in) I slices")
951
0
    ("MaxBTChromaISlice",                               c->m_maxBT[2],                                       "Max BT size for chroma in I slices")
952
0
    ("MaxBTNonISlice",                                  c->m_maxBT[1],                                       "Max BT size for P/B slices")
953
0
    ("MaxTTLumaISlice",                                 c->m_maxTT[0],                                       "Max TT size for (luma in) I slices")
954
0
    ("MaxTTChromaISlice",                               c->m_maxTT[2],                                       "Max TT size for chroma in I slices")
955
0
    ("MaxTTNonISlice",                                  c->m_maxTT[1],                                       "Max TT size for P/B slices")
956
0
    ("DualITree",                                       c->m_dualITree,                                      "Use separate luma and chroma QTBTT trees for intra slice (if off, luma constraint apply to all channels)")
957
0
    ("Log2MaxTbSize",                                   c->m_log2MaxTbSize,                                  "Maximum transform block size in logarithm base 2")
958
0
    ("Log2MinCodingBlockSize",                          c->m_log2MinCodingBlockSize,                         "Minimum coding block size in logarithm base 2")
959
0
    ;
960
961
0
    opts.setSubSection("Coding tools");
962
0
    opts.addOptions()
963
0
    ("CostMode",                                        toCostMode,                                          "Use alternative cost functions: choose between 'lossy', 'sequence_level_lossless', 'lossless' (which forces QP to " MACRO_TO_STRING(LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP) ") and 'mixed_lossless_lossy' (which used QP'=" MACRO_TO_STRING(LOSSLESS_AND_MIXED_LOSSLESS_RD_COST_TEST_QP_PRIME) " for pre-estimates of transquant-bypass blocks).")
964
0
    ("ASR",                                             c->m_bUseASR,                                        "Adaptive motion search range")
965
0
    ("HadamardME",                                      c->m_bUseHADME,                                      "Hadamard ME for fractional-pel")
966
0
    ("FastHAD",                                         c->m_fastHad,                                        "Use fast sub-sampled hadamard for square blocks >=32x32")
967
0
    ("RDOQ",                                            c->m_RDOQ,                                           "Rate-Distortion Optimized Quantization mode")
968
0
    ("RDOQTS",                                          c->m_useRDOQTS,                                      "Rate-Distortion Optimized Quantization mode for TransformSkip")
969
0
    ("SelectiveRDOQ",                                   toSelectiveRDOQ,                                     "Enable selective RDOQ (0: never, 1: always, 2: for natural content)")
970
971
0
    ("JointCbCr",                                       c->m_JointCbCrMode,                                  "Enable joint coding of chroma residuals (0:off, 1:on)")
972
0
    ("CabacInitPresent",                                c->m_cabacInitPresent,                               "Enable cabac table index selection based on previous frame")
973
0
    ("LCTUFast",                                        c->m_useFastLCTU,                                    "Fast methods for large CTU")
974
0
    ("PBIntraFast",                                     c->m_usePbIntraFast,                                 "Intra mode pre-check dependent on best Inter mode, skip intra if it is not probable (0:off ... 2:fastest)")
975
0
    ("FastMrg",                                         c->m_useFastMrg,                                     "Fast methods for inter merge")
976
0
    ("AMaxBT",                                          c->m_useAMaxBT,                                      "Adaptive maximal BT-size")
977
0
    ("FastQtBtEnc",                                     c->m_fastQtBtEnc,                                    "Fast encoding setting for QTBT")
978
0
    ("ContentBasedFastQtbt",                            c->m_contentBasedFastQtbt,                           "Signal based QTBT speed-up")
979
0
    ("FEN",                                             c->m_fastInterSearchMode,                            "fast encoder setting")
980
0
    ("ECU",                                             c->m_useEarlyCU,                                     "Early CU setting (1: ECU limited to specific block size and TL, 2: unconstrained ECU)")
981
0
    ("FDM",                                             c->m_useFastDecisionForMerge,                        "Fast decision for Merge RD Cost")
982
983
0
    ("DisableIntraInInter",                             c->m_bDisableIntraCUsInInterSlices,                  "Flag to disable intra CUs in inter slices")
984
0
    ("FastUDIUseMPMEnabled",                            c->m_bFastUDIUseMPMEnabled,                          "If enabled, adapt intra direction search, accounting for MPM")
985
0
    ("FastMEForGenBLowDelayEnabled",                    c->m_bFastMEForGenBLowDelayEnabled,                  "If enabled use a fast ME for generalised B Low Delay slices")
986
987
0
    ("MTSImplicit",                                     c->m_MTSImplicit,                                    "Enable implicit MTS when explicit MTS is off\n")
988
0
    ("TMVPMode",                                        c->m_TMVPModeId,                                     "TMVP mode enable(0: off 1: for all slices 2: for certain slices only)")
989
0
    ("DepQuant",                                        c->m_DepQuantEnabled,                                "Enable dependent quantization" )
990
0
    ("QuantThrVal",                                     c->m_quantThresholdVal,                              "Quantization threshold value for DQ last coefficient search" )
991
0
    ("SbbSkipThr",                                      toSbbSkipThr,                                        "RDOQ2 and DQ: sub-blocks whose coefficients all lie below this many half quantization steps are decided all zero [0...4.0), 1.0: in RDOQ2 the levels that round to 0, 0: off" )
992
0
    ("SignHideFlag",                                    c->m_SignDataHidingEnabled,                          "Enable sign data hiding" )
993
0
    ("MIP",                                             c->m_MIP,                                            "Enable MIP (matrix-based intra prediction)")
994
0
    ("FastMIP",                                         c->m_useFastMIP,                                     "Fast encoder search for MIP (matrix-based intra prediction)")
995
0
    ("MaxNumMergeCand",                                 c->m_maxNumMergeCand,                                "Maximum number of merge candidates")
996
0
    ("MaxNumAffineMergeCand",                           c->m_maxNumAffineMergeCand,                          "Maximum number of affine merge candidates")
997
0
    ("Geo",                                             c->m_Geo,                                            "Enable geometric partitioning mode (0:off, 1:on)")
998
0
    ("MaxNumGeoCand",                                   c->m_maxNumGeoCand,                                  "Maximum number of geometric partitioning mode candidates")
999
0
    ("FastIntraTools",                                  c->m_FastIntraTools,                                 "SpeedUPIntraTools:LFNST,ISP,MTS. (0:off, 1:speed1, 2:speed2)")
1000
0
    ("IntraEstDecBit",                                  c->m_IntraEstDecBit,                                 "Intra estimation decimation binary exponent for first pass directional modes screening (only test each (2^N)-th mode in the first estimation pass)")
1001
0
    ;
1002
1003
    // motion search options
1004
0
    opts.setSubSection("Motion search options");
1005
0
    opts.addOptions()
1006
0
    ("FastSearch",                                      c->m_motionEstimationSearchMethod,                   "Search mode (0:Full search 1:Diamond 2:Deprecated 3:Enhanced Diamond 4: FastDiamond)")
1007
0
    ("FastSearchSCC",                                   c->m_motionEstimationSearchMethodSCC,                "Search mode for SCC (0:use non SCC-search 1:Deprecated 2:DiamondSCC 3:FastDiamondSCC)")
1008
0
    ("SearchRange,-sr",                                 c->m_SearchRange,                                    "Motion search range")
1009
0
    ("BipredSearchRange",                               c->m_bipredSearchRange,                              "Motion search range for bipred refinement")
1010
0
    ("MinSearchWindow",                                 c->m_minSearchWindow,                                "Minimum motion search window size for the adaptive window ME")
1011
0
    ("ClipForBiPredMEEnabled",                          c->m_bClipForBiPredMeEnabled,                        "Enable clipping in the Bi-Pred ME.")
1012
0
    ("FastMEAssumingSmootherMVEnabled",                 c->m_bFastMEAssumingSmootherMVEnabled,               "Enable fast ME assuming a smoother MV.")
1013
0
    ("IntegerET",                                       c->m_bIntegerET,                                     "Enable early termination for integer motion search")
1014
0
    ("FastSubPel",                                      c->m_fastSubPel,                                     "Enable fast sub-pel ME (1: enable fast sub-pel ME, 2: completely disable sub-pel ME)")
1015
0
    ("ReduceFilterME",                                  c->m_meReduceTap,                                    "Use reduced filter taps during subpel refinement (0 - use 8-tap; 1 - 6-tap; 2 - 4-tap)")
1016
0
    ;
1017
1018
    // Deblocking filter parameters
1019
0
    opts.setSubSection("Loop filters (deblock and SAO)");
1020
0
    opts.addOptions()
1021
0
    ("LoopFilterDisable",                               c->m_bLoopFilterDisable,                             "")
1022
0
    ("LoopFilterOffsetInPPS",                           c->m_loopFilterOffsetInPPS,                          "")
1023
0
    ("LoopFilterBetaOffset_div2",                       c->m_loopFilterBetaOffsetDiv2[0],                    "")
1024
0
    ("LoopFilterTcOffset_div2",                         c->m_loopFilterTcOffsetDiv2[0],                      "")
1025
0
    ("LoopFilterCbBetaOffset_div2",                     c->m_loopFilterBetaOffsetDiv2[1],                    "")
1026
0
    ("LoopFilterCbTcOffset_div2",                       c->m_loopFilterTcOffsetDiv2[1],                      "")
1027
0
    ("LoopFilterCrBetaOffset_div2",                     c->m_loopFilterBetaOffsetDiv2[2],                    "")
1028
0
    ("LoopFilterCrTcOffset_div2",                       c->m_loopFilterTcOffsetDiv2[2],                      "")
1029
1030
0
    ("DeblockLastTLayers",                              c->m_deblockLastTLayers,                             "Deblock only the highest n temporal layers, 0: all temporal layers are deblocked")
1031
1032
0
    ("DisableLoopFilterAcrossTiles",                    c->m_bDisableLFCrossTileBoundaryFlag,                "Loop filtering applied across tile boundaries or not (0: filter across tile boundaries  1: do not filter across tile boundaries)")
1033
0
    ("DisableLoopFilterAcrossSlices",                   c->m_bDisableLFCrossSliceBoundaryFlag,               "Loop filtering applied across tile boundaries or not (0: filter across slice boundaries  1: do not filter across slice boundaries)")
1034
1035
0
    ("SAO",                                             toSaoWithScc,                                        "Enable Sample Adaptive Offset (1: always, 2: only for screen content frames)")
1036
0
    ("SaoEncodingRate",                                 c->m_saoEncodingRate,                                "When >0 SAO early picture termination is enabled for luma and chroma")
1037
0
    ("SaoEncodingRateChroma",                           c->m_saoEncodingRateChroma,                          "The SAO early picture termination rate to use for chroma (when m_SaoEncodingRate is >0). If <=0, use results for luma")
1038
0
    ("SaoLumaOffsetBitShift",                           c->m_saoOffsetBitShift[ 0 ],                         "Specify the luma SAO bit-shift. If negative, automatically calculate a suitable value based upon bit depth and initial QP")
1039
0
    ("SaoChromaOffsetBitShift",                         c->m_saoOffsetBitShift[ 1 ],                         "Specify the chroma SAO bit-shift. If negative, automatically calculate a suitable value based upon bit depth and initial QP")
1040
0
    ;
1041
1042
0
    opts.setSubSection("SEI and auxiliary options");
1043
0
    opts.addOptions()
1044
0
    ("SEIDecodedPictureHash,-dph",                      toHashType,                                          "Control generation of decode picture hash SEI messages, (0:off, 1:md5, 2:crc, 3:checksum)" )
1045
0
    ("SEIBufferingPeriod",                              c->m_bufferingPeriodSEIEnabled,                      "Control generation of buffering period SEI messages")
1046
0
    ("SEIPictureTiming",                                c->m_pictureTimingSEIEnabled,                        "Control generation of picture timing SEI messages")
1047
0
    ("SEIDecodingUnitInfo",                             c->m_decodingUnitInfoSEIEnabled,                     "Control generation of decoding unit information SEI message.")
1048
0
    ("MasteringDisplayColourVolume",                    toMasteringDisplay,                                  "SMPTE ST 2086 mastering display colour volume info SEI (HDR), "
1049
0
                                                                                                             "vec(uint) size 10, x,y,x,y,x,y,x,y,max,min where: \"G(x,y)B(x,y)R(x,y)WP(x,y)L(max,min)\""
1050
0
                                                                                                             "range: 0 <= GBR,WP <= 50000, 0 <= L <= uint; GBR xy coordinates in increment of 1/50000, min/max luminance in units of 1/10000 cd/m2 "
1051
0
                                                                                                             "e.g. for P3D65 1000-nits, where G(x=0.265, y=0.690), B(x=0.150, y=0.060), R(x=0.680, y=0.320), WP(x=0.3127, y=0.3290), L(max=1000, min=0.0001): 13250,34500,7500,3000,34000,16000,15635,16450,10000000,1" )
1052
0
    ("MaxContentLightLevel",                            toContentLightLevel,                                 "Specify content light level info SEI as \"cll,fall\" (HDR) max. content light level, "
1053
0
                                                                                                             "max. frame average light level, range: 1 <= cll,fall <= 65535', e.g. 1000,400")
1054
0
    ("PreferredTransferCharacteristics",                toPrefTransferCharacteristics,                       "Specify preferred transfer characteristics SEI and overwrite transfer entry in VUI (0-18): reserved, bt709, unknown, empty, bt470m, bt470bg, smpte170m, "
1055
0
                                                                                                             "smpte240m, linear, log100, log316, iec61966-2-4, bt1361e, iec61966-2-1, "
1056
0
                                                                                                             "bt2020-10, bt2020-12, smpte2084, smpte428, arib-std-b67")
1057
0
    ("AccessUnitDelimiter,-aud",                        toAud,                                               "Enable Access Unit Delimiter NALUs (-1: auto, 0: off, 1: on; default: auto - enable only if needed by dependent options)" , true)
1058
0
    ("HrdParametersPresent,-hrd",                       c->m_hrdParametersPresent,                           "Enable generation of hrd_parameters() (0: off, 1: on)")
1059
0
    ("EnableDecodingParameterSet",                      c->m_decodingParameterSetEnabled,                    "Enable writing of Decoding Parameter Set")
1060
0
    ;
1061
      
1062
0
    opts.setSubSection("VUI options");
1063
0
    opts.addOptions()
1064
0
    ("VuiParametersPresent,-vui",                       toVui,                                               "Enable generation of vui_parameters() (-1: auto, 0: off, 1: on; default: auto - enable only if needed by dependent options)", true)
1065
0
    ("AspectRatioInfoPresent",                          c->m_aspectRatioInfoPresent,                         "Signals whether aspect_ratio_idc is present")
1066
0
    ("AspectRatioIdc",                                  c->m_aspectRatioIdc,                                 "Aspect ratio idc (0-16,255) 0=undef, 1=1:1, 2=12:11, 3=10:11, 4=16:11, 5=40:33, 6=24:11, 7=20:11, 8=32:11, 9=80:33, 10=18:11, 11=15:11, 12=64:33, "
1067
0
                                                                                                             "13=160:99, 14=4:3, 15=3:2, 16=2:1")
1068
0
    ("Sar",                                             toSarSize,                                           "Sample aspect ratio - ratio of width to height (WidthxHeight)")
1069
0
    ("SarWidth",                                        c->m_sarWidth,                                       "horizontal size of the sample aspect ratio")
1070
0
    ("SarHeight",                                       c->m_sarHeight,                                      "vertical size of the sample aspect ratio")
1071
1072
0
    ("ColourDescriptionPresent",                        c->m_colourDescriptionPresent,                       "Signals whether colour_primaries, transfer_characteristics, matrix_coefficients, full_range_flag are present")
1073
0
    ("ColourPrimaries",                                 toColourPrimaries,                                   "Specify colour primaries (0-13): reserved, bt709, unknown, empty, bt470m, bt470bg, smpte170m, "
1074
0
                                                                                                             "smpte240m, film, bt2020, smpte428, smpte431, smpte432")
1075
1076
0
    ("TransferCharacteristics",                         toTransferCharacteristics,                           "Specify opto-electronic transfer characteristics (0-18): reserved, bt709, unknown, empty, bt470m, bt470bg, smpte170m, "
1077
0
                                                                                                             "smpte240m, linear, log100, log316, iec61966-2-4, bt1361e, iec61966-2-1, "
1078
0
                                                                                                             "bt2020-10, bt2020-12, smpte2084, smpte428, arib-std-b67")
1079
0
    ("MatrixCoefficients",                              toColourMatrix,                                      "Specify colour matrix setting to derive luma/chroma from RGB primaries (0-14): gbr, bt709, unknown, empty, fcc, bt470bg, smpte170m, "
1080
0
                                                                                                             "smpte240m, ycgco, bt2020nc, bt2020c, smpte2085, chroma-derived-nc, chroma-derived-c, ictcp")
1081
1082
0
    ("ChromaLocInfoPresent",                            toChromaLocInfo,                                     "Signals whether chroma_sample_loc_type is present (-1: auto, 0: off, 1: on)")
1083
0
    ("ChromaSampleLocType",                             c->m_chromaSampleLocType,                            "Specifies the location of chroma samples for progressive content(-1 auto, 0-5 Chroma420LocType)")
1084
0
    ("OverscanInfoPresent",                             c->m_overscanInfoPresent,                            "Indicates whether conformant decoded pictures are suitable for display using overscan")
1085
0
    ("OverscanAppropriate",                             c->m_overscanAppropriateFlag,                        "Indicates whether conformant decoded pictures are suitable for display using overscan")
1086
0
    ("VideoFullRange",                                  toColourRangeMode,                                   "Indicates the black level and range of luma and chroma signals")
1087
0
    ("Range",                                           toColourRangeMode,                                   "set colour range: unknown, limited | mpeg | tv, full | jpeg | pc")
1088
0
    ;
1089
1090
0
    opts.setSubSection("Summary options (debugging)");
1091
0
    opts.addOptions()
1092
0
    ("SummaryOutFilename",                              toSummaryOutFilename,                                "Filename to use for producing summary output file. If empty, do not produce a file.")
1093
0
    ("SummaryPicFilenameBase",                          toSummaryPicFilenameBase,                            "Base filename to use for producing summary picture output files. The actual filenames used will have I.txt, P.txt and B.txt appended. If empty, do not produce a file.")
1094
0
    ("SummaryVerboseness",                              c->m_summaryVerboseness,                             "Specifies the level of the verboseness of the text output")
1095
0
    ;
1096
1097
0
    opts.setSubSection("Coding tools");
1098
0
    opts.addOptions()
1099
0
    ("SMVD",                                            c->m_SMVD,                                           "Enable Symmetric MVD (0:off 1:vtm 2:fast 3:faster\n")
1100
0
    ("AMVR",                                            c->m_AMVRspeed,                                      "Enable Adaptive MV precision Mode (IMV)")
1101
    // added for backward compatibility with VTM
1102
0
    ("IMV",                                             c->m_AMVRspeed,                                      "Enable Adaptive MV precision Mode (IMV)")
1103
0
    ("LMChroma",                                        c->m_LMChroma,                                       "Enable LMChroma prediction")
1104
0
    ("MRL",                                             c->m_MRL,                                            "MultiRefernceLines")
1105
0
    ("BDOF",                                            c->m_BDOF,                                           "Enable bi-directional optical flow")
1106
    // added for backward compatibility with VTM
1107
0
    ("BIO",                                             c->m_BDOF,                                           "Enable bi-directional optical flow")
1108
0
    ("DMVR",                                            c->m_DMVR,                                           "Decoder-side Motion Vector Refinement")
1109
0
    ("EncDbOpt",                                        c->m_EDO,                                            "Encoder optimization with deblocking filter 0:off 1:vtm 2:fast")
1110
0
    ("EDO",                                             c->m_EDO,                                            "Encoder optimization with deblocking filter 0:off 1:vtm 2:fast")
1111
0
    ("ALF",                                             c->m_alf,                                            "Adaptive Loop Filter" )
1112
0
    ("ALFSpeed",                                        c->m_alfSpeed,                                       "ALF speed (skip filtering of non-referenced frames) [0-1]" )
1113
0
    ("CCALF",                                           c->m_ccalf,                                          "Cross-component Adaptive Loop Filter" )
1114
0
    ("UseNonLinearAlfLuma",                             c->m_useNonLinearAlfLuma,                            "Non-linear adaptive loop filters for Luma Channel")
1115
0
    ("UseNonLinearAlfChroma",                           c->m_useNonLinearAlfChroma,                          "Non-linear adaptive loop filters for Chroma Channels")
1116
0
    ("MaxNumAlfAlternativesChroma",                     c->m_maxNumAlfAlternativesChroma,                    std::string("Maximum number of alternative Chroma filters (1-") + std::to_string(VVENC_MAX_NUM_ALF_ALTERNATIVES_CHROMA) + std::string (", inclusive)") )
1117
0
    ("ALFTempPred",                                     c->m_alfTempPred,                                    "Enable usage of ALF temporal prediction for filter data\n" )
1118
0
    ("ALFUnitSize",                                     c->m_alfUnitSize,                                    "Size of ALF Search Unit [-1:default size(CTU)]\n" )
1119
0
    ("PROF",                                            c->m_PROF,                                           "Enable prediction refinement with optical flow for affine mode")
1120
0
    ("Affine",                                          c->m_Affine,                                         "Enable affine prediction")
1121
0
    ("AffineType",                                      c->m_AffineType,                                     "Enable affine type prediction")
1122
0
    ("MMVD",                                            c->m_MMVD,                                           "Enable Merge mode with Motion Vector Difference")
1123
0
    ("MmvdDisNum",                                      c->m_MmvdDisNum,                                     "Number of MMVD Distance Entries")
1124
0
    ("AllowDisFracMMVD",                                c->m_allowDisFracMMVD,                               "Disable fractional MVD in MMVD mode adaptively")
1125
0
    ("MCTF",                                            c->m_vvencMCTF.MCTF,                                 "Enable GOP based temporal filter. (0:off, 1:filter all frames, 2:use SCC detection to disable for screen coded content)")
1126
0
    ("MCTFSpeed",                                       c->m_vvencMCTF.MCTFSpeed,                            "MCTF Fast Mode (0:best quality ... 4:fastest operation)")
1127
0
    ("MCTFLevelTilt",                                   toMCTFLevelTilt,                                     "MCTF filter strength raised for the three upper temporal levels, the pictures the others predict from (-1: auto, on with film grain analysis (fga) in random access; 0: off; 1: on, random access only; also raises explicit MCTFStrength values)")
1128
0
    ("MCTFUnitSize",                                    c->m_vvencMCTF.MCTFUnitSize,                         "Size of MCTF operation area (block size for motion compensation).")
1129
0
    ("MCTFFutureReference",                             c->m_vvencMCTF.MCTFFutureReference,                  "Enable referencing of future frames in the GOP based temporal filter. This is typically disabled for Low Delay configurations.")
1130
0
    ("MCTFFrame",                                       toMCTFFrames,                                        "Frame to filter Strength for frame in GOP based temporal filter")
1131
0
    ("MCTFStrength",                                    toMCTFStrengths,                                     "Strength for  frame in GOP based temporal filter.")
1132
0
    ("BIM",                                             toBIM,                                               "Block importance mapping: lower the QP of blocks that later pictures predict from (0: off, 1: CU-tree, TPL model with one GOP of look-ahead, 2: from MCTF's motion error)")
1133
0
    ("CuTreeStrength",                                  toCuTreeStrength,                                    "CU-tree (BIM 1): scale of its QP offsets [0...8.0)")
1134
0
    ("CuTreeBlockSize",                                 toCuTreeBlockSize,                                   "CU-tree (BIM 1): side of its analysis blocks in luma samples (16, 32, or -1: automatic, 32 from 720 lines on, else 16)")
1135
1136
0
    ("FastLocalDualTreeMode",                           c->m_fastLocalDualTreeMode,                          "Fast intra pass coding for local dual-tree in intra coding region (0:off, 1:use threshold, 2:one intra mode only)")
1137
0
    ("QtbttExtraFast",                                  c->m_qtbttSpeedUp,                                   "Non-VTM compatible QTBTT speed-ups" )
1138
0
    ("FastTTSplit",                                     c->m_fastTTSplit,                                    "Fast method for TT split" )
1139
0
    ("FastAMVR",                                        toFastAMVR,                                          "No AMVR search where the best mode is skip, where the motion search with quarter-sample MVDs costs more than 1.1 times "
1140
0
                                                                                                             "the best mode or its largest MVD is below half a sample; no 4-sample MVDs where that MVD is below 4 samples (0: off, 1: on)" )
1141
0
    ;
1142
1143
0
    opts.setSubSection("Threading, performance");
1144
0
    opts.addOptions()
1145
0
    ("MaxParallelFrames",                               c->m_maxParallelFrames,                              "Maximum number of frames to be processed in parallel(0:off, >=2: enable parallel frames)")
1146
0
    ("WppBitEqual",                                     c->m_ensureWppBitEqual,                              "Ensure bit equality with WPP case (0:off (sequencial mode), 1:copy from wpp line above, 2:line wise reset)")
1147
0
    ("EnablePicPartitioning",                           c->m_picPartitionFlag,                               "Enable picture partitioning (0: single tile, single slice, 1: multiple tiles/slices)")
1148
0
    ("TileColumnWidthArray",                            toTileColumnWidth,                                   "Tile column widths in units of CTUs. Last column width in list will be repeated uniformly to cover any remaining picture width")
1149
0
    ("TileRowHeightArray",                              toTileRowHeight,                                     "Tile row heights in units of CTUs. Last row height in list will be repeated uniformly to cover any remaining picture height")
1150
0
    ("TileParallelCtuEnc",                              c->m_tileParallelCtuEnc,                             "Allow parallel CTU block search in different tiles")
1151
0
    ("FppLinesSynchro",                                 toIfpLines,                                          "(deprecated) Inter-Frame Parallelization(IFP) explicit CTU-lines synchronization offset (-1: default mode with two lines, 0: off)")
1152
0
    ("IFPLines",                                        toIfpLines,                                          "Inter-Frame Parallelization(IFP) explicit CTU-lines synchronization offset (-1: default mode with two lines, 0: off)")
1153
0
    ("IFP",                                             toUseIfp,                                            "Inter-Frame Parallelization(IFP) (-1: auto, 0: off, 1: on, with default setting of IFPLines)")
1154
0
    ("NumParallelGOPs",                                 toNumParallelGOPs,                                   "Number of additional GOPs processed in parallel (-1: auto). With IFP: GOP parallel processing (auto: 0). Without IFP: GOPs of input read ahead so that frame parallel encoding can start later GOPs early, RAM for speed (auto: 2)")
1155
0
    ;
1156
1157
0
    opts.setSubSection("Coding tools");
1158
0
    opts.addOptions()
1159
0
    ("SbTMVP",                                          c->m_SbTMVP,                                         "Enable Subblock Temporal Motion Vector Prediction (0: off, 1: on)")
1160
0
    ("CIIP",                                            c->m_CIIP,                                           "Enable CIIP mode, 0: off, 1: vtm, 2: fast, 3: faster ")
1161
0
    ("SBT",                                             c->m_SBT,                                            "Enable Sub-Block Transform for inter blocks (0: off 1: vtm, 2: fast, 3: faster)" )
1162
0
    ("LFNST",                                           c->m_LFNST,                                          "Enable LFNST (0: off, 1: on)" )
1163
0
    ("MTS",                                             c->m_MTS,                                            "Multiple Transform Set (MTS)" )
1164
0
    ("MTSIntraMaxCand",                                 c->m_MTSIntraMaxCand,                                "Number of additional candidates to test for MTS in intra slices")
1165
0
    ("ISP",                                             c->m_ISP,                                            "Intra Sub-Partitions Mode (0: off, 1: vtm, 2: fast, 3: faster)")
1166
0
    ("TransformSkip",                                   c->m_TS,                                             "Transform skipping, 0: off, 1: TS, 2: TS with SCC detection ")
1167
0
    ("TransformSkipLog2MaxSize",                        c->m_TSsize,                                         "Specify transform-skip maximum log2-size. Minimum 2, Maximum 5")
1168
0
    ("ChromaTS",                                        c->m_useChromaTS,                                    "Transform skipping for chroma, 0:off, 1:on (requires transform skipping)")
1169
0
    ("BDPCM",                                           c->m_useBDPCM,                                       "BDPCM (0:off, 1:luma and chroma, 2: BDPCM with SCC detection)")
1170
0
    ("RPR",                                             c->m_rprEnabledFlag,                                 "Reference Sample Resolution (0: disable, 1: enabled, 2: RPR ready")
1171
0
    ("IBC",                                             c->m_IBCMode,                                        "IBC (0:off, 1:IBC, 2: IBC with SCC detection)")
1172
0
    ("IBCFastMethod",                                   c->m_IBCFastMethod,                                  "Fast methods for IBC. 1:default, [2..6] speedups")
1173
0
    ("BCW",                                             c->m_BCW,                                            "Enable Generalized Bi-prediction(Bcw) 0: disabled, 1: enabled, 2: fast")
1174
0
    ("FastInferMerge",                                  c->m_FIMMode,                                        "Fast method to skip Inter/Intra modes. 0: off, [1..4] speedups")
1175
0
    ("NumIntraModesFullRD",                             c->m_numIntraModesFullRD,                            "Number modes for full RD intra search [-1, 1..3] (default: -1 auto)")
1176
0
    ("ReduceIntraChromaModesFullRD",                    c->m_reduceIntraChromaModesFullRD,                   "Reduce modes for chroma full RD intra search")
1177
0
    ("FirstPassMode",                                   c->m_FirstPassMode,                                  "Mode for first encoding pass when using rate control "
1178
0
                                                                                                               "(0: default, 1: faster, 2: faster with temporal downsampling, "
1179
0
                                                                                                                "3: faster with resolution downsampling, "
1180
0
                                                                                                                "4: faster with temporal and resolution downsampling)" )
1181
0
    ;
1182
1183
0
    opts.setSubSection("Input Options");
1184
0
    opts.addOptions()
1185
0
    ("HorCollocatedChroma",                             c->m_horCollocatedChromaFlag,                        "Specifies location of a chroma sample relatively to the luma sample in horizontal direction in the reference picture resampling"
1186
0
                                                                                                             "(0: horizontally shifted by 0.5 units of luma samples, 1: collocated)")
1187
0
    ("VerCollocatedChroma",                             c->m_verCollocatedChromaFlag,                        "Specifies location of a chroma sample relatively to the luma sample in vertical direction in the cross-component linear model intra prediction and the reference picture resampling"
1188
0
                                                                                                             "(0: horizontally co-sited, vertically shifted by 0.5 units of luma samples, 1: collocated)")
1189
0
    ("ClipInputVideoToRec709Range",                     m_bClipInputVideoToRec709Range,                      "Enable clipping input video to the Rec. 709 Range on loading when InternalBitDepth is less than MSBExtendedBitDepth")
1190
0
    ;
1191
1192
0
    opts.setSubSection("Reconstructed video options");
1193
0
    opts.addOptions()
1194
0
    ("ClipOutputVideoToRec709Range",                    m_bClipOutputVideoToRec709Range,                     "Enable clipping output video to the Rec. 709 Range on saving when OutputBitDepth is less than InternalBitDepth")
1195
0
    ("PYUV",                                            m_packedYUVOutput,                                   "Enable output 10-bit and 12-bit YUV data as 5-byte and 3-byte (respectively) packed YUV data. Ignored for interlaced output.")
1196
0
    ;
1197
0
  }
1198
1199
0
  {
1200
0
    opts.setSubSection( "Tracing" );
1201
0
    opts.addOptions()
1202
0
    ("tracechannellist",              c->m_listTracingChannels,  "list all available tracing channels")
1203
0
    ("tracerule",                     toTraceRule,               "tracing rule (ex: \"D_CABAC:poc==8\" or \"D_REC_CB_LUMA:poc==8\")")
1204
0
    ("tracefile",                     toTraceFile,               "tracing file")
1205
0
    ;
1206
0
  }
1207
1208
0
  {
1209
0
    opts.setSubSection("Film grain analysis");
1210
0
    opts.addOptions()
1211
0
    ("fga",                           toFga,                     "Experimental: Film grain analysis generating the FGC SEI message (0: off, 1: the analysis of VTM, 2: (1) + grain measured from the temporal residual, calibrated scaling factors, 3: (2) + auto-regressive grain model)")
1212
0
    ("fgastrength",                   toFgaStrength,             "Experimental: Film grain strength as a factor of the analysed strength [0...4.0), 1.0 keeps it, 0 disables the grain")
1213
0
    ;
1214
0
  }
1215
1216
0
  std::ostringstream fullOpts;
1217
0
  po::doHelp( fullOpts, opts );
1218
1219
0
  for ( int i = 0; i < VVENC_MAX_GOP; i++ )
1220
0
  {
1221
0
    std::ostringstream cOSS;
1222
0
    cOSS << "Frame" << i+1;
1223
0
    opts.addOptions()(cOSS.str(), c->m_GOPList[i] );
1224
0
  }
1225
1226
0
  if( !m_easyMode )
1227
0
  {
1228
    // enable access to easy app param names as hidden option (usable for e.g. vvenc_set_param(c,"bitrate", 500000) )
1229
0
    opts.setSubSection("Extra");
1230
0
    opts.addOptions()
1231
0
    ("tickspersec",                                     c->m_TicksPerSecond,                                 "Ticks Per Second for dts generation, (1..27000000)")
1232
0
    ("framerate,r",                                     c->m_FrameRate,                                      "temporal rate (framerate) e.g. 25,29,30,50,59,60 ")
1233
0
    ("frames",                                          c->m_framesToBeEncoded,                              "max. frames to encode [all]")
1234
0
    ("bitrate",                                         toBitrate,                                           "bitrate for rate control (0: constant-QP encoding without rate control, otherwise "
1235
0
                                                                                                             "bits/second; use e.g. 1.5M, 1.5Mbps, 1500k, 1500kbps, 1500000bps, 1500000)")
1236
0
    ("maxrate",                                         toMaxRate,                                           "approximate maximum instantaneous bitrate for constrained VBR in rate control (0: "
1237
0
                                                                                                             "no rate cap; use e.g. 3.5M, 3.5Mbps, 3500k, 3500kbps, 3500000bps, 3500000), use suffix 'x' "
1238
0
                                                                                                             "to specify as a multiple of target bitrate")
1239
0
    ("qpa",                                             toQPA,                                               "Enable perceptually motivated QP adaptation, XPSNR based (0:off, 1:on)", true)
1240
0
    ("internal-bitdepth",                               c->m_internalBitDepth[0],                            "internal bitdepth (8, 10)")
1241
0
    ("refreshtype,-rt",                                 toDecRefreshType,                                    "intra refresh type (idr, cra, cra_cre: CRA, constrained RASL picture encoding)")
1242
0
    ("decodedpicturehash,-dph",                         toHashType,                                          "control generation of decode picture hash SEI messages, (0: off, 1: md5, 2: crc, 3: checksum)")
1243
0
    ;
1244
0
  }
1245
1246
  //
1247
  // parse command line parameters and read configuration files
1248
  //
1249
0
  try
1250
0
  {
1251
0
    po::ErrorReporter err;
1252
0
    const std::list<const char*>& argv_unhandled = po::scanArgv( opts, argc, (const char**) argv, err );
1253
1254
0
    if ( do_help || argc == 0 )
1255
0
    {
1256
0
      m_showHelp = true;
1257
0
      rcOstr << easyOpts.str();
1258
0
      return 1;
1259
0
    }
1260
0
    else if ( do_full_help )
1261
0
    {
1262
0
      m_showHelp = true;
1263
0
      rcOstr << fullOpts.str();
1264
1265
0
      if( m_easyMode )
1266
0
      {
1267
0
        std::ostringstream additionalStr;
1268
0
        additionalStr << std::endl << "#======== string options by option 'additional' ================" << std::endl;
1269
0
        additionalStr << "Additional useful options of full feature app can be used with string option 'additional'." << std::endl;
1270
0
        additionalStr << "All available options of full feature app and vvencapp can be used in 'additional'." << std::endl;
1271
0
        additionalStr << "Options are assigned by '(long)optionname=value'. Concatenate options with ':'" << std::endl;
1272
0
        additionalStr << "For instance set hdr10 bt2020 mode (corresponds to option '--hdr pq_2020')" << std::endl;
1273
0
        additionalStr << "vvencapp  --additional ColourPrimaries=bt2020:TransferCharacteristics=smpte2084:MatrixCoefficients=bt2020nc" << std::endl;
1274
0
        additionalStr << "'additional' options are always parsed after all other options have been parsed!" << std::endl;
1275
0
        additionalStr << "Overview of usefull additional options:" << std::endl;
1276
0
        rcOstr << additionalStr.str();
1277
1278
0
        po::Options unusedOpts;
1279
0
        std::ostringstream addOpts;
1280
0
        unusedOpts.setSubSection("additional - VUI options");
1281
0
        unusedOpts.addOptions()
1282
0
        ("AspectRatioIdc",                                  c->m_aspectRatioIdc,           "Aspect ratio idc (0-16,255) 0=undef, 1=1:1, 2=12:11, 3=10:11, 4=16:11, 5=40:33, 6=24:11, 7=20:11, 8=32:11, 9=80:33, 10=18:11, 11=15:11, 12=64:33, 13=160:99, 14=4:3, 15=3:2, 16=2:1 "
1283
0
                                                                                           "e.g. --additional AspectRatioIdc=14")
1284
0
        ("Sar",                                             toSarSize,                     "Sample aspect ratio - ratio of width to height (WidthxHeight)")
1285
0
        ("ColourDescriptionPresent",                        c->m_colourDescriptionPresent, "Signals whether colour_primaries, transfer_characteristics, matrix_coefficients, full_range_flag are present")
1286
0
        ("ColourPrimaries",                                 toColourPrimaries,             "Specify colour primaries (0-13): reserved, bt709, unknown, empty, bt470m, bt470bg, smpte170m, "
1287
0
                                                                                           "smpte240m, film, bt2020, smpte428, smpte431, smpte432")
1288
0
        ("TransferCharacteristics",                         toTransferCharacteristics,     "Specify opto-electronic transfer characteristics (0-18): reserved, bt709, unknown, empty, bt470m, bt470bg, smpte170m, "
1289
0
                                                                                           "smpte240m, linear, log100, log316, iec61966-2-4, bt1361e, iec61966-2-1, "
1290
0
                                                                                           "bt2020-10, bt2020-12, smpte2084, smpte428, arib-std-b67")
1291
0
        ("MatrixCoefficients",                              toColourMatrix,                "Specify colour matrix setting to derive luma/chroma from RGB primaries (0-14): gbr, bt709, unknown, empty, fcc, bt470bg, smpte170m, "
1292
0
                                                                                           "smpte240m, ycgco, bt2020nc, bt2020c, smpte2085, chroma-derived-nc, chroma-derived-c, ictcp")
1293
0
        ("ChromaLocInfoPresent",                            toChromaLocInfo,               "Signals whether chroma_sample_loc_type is present (-1: auto, 0: off, 1: on)")
1294
0
        ("ChromaSampleLocType",                             c->m_chromaSampleLocType,      "Specifies the location of chroma samples for progressive content(-1 auto, 0-5 Chroma420LocType)")
1295
0
        ("OverscanAppropriate",                             c->m_overscanAppropriateFlag,  "Indicates whether conformant decoded pictures are suitable for display using overscan")
1296
0
        ;
1297
1298
0
        unusedOpts.setSubSection("additional - SEI and auxiliary options");
1299
0
        unusedOpts.addOptions()
1300
0
        ("MasteringDisplayColourVolume",                    toMasteringDisplay,            "SMPTE ST 2086 mastering display colour volume info SEI (HDR), "
1301
0
                                                                                           "vec(uint) size 10, x,y,x,y,x,y,x,y,max,min where: \"G(x,y)B(x,y)R(x,y)WP(x,y)L(max,min)\""
1302
0
                                                                                           "range: 0 <= GBR,WP <= 50000, 0 <= L <= uint; GBR xy coordinates in increment of 1/50000, min/max luminance in units of 1/10000 cd/m2 "
1303
0
                                                                                           "e.g. for P3D65 1000-nits, where G(x=0.265, y=0.690), B(x=0.150, y=0.060), R(x=0.680, y=0.320), WP(x=0.3127, y=0.3290), L(max=1000, min=0.0001): "
1304
0
                                                                                           "--additional MasteringDisplayColourVolume=13250,34500,7500,3000,34000,16000,15635,16450,10000000,1" )
1305
0
        ("MaxContentLightLevel",                            toContentLightLevel,           "Specify content light level info SEI as \"cll,fall\" (HDR) max. content light level, "
1306
0
                                                                                           "max. frame average light level, range: 1 <= cll,fall <= 65535', e.g. --additional MaxContentLightLevel=1000,400")
1307
0
        ("PreferredTransferCharacteristics",                toPrefTransferCharacteristics, "Specify preferred transfer characteristics SEI and overwrite transfer entry in VUI (0-18): reserved, bt709, unknown, empty, bt470m, bt470bg, smpte170m, "
1308
0
                                                                                           "smpte240m, linear, log100, log316, iec61966-2-4, bt1361e, iec61966-2-1, "
1309
0
                                                                                           "bt2020-10, bt2020-12, smpte2084, smpte428, arib-std-b67 , e.g. --additional PreferredTransferCharacteristics=arib-std-b67")
1310
0
        ;
1311
0
       unusedOpts.setSubSection("additional - Slice decision options");
1312
0
        unusedOpts.addOptions()
1313
0
        ("PicReordering",                                   c->m_picReordering,            "Allow reordering of pictures (0:off, 1:on), should be disabled for low delay requirements")
1314
0
        ;
1315
1316
0
        po::doAdditionalOptList( addOpts, unusedOpts );
1317
0
        rcOstr << addOpts.str();
1318
1319
0
      }
1320
0
      return 1;
1321
0
    }
1322
1323
0
    if( !m_easyMode && !writeCfg.empty() )
1324
0
    {
1325
0
      std::ofstream cfgFile;
1326
0
      cfgFile.open( writeCfg.c_str(), std::ios::out | std::ios::trunc);
1327
0
      if( !cfgFile.is_open() )
1328
0
      {
1329
0
        rcOstr << " [error]: failed to open output config file " << writeCfg << std::endl;
1330
0
        return -1;
1331
0
      }
1332
0
      else
1333
0
      {
1334
0
        std::list<std::string> ignoreParamsLst;
1335
0
        ignoreParamsLst.push_back( "help" );
1336
0
        ignoreParamsLst.push_back( "longhelp" );
1337
0
        ignoreParamsLst.push_back( "fullhelp" );
1338
0
        ignoreParamsLst.push_back( "WriteConfig" );
1339
0
        ignoreParamsLst.push_back( "configfile" );
1340
0
        ignoreParamsLst.push_back( "c" );
1341
1342
0
        ignoreParamsLst.push_back( "decode" );
1343
0
        for ( int i = 0; i < VVENC_MAX_GOP; i++ )
1344
0
        {
1345
0
          std::ostringstream cOSS;
1346
0
          cOSS << "Frame" << i+1;
1347
0
          ignoreParamsLst.push_back( cOSS.str() );
1348
0
        }
1349
1350
0
        std::ostringstream cfgStream;
1351
0
        po::saveConfig( cfgStream, opts, ignoreParamsLst );
1352
0
        cfgFile << cfgStream.str() << std::endl;
1353
0
        cfgFile.close();
1354
0
      }
1355
0
    }
1356
1357
0
    if ( m_showVersion )
1358
0
    {
1359
0
      return 1;
1360
0
    }
1361
1362
    // file check
1363
0
    std::string cErr;
1364
0
    if( !m_inputFileName.empty() && !apputils::FileIOHelper::checkInputFile( m_inputFileName, cErr ) )
1365
0
    {
1366
0
      err.warn( "Input file" ) << cErr;
1367
0
    }
1368
1369
0
    if( !m_bitstreamFileName.empty() && !apputils::FileIOHelper::checkBitstreamFile( m_bitstreamFileName, cErr ) )
1370
0
    {
1371
0
      err.warn( "Bitstream file" ) << cErr;
1372
0
    }
1373
1374
0
    if( !m_inputFileName.empty() && m_inputFileName != "-" )
1375
0
    {
1376
0
      if( !m_bitstreamFileName.empty() && m_inputFileName == m_bitstreamFileName )
1377
0
      {
1378
0
        err.error( "Bitstream file" ) <<  "Bitstream file and Input file are the same.\n";
1379
0
      }
1380
0
      if( !m_reconFileName.empty() && m_inputFileName == m_reconFileName )
1381
0
      {
1382
0
        err.error( "Reconstructed YUV file" ) <<  "Reconstructed YUV file and Input file are the same.\n";
1383
0
      }
1384
0
      if( !m_RCStatsFileName.empty() && m_inputFileName == m_RCStatsFileName )
1385
0
      {
1386
0
        err.error( "rate control statistics file" ) <<  "rate control statistics file and Input file are the same.\n";
1387
0
      }
1388
0
    }
1389
1390
0
    if ( m_FrameSkip < 0 )
1391
0
    {
1392
0
      err.error( "number of frames to skip" ) << (m_easyMode ? "frameskip must be >= 0\n" : "FrameSkip must be >= 0\n");
1393
0
    }
1394
1395
    // check for y4m input
1396
0
    bool isY4m = ( m_forceY4mInput || apputils::FileIOHelper::isY4mInputFilename( m_inputFileName ) ) ? true : false;
1397
0
    if( !isY4m && apputils::FileIOHelper::isY4mHeaderAvailable( m_inputFileName ) )
1398
0
    {
1399
0
      err.warn( "Input file" ) << "Y4M file signature detected. Enable Y4M mode.\n";
1400
0
      isY4m = true;
1401
0
      m_forceY4mInput = true;
1402
0
    }
1403
1404
0
    if ( isY4m )
1405
0
    {
1406
0
      if( 0 > apputils::FileIOHelper::parseY4mHeader( m_inputFileName, *c, m_inputFileChromaFormat ))
1407
0
      {
1408
0
        err.error( "y4m parser" ) << "cannot parse y4m metadata.\n";
1409
0
      }
1410
0
    }
1411
1412
0
    if( sdrMode != VVENC_HDR_OFF || hdrMode != VVENC_HDR_OFF )
1413
0
    {
1414
      // check if at least one mode has changed, but error when both changed
1415
0
      if( sdrMode != hdrMode && sdrMode != VVENC_HDR_OFF && hdrMode != VVENC_HDR_OFF )
1416
0
      {
1417
0
        err.error( "Dynamic range" ) << "cannot combine hdr and sdr mode. use one or another.\n";
1418
0
      }
1419
1420
0
      c->m_HdrMode = (sdrMode != VVENC_HDR_OFF) ? sdrMode : hdrMode;
1421
0
    }
1422
1423
0
    for( auto& a : argv_unhandled )
1424
0
    {
1425
0
      rcOstr << "Unknown argument: '" << a << "'\n";
1426
0
      ret = warnUnknowParameter ? 2 : -1;
1427
0
    }
1428
1429
0
    if( err.is_errored )
1430
0
    {
1431
0
      rcOstr << err.outstr.str();
1432
0
      if( argc == 2 ) return VVENC_PARAM_BAD_NAME;
1433
0
      else            return warnUnknowParameter ? 2 : -1;
1434
0
    }
1435
0
    else if( err.is_warning )
1436
0
    {
1437
0
      rcOstr << err.outstr.str() << "\n";
1438
0
      return 2;
1439
0
    }
1440
0
  }
1441
0
  catch( program_options::ParseFailure &e )
1442
0
  {
1443
0
    rcOstr << "Error parsing option \"" << e.arg << "\" with argument \"" << e.val << "\".\n";
1444
0
    if( argc == 2 )
1445
0
      ret = VVENC_PARAM_BAD_VALUE;
1446
0
    else
1447
0
      ret = -1;
1448
0
  }
1449
1450
0
  return ret;
1451
0
}
1452
1453
bool checkCfg( vvenc_config* c, std::ostream& rcOstr )
1454
0
{
1455
0
  bool ret = false;
1456
0
1457
0
  // check bitstream file name in encode and decode mode
1458
0
  if( m_bitstreamFileName.empty() )
1459
0
  {
1460
0
    // if rc statsfile is defined and in 1st pass, bitstream file is not needed
1461
0
    if ( !(c->m_RCPass == 1 && !m_RCStatsFileName.empty()) )
1462
0
    {
1463
0
      rcOstr << "error: bitstream file name must be specified (" << (m_easyMode ? "--output" : "--BitstreamFile") << "=bit.266)" << std::endl;
1464
0
      ret = true;
1465
0
    }
1466
0
  }
1467
0
1468
0
  // check remaining parameter set
1469
0
  if( !xCheckCfg( c, rcOstr ) )
1470
0
  {
1471
0
    ret = true;
1472
0
  }
1473
0
  return ret;
1474
0
}
1475
1476
static inline std::string getDynamicRangeStr( int dynamicRange )
1477
0
{
1478
0
  std::string cT;
1479
0
  switch( dynamicRange )
1480
0
  {
1481
0
    case VVENC_HDR_OFF            : cT = "SDR"; break;
1482
0
    case VVENC_HDR_PQ             : cT = "HDR10/PQ"; break;
1483
0
    case VVENC_HDR_HLG            : cT = "HDR HLG"; break;
1484
0
    case VVENC_HDR_PQ_BT2020      : cT = "HDR10/PQ BT.2020"; break;
1485
0
    case VVENC_HDR_HLG_BT2020     : cT = "HDR HLG BT.2020"; break;
1486
0
    case VVENC_HDR_USER_DEFINED   : cT = "HDR user defined"; break;
1487
0
    case VVENC_SDR_BT709          : cT = "SDR BT.709"; break;
1488
0
    case VVENC_SDR_BT2020         : cT = "SDR BT.2020"; break;
1489
0
    case VVENC_SDR_BT470BG        : cT = "SDR BT.470 B/G"; break;
1490
0
    default                       : cT = "unknown"; break;
1491
0
  }
1492
0
  return cT;
1493
0
}
1494
1495
static int64_t getFrameCount( std::string fileName, unsigned int width, unsigned int height, vvencChromaFormat chromaFormat, int bitdepth, bool packed = false )
1496
0
{
1497
0
  int64_t packetCount = 0;
1498
1499
0
  if( !strcmp( fileName.c_str(), "-" ) )
1500
0
  {
1501
0
    return -1;
1502
0
  }
1503
1504
0
  std::fstream fhandle;
1505
0
  fhandle.open( fileName.c_str(), std::ios::binary | std::ios::in );
1506
0
  if( fhandle.fail() )
1507
0
    return -1;
1508
1509
0
  fhandle.seekg( 0, std::ios::end );
1510
0
  std::streamoff filelength = fhandle.tellg();
1511
0
  fhandle.close();
1512
1513
0
  unsigned int uiBitsPerPx = bitdepth == 8 ? 12 : 24;
1514
0
  switch ( chromaFormat )
1515
0
  {
1516
0
    case VVENC_CHROMA_400: uiBitsPerPx = bitdepth == 8 ?  8 : 16; break;
1517
0
    case VVENC_CHROMA_420: uiBitsPerPx = bitdepth == 8 ? 12 : 24; break;
1518
0
    case VVENC_CHROMA_422: uiBitsPerPx = bitdepth == 8 ? 16 : 32; break;
1519
0
    case VVENC_CHROMA_444: uiBitsPerPx = bitdepth == 8 ? 24 : 48; break;
1520
0
    default: break;
1521
0
  }
1522
1523
0
  size_t frameSize = (width * height * uiBitsPerPx) >> 3;
1524
1525
0
  if ( packed && bitdepth == 10 && chromaFormat == VVENC_CHROMA_420 )
1526
0
  {
1527
0
    size_t stride = width * 5 / 4;
1528
0
    size_t lumaSize = stride * height;
1529
0
    size_t chromaSize = lumaSize >> 2;
1530
0
    frameSize = lumaSize + chromaSize + chromaSize;
1531
0
  }
1532
1533
0
  packetCount = (int64_t)filelength / frameSize;
1534
0
  return packetCount;
1535
0
}
1536
1537
virtual std::string getAppConfigAsString( vvenc_config* c, vvencMsgLevel eMsgLevel ) const
1538
0
{
1539
0
  std::stringstream css;
1540
0
  std::string loglvl("vvenc ");
1541
0
  switch ( eMsgLevel )
1542
0
  {
1543
0
    case VVENC_SILENT : loglvl.append("[silent]: ");  break;
1544
0
    case VVENC_ERROR  : loglvl.append("[error]: ");   break;
1545
0
    case VVENC_WARNING: loglvl.append("[warning]: "); break;
1546
0
    case VVENC_INFO   : loglvl.append("[info]: ");    break;
1547
0
    case VVENC_NOTICE : loglvl.append("[notice]: ");  break;
1548
0
    case VVENC_VERBOSE: loglvl.append("[verbose]: "); break;
1549
0
    case VVENC_DETAILS: loglvl.append("[details]: "); break;
1550
0
    default: break;
1551
0
  }
1552
1553
0
  bool isY4m = ( m_forceY4mInput || apputils::FileIOHelper::isY4mInputFilename( m_inputFileName ) ) ? true : false;
1554
0
  std::string ext = apputils::FileIOHelper::getFileExtension( m_inputFileName );
1555
0
  std::transform( ext.begin(), ext.end(), ext.begin(), ::tolower );
1556
0
  std::string format = isY4m ? "y4m" : "yuv";
1557
1558
0
  if( eMsgLevel >= VVENC_INFO )
1559
0
  {
1560
0
    if( format != ext )
1561
0
      css << loglvl << "Input File                             : " << m_inputFileName << "  (" << format << ")\n";
1562
0
    else
1563
0
      css << loglvl << "Input File                             : " << m_inputFileName << "\n";
1564
0
    css << loglvl << "Bitstream File                         : " << m_bitstreamFileName << "\n";
1565
0
  }
1566
0
  if( eMsgLevel >= VVENC_DETAILS )
1567
0
  {
1568
0
    if( !m_easyMode )
1569
0
      css << loglvl << "Reconstruction File                    : " << m_reconFileName << "\n";
1570
0
    if ( c->m_RCTargetBitrate > 0 )
1571
0
      css << loglvl << "RC Statistics  File                    : " << m_RCStatsFileName << "\n";
1572
0
  }
1573
1574
0
  if ( c )
1575
0
  {
1576
0
    if( eMsgLevel >= VVENC_INFO )
1577
0
    {
1578
0
      std::string inputFmt;
1579
0
      switch ( c->m_internChromaFormat)
1580
0
      {
1581
0
        case VVENC_CHROMA_400: inputFmt= "yuv400p"; break;
1582
0
        case VVENC_CHROMA_422: inputFmt= "yuv422p"; break;
1583
0
        case VVENC_CHROMA_444: inputFmt= "yuv444p"; break;
1584
0
        case VVENC_CHROMA_420: 
1585
0
        default:
1586
0
          inputFmt= "yuv420p"; break;
1587
0
      }
1588
0
      if( c->m_inputBitDepth[ 0 ] == 10 )
1589
0
      {
1590
0
        inputFmt.append("10");
1591
0
        if ( m_packedYUVInput )
1592
0
          inputFmt.append("(packed)");
1593
0
      }
1594
1595
0
      std::stringstream frameCountStr;
1596
0
      std::stringstream framesStr;
1597
1598
0
      if( strcmp( m_inputFileName.c_str(), "-" ) )
1599
0
      {
1600
0
        int64_t frameCount = getFrameCount( m_inputFileName, c->m_SourceWidth, c->m_SourceHeight, c->m_internChromaFormat, c->m_inputBitDepth[ 0 ], m_packedYUVInput );
1601
0
        frameCountStr << frameCount << (frameCount > 1 ? " frames" : " frame");
1602
1603
0
        int64_t framesToEncode = (c->m_framesToBeEncoded == 0 || c->m_framesToBeEncoded >= frameCount) ? frameCount : c->m_framesToBeEncoded;
1604
0
        framesStr << "encode " << framesToEncode << ( framesToEncode > 1 ? " frames " : " frame ");
1605
0
      }
1606
0
      else 
1607
0
      {
1608
0
        framesStr << "encode "  << c->m_framesToBeEncoded << ( c->m_framesToBeEncoded > 1 ? " frames " : " frame ");
1609
0
      }
1610
1611
0
      if ( m_FrameSkip )
1612
0
        framesStr << " skip " << m_FrameSkip << ( m_FrameSkip > 1 ? " frames " : " frame ");         
1613
        
1614
0
      css << loglvl << "Real Format                            : ";      
1615
0
      css << c->m_PadSourceWidth - c->m_confWinLeft - c->m_confWinRight << "x" << c->m_PadSourceHeight - c->m_confWinTop - c->m_confWinBottom << "  "
1616
0
          << inputFmt << "  " << (double)c->m_FrameRate/c->m_FrameScale << " Hz  " << getDynamicRangeStr(c->m_HdrMode) << "  " << frameCountStr.str() << "\n";
1617
0
      css << loglvl << "Frames                                 : " << framesStr.str() << "\n";
1618
0
    }
1619
0
  }
1620
1621
0
  return css.str();
1622
0
}
1623
1624
std::vector <std::tuple<std::string, std::string>> getAdditionalSettingList()
1625
0
{
1626
0
  std::vector <std::tuple<std::string, std::string>> settingsDictionary;
1627
0
  if ( !m_additionalSettings.empty())
1628
0
  {
1629
0
    char delimiter =':'; // delimiter to mark entry beside space
1630
0
    std::vector<std::string> tokenvec = tokenize( m_additionalSettings, delimiter );
1631
0
1632
0
    for( auto &t : tokenvec )
1633
0
    {
1634
0
      char delimiterEntryValue = '='; // delimiter to mark entry from value
1635
0
      std::vector<std::string> entry = tokenize( t, delimiterEntryValue );
1636
0
1637
0
      if( !entry.empty() )
1638
0
      {
1639
0
        std::string key   = entry.front();
1640
0
        std::string value = entry.size() > 1 ? entry[1] : "";
1641
0
1642
0
        settingsDictionary.push_back(std::make_tuple( key, value) );
1643
0
      }
1644
0
    }
1645
0
  }
1646
0
1647
0
  return settingsDictionary;
1648
0
}
1649
1650
private:
1651
1652
bool xCheckCfg( vvenc_config* c, std::ostream& rcOstr )
1653
0
{
1654
0
  bool ret = true;
1655
0
1656
0
  if( m_inputFileName.empty() )
1657
0
  {
1658
0
    rcOstr << "error: input yuv file name must be specified (--input=video.yuv)" << std::endl;
1659
0
    ret = false;
1660
0
  }
1661
0
  if( ! strcmp( m_inputFileName.c_str(), "-" )
1662
0
      && c->m_RCNumPasses > 1
1663
0
      && c->m_RCPass < 0 )
1664
0
  {
1665
0
    rcOstr << "error: two pass rate control within single application call and reading from stdin not supported" << std::endl;
1666
0
    ret = false;
1667
0
  }
1668
0
1669
0
#ifndef VVENC_ENABLE_THIRDPARTY_JSON
1670
0
  if( c->m_RCPass > 0 )
1671
0
  {
1672
0
    rcOstr << "error: reading/writing rate control statistics file not supported, please disable pass parameter or compile with json enabled" << std::endl;
1673
0
    ret = false;
1674
0
  }
1675
0
  if( ! m_RCStatsFileName.empty() )
1676
0
  {
1677
0
    rcOstr << "error: reading/writing rate control statistics file not supported, please disable rcstatsfile parameter or compile with json enabled" << std::endl;
1678
0
    ret = false;
1679
0
  }
1680
0
  if( ! m_logoFileName.empty() )
1681
0
  {
1682
0
    rcOstr << "error: reading of logo overlay file not supported, please disable logofile parameter or compile with json enabled" << std::endl;
1683
0
    ret = false;
1684
0
  }
1685
0
#endif
1686
0
1687
0
  if( c->m_RCPass > 0 && m_RCStatsFileName.empty() )
1688
0
  {
1689
0
    rcOstr << "error: rate control statistics file name must be specify, when pass parameter is set (--rcstatsfile=stats.json)" << std::endl;
1690
0
    ret = false;
1691
0
  }
1692
0
  if( c->m_RCNumPasses == 1 && ! m_RCStatsFileName.empty() )
1693
0
  {
1694
0
    rcOstr << "error: rate control statistics file not supported in single pass encoding" << std::endl;
1695
0
    ret = false;
1696
0
  }
1697
0
1698
0
  if( m_inputFileChromaFormat != VVENC_CHROMA_400 && m_inputFileChromaFormat != VVENC_CHROMA_420 )
1699
0
  {
1700
0
    rcOstr << "error: input chroma format must be either 400, 420" << std::endl;
1701
0
    ret = false;
1702
0
  }
1703
0
1704
0
  if( m_packedYUVInput )
1705
0
  {
1706
0
    if( get_width_of_component( c->m_internChromaFormat, c->m_SourceWidth, 0 ) % 4 != 0 )
1707
0
    {
1708
0
      rcOstr <<  "error: unsupported input width for packed input (width must be a multiple of 4)" << std::endl;
1709
0
      ret = false;
1710
0
    }
1711
0
1712
0
    if( (c->m_internChromaFormat == VVENC_CHROMA_420 || c->m_internChromaFormat == VVENC_CHROMA_422) &&
1713
0
         get_width_of_component( c->m_internChromaFormat, c->m_SourceWidth, 1 ) % 4 != 0 )
1714
0
    {
1715
0
      rcOstr <<  "error: unsupported input width for packed input (chroma width must be a multiple of 4)" << std::endl;
1716
0
      ret = false;
1717
0
    }
1718
0
  }
1719
0
1720
0
  if( m_packedYUVOutput && ! m_reconFileName.empty() )
1721
0
  {
1722
0
    // if output bitdepth not defined, use internal bitdepth as default value
1723
0
    if (c->m_outputBitDepth[0] == 0) c->m_outputBitDepth[0] = c->m_internalBitDepth[0];
1724
0
    if (c->m_outputBitDepth[1] == 0) c->m_outputBitDepth[1] = c->m_outputBitDepth[0];
1725
0
1726
0
    if( ( c->m_outputBitDepth[ 0 ] != 10 && c->m_outputBitDepth[ 0 ] != 12 )
1727
0
        || ( ( ( c->m_SourceWidth ) & ( 1 + ( c->m_outputBitDepth[ 0 ] & 3 ) ) ) != 0 ) )
1728
0
    {
1729
0
      rcOstr << "error: invalid output bit-depth or image width for packed YUV output" << std::endl;
1730
0
      ret = false;
1731
0
    }
1732
0
    if( ( c->m_internChromaFormat != VVENC_CHROMA_400 ) && ( ( c->m_outputBitDepth[ 1 ] != 10 && c->m_outputBitDepth[ 1 ] != 12 )
1733
0
          || ( ( get_width_of_component( c->m_internChromaFormat, c->m_SourceWidth, 1 ) & ( 1 + ( c->m_outputBitDepth[ 1 ] & 3 ) ) ) != 0 ) ) )
1734
0
    {
1735
0
      rcOstr << "error: invalid chroma output bit-depth or image width for packed YUV output" << std::endl;
1736
0
      ret = false;
1737
0
    }
1738
0
  }
1739
0
1740
0
  return ret;
1741
0
}
1742
1743
1744
std::vector<std::string> tokenize(std::string str, char delimiter )
1745
0
{
1746
0
  std::vector<std::string> tokenvec;
1747
0
  bool tupleRequired=false;
1748
0
  std::string cDefDel = " ";
1749
0
  if ( delimiter == '=' )
1750
0
  {
1751
0
    // when searching for "=" we always want to return a tuple of "key value"
1752
0
    replace_if( str.begin(), str.end(), []( int c ){ return isspace( c ) || c == '='; }, ' ' );
1753
0
    tupleRequired=true;
1754
0
  }
1755
0
  else if ( delimiter == ':' )
1756
0
    replace_if( str.begin(), str.end(), []( int c ){ return isspace( c ) || c == ':'; }, ' ' );
1757
0
  else
1758
0
    replace_if( str.begin(), str.end(), []( int c ){ return isspace( c ); }, ' ' );
1759
0
1760
0
  std::string cDelList = "\"";  // lists must be defined within " "
1761
0
1762
0
  size_t start = str.find_first_not_of(cDefDel);
1763
0
  size_t end=std::string::npos;
1764
0
1765
0
  while (start != std::string::npos)
1766
0
  {
1767
0
    size_t startL = str.find(cDelList, start);  // Find occurence of a list
1768
0
    size_t endL = str.find(cDelList, startL+1); // Find occurence of list end
1769
0
1770
0
    end = str.find(cDefDel, start); // Find next occurence of delimiter
1771
0
1772
0
    if( startL != std::string::npos && endL != std::string::npos && startL <= end)
1773
0
    {
1774
0
      // extract a value as list, when " " was found ( only when both " was found a next space is in current statement)
1775
0
      std::string listItem = str.substr(start, endL-start );
1776
0
      std::string::iterator end_pos = std::remove(listItem.begin(), listItem.end(), '\"');
1777
0
      listItem.erase(end_pos, listItem.end());
1778
0
      tokenvec.push_back( listItem );
1779
0
1780
0
      end = str.find(cDefDel, endL);
1781
0
      start = str.find_first_not_of(cDefDel, end);
1782
0
    }
1783
0
    else if( startL != std::string::npos && endL == std::string::npos)
1784
0
    {
1785
0
      // error case, found start ", but without end
1786
0
      tokenvec.clear();
1787
0
      return tokenvec;
1788
0
    }
1789
0
    else
1790
0
    {
1791
0
      // Push back the token found into vector
1792
0
      if( (start==0 && tokenvec.empty()) || start>0 )
1793
0
      {
1794
0
        if( tupleRequired && !tokenvec.empty() )
1795
0
        {
1796
0
          // when in tuple mode, we extract everything after = as a value
1797
0
          end=std::string::npos;
1798
0
          tokenvec.push_back( str.substr(start, end) );
1799
0
        }
1800
0
        else
1801
0
        {
1802
0
          tokenvec.push_back( str.substr(start, end-start) );
1803
0
        }
1804
0
      }
1805
0
      // Skip all occurences of the delimiter to find new start
1806
0
      start = str.find_first_not_of(cDefDel, end);
1807
0
    }
1808
0
  }
1809
0
1810
0
  return tokenvec;
1811
0
}
1812
1813
1814
static int get_width_of_component( const vvencChromaFormat chFmt, const int frameWidth, const int compId )
1815
0
{
1816
0
  int w = frameWidth;
1817
0
  if ( compId > 0 )
1818
0
  {
1819
0
    switch ( chFmt )
1820
0
    {
1821
0
      case VVENC_CHROMA_400: w = 0;      break;
1822
0
      case VVENC_CHROMA_420:
1823
0
      case VVENC_CHROMA_422: w = w >> 1; break;
1824
0
      default: break;
1825
0
    }
1826
0
  }
1827
0
  return w;
1828
0
}
1829
1830
static int get_height_of_component( const vvencChromaFormat chFmt, const int frameHeight, const int compId )
1831
0
{
1832
0
  int h = frameHeight;
1833
0
  if ( compId > 0 )
1834
0
  {
1835
0
    switch ( chFmt )
1836
0
    {
1837
0
      case VVENC_CHROMA_400: h = 0;      break;
1838
0
      case VVENC_CHROMA_420: h = h >> 1; break;
1839
0
      case VVENC_CHROMA_422:
1840
0
      default: break;
1841
0
    }
1842
0
  }
1843
0
  return h;
1844
0
}
1845
1846
};
1847
1848
void setPresets( VVEncAppCfg* appcfg, vvenc_config* cfg,  int preset )
1849
0
{
1850
0
  VVEncAppCfg::presetChangeCallback callback = appcfg->getPresetChangeCallback();
1851
0
  if( callback )
1852
0
  {
1853
0
    callback( cfg, (vvencPresetMode)preset );
1854
0
  }
1855
0
}
1856
1857
void setInputBitDepthAndColorSpace( VVEncAppCfg* appcfg, vvenc_config* cfg, int dbcs )
1858
0
{
1859
0
  switch( dbcs )
1860
0
  {
1861
0
  case YUV420_8 :         appcfg->m_inputFileChromaFormat = VVENC_CHROMA_420; cfg->m_inputBitDepth[0] = 8;  break;
1862
0
  case YUV420_10 :        appcfg->m_inputFileChromaFormat = VVENC_CHROMA_420; cfg->m_inputBitDepth[0] = 10; break;
1863
0
  case YUV420_10_PACKED : appcfg->m_inputFileChromaFormat = VVENC_CHROMA_420; cfg->m_inputBitDepth[0] = 10; appcfg->m_packedYUVInput=true; break;
1864
0
  case YUV422_8 :         appcfg->m_inputFileChromaFormat = VVENC_CHROMA_422; cfg->m_inputBitDepth[0] = 8;  break;
1865
0
  case YUV422_10 :        appcfg->m_inputFileChromaFormat = VVENC_CHROMA_422; cfg->m_inputBitDepth[0] = 10; break;
1866
0
  case YUV444_8 :         appcfg->m_inputFileChromaFormat = VVENC_CHROMA_444; cfg->m_inputBitDepth[0] = 8;  break;
1867
0
  case YUV444_10 :        appcfg->m_inputFileChromaFormat = VVENC_CHROMA_444; cfg->m_inputBitDepth[0] = 10; break;
1868
0
  case YUV400_8 :         appcfg->m_inputFileChromaFormat = VVENC_CHROMA_400; cfg->m_inputBitDepth[0] = 8;  break;
1869
0
  case YUV400_10 :        appcfg->m_inputFileChromaFormat = VVENC_CHROMA_400; cfg->m_inputBitDepth[0] = 10; break;
1870
0
  default: break;
1871
0
  }
1872
0
}
1873
1874
static void setSAO( VVEncAppCfg*, vvenc_config *cfg, int saoVal )
1875
0
{
1876
0
  cfg->m_bUseSAO = !!saoVal;
1877
0
  cfg->m_saoScc  = saoVal == 2;
1878
0
}
1879
1880
static void setColourRange( VVEncAppCfg*, vvenc_config *cfg, int colourRange )
1881
0
{
1882
0
  if( colourRange ) // enable vui/colour description if colour range is specified
1883
0
  {
1884
0
    cfg->m_videoFullRangeFlag = (colourRange == 2) ? true : false;
1885
0
    cfg->m_colourDescriptionPresent = true;
1886
0
    cfg->m_vuiParametersPresent = true;
1887
0
  }
1888
0
}
1889
1890
} // namespace
1891
1892
//! \}
1893