1 /******************************************************************************\
2 Copyright (c) 2005-2020, Intel Corporation
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
7 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
9 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10
11 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
15 This sample was distributed or derived from the Intel's Media Samples package.
16 The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
17 or https://software.intel.com/en-us/media-client-solutions-support.
18 \**********************************************************************************/
19
20 #include "mfx_samples_config.h"
21
22 #include <cmath>
23 #include <memory>
24 #include "pipeline_encode.h"
25 #include "pipeline_user.h"
26 #include "pipeline_region_encode.h"
27 #include <stdarg.h>
28 #include <string>
29 #include "version.h"
30
31 #define VAL_CHECK(val, argIdx, argName) \
32 { \
33 if (val) \
34 { \
35 PrintHelp(NULL, MSDK_STRING("Input argument number %d \"%s\" require more parameters"), argIdx, argName); \
36 return MFX_ERR_UNSUPPORTED;\
37 } \
38 }
39
40 #ifndef MFX_VERSION
41 #error MFX_VERSION not defined
42 #endif
43
PrintHelp(msdk_char * strAppName,const msdk_char * strErrorMessage,...)44 void PrintHelp(msdk_char *strAppName, const msdk_char *strErrorMessage, ...)
45 {
46 msdk_printf(MSDK_STRING("Encoding Sample Version %s\n\n"), GetMSDKSampleVersion().c_str());
47
48 if (strErrorMessage)
49 {
50 va_list args;
51 msdk_printf(MSDK_STRING("ERROR: "));
52 va_start(args, strErrorMessage);
53 msdk_vprintf(strErrorMessage, args);
54 va_end(args);
55 msdk_printf(MSDK_STRING("\n\n"));
56 }
57
58 msdk_printf(MSDK_STRING("Usage: %s <msdk-codecid> [<options>] -i InputYUVFile -o OutputEncodedFile -w width -h height\n"), strAppName);
59 msdk_printf(MSDK_STRING("\n"));
60 msdk_printf(MSDK_STRING("Supported codecs, <msdk-codecid>:\n"));
61 msdk_printf(MSDK_STRING(" <codecid>=h264|mpeg2|vc1|mvc|jpeg - built-in Media SDK codecs\n"));
62 msdk_printf(MSDK_STRING(" <codecid>=h265|vp9 - in-box Media SDK plugins (may require separate downloading and installation)\n"));
63 msdk_printf(MSDK_STRING(" If codecid is jpeg, -q option is mandatory.)\n"));
64 msdk_printf(MSDK_STRING("Options: \n"));
65 #if defined(LINUX32) || defined(LINUX64)
66 msdk_printf(MSDK_STRING(" [-device /path/to/device] - set graphics device for processing\n"));
67 msdk_printf(MSDK_STRING(" For example: '-device /dev/dri/card0'\n"));
68 msdk_printf(MSDK_STRING(" '-device /dev/dri/renderD128'\n"));
69 msdk_printf(MSDK_STRING(" If not specified, defaults to the first Intel device found on the system\n"));
70 #endif
71 #if (defined(_WIN64) || defined(_WIN32)) && (MFX_VERSION >= 1031)
72 msdk_printf(MSDK_STRING(" [-dGfx] - preffer processing on dGfx (by default system decides)\n"));
73 msdk_printf(MSDK_STRING(" [-iGfx] - preffer processing on iGfx (by default system decides)\n"));
74 #endif
75 msdk_printf(MSDK_STRING(" [-nv12|nv16|yuy2|uyvy|ayuv|rgb4|p010|y210|y410|a2rgb10|p016|p210|y216] - input color format (by default YUV420 is expected).\n"));
76 msdk_printf(MSDK_STRING(" [-msb10] - 10-bit color format is expected to have data in Most Significant Bits of words.\n (LSB data placement is expected by default).\n This option also disables data shifting during file reading.\n"));
77 msdk_printf(MSDK_STRING(" [-ec::p010|yuy2|nv12|nv16|rgb4|ayuv|uyvy|y210|y410|p016|y216] - force output color format for encoder (conversion will be made if necessary). Default value: input color format\n"));
78 msdk_printf(MSDK_STRING(" [-tff|bff] - input stream is interlaced, top|bottom fielf first, if not specified progressive is expected\n"));
79 msdk_printf(MSDK_STRING(" [-bref] - arrange B frames in B pyramid reference structure\n"));
80 msdk_printf(MSDK_STRING(" [-nobref] - do not use B-pyramid (by default the decision is made by library)\n"));
81 msdk_printf(MSDK_STRING(" [-idr_interval size] - idr interval, default 0 means every I is an IDR, 1 means every other I frame is an IDR etc\n"));
82 msdk_printf(MSDK_STRING(" [-f frameRate] - video frame rate (frames per second)\n"));
83 msdk_printf(MSDK_STRING(" [-n number] - number of frames to process\n"));
84 msdk_printf(MSDK_STRING(" [-b bitRate] - encoded bit rate (Kbits per second), valid for H.264, H.265, MPEG2 and MVC encoders \n"));
85 msdk_printf(MSDK_STRING(" [-u usage] - target usage, valid for H.265, H.264, H.265, MPEG2 and MVC encoders. Expected values:\n"));
86 msdk_printf(MSDK_STRING(" veryslow(quality), slower, slow, medium(balanced), fast, faster, veryfast(speed)\n"));
87 msdk_printf(MSDK_STRING(" [-q quality] - mandatory quality parameter for JPEG encoder. In range [1,100]. 100 is the best quality. \n"));
88 msdk_printf(MSDK_STRING(" [-r distance] - Distance between I- or P- key frames (1 means no B-frames) \n"));
89 msdk_printf(MSDK_STRING(" [-g size] - GOP size (default 256)\n"));
90 msdk_printf(MSDK_STRING(" [-x numRefs] - number of reference frames\n"));
91 msdk_printf(MSDK_STRING(" [-num_active_P numRefs] - number of maximum allowed references for P frames (for HEVC only)\n"));
92 msdk_printf(MSDK_STRING(" [-num_active_BL0 numRefs] - number of maximum allowed references for B frames in L0 (for HEVC only)\n"));
93 msdk_printf(MSDK_STRING(" [-num_active_BL1 numRefs] - number of maximum allowed references for B frames in L1 (for HEVC only)\n"));
94 #if (MFX_VERSION >= 1027)
95 msdk_printf(MSDK_STRING(" [-TargetBitDepthLuma] - Encoding target bit depth for luma samples, by default same as source one \n"));
96 msdk_printf(MSDK_STRING(" [-TargetBitDepthChroma] - Encoding target bit depth for chroma samples, by default same as source one \n"));
97 #endif
98 msdk_printf(MSDK_STRING(" [-la] - use the look ahead bitrate control algorithm (LA BRC) (by default constant bitrate control method is used)\n"));
99 msdk_printf(MSDK_STRING(" for H.264, H.265 encoder. Supported only with -hw option on 4th Generation Intel Core processors. \n"));
100 msdk_printf(MSDK_STRING(" if [-icq] option is also enabled simultaneously, then LA_ICQ bitrate control algotithm will be used. \n"));
101 msdk_printf(MSDK_STRING(" [-la_ext] - use external LA plugin (compatible with H.264, H.265 encoders)\n"));
102 msdk_printf(MSDK_STRING(" [-lad depth] - depth parameter for the LA BRC, the number of frames to be analyzed before encoding. In range [0,100] (0 - default: auto-select by mediasdk library).\n"));
103 msdk_printf(MSDK_STRING(" may be 1 in the case when -mss option is specified \n"));
104 msdk_printf(MSDK_STRING(" if [-icq] option is also enabled simultaneously, then LA_ICQ bitrate control algotithm will be used. \n"));
105 msdk_printf(MSDK_STRING(" [-dstw width] - destination picture width, invokes VPP resizing\n"));
106 msdk_printf(MSDK_STRING(" [-dsth height] - destination picture height, invokes VPP resizing\n"));
107 msdk_printf(MSDK_STRING(" [-hw] - use platform specific SDK implementation (default)\n"));
108 msdk_printf(MSDK_STRING(" [-sw] - use software implementation, if not specified platform specific SDK implementation is used\n"));
109 msdk_printf(MSDK_STRING(" [-p plugin] - encoder plugin. Supported values: hevce_sw, hevce_gacc, hevce_hw, vp8e_hw, vp9e_hw, hevce_fei_hw\n"));
110 msdk_printf(MSDK_STRING(" (optional for Media SDK in-box plugins, required for user-encoder ones)\n"));
111 msdk_printf(MSDK_STRING(" [-path path] - path to plugin (valid only in pair with -p option)\n"));
112 msdk_printf(MSDK_STRING(" [-async] - depth of asynchronous pipeline. default value is 4. must be between 1 and 20.\n"));
113 msdk_printf(MSDK_STRING(" [-gpucopy::<on,off>] Enable or disable GPU copy mode\n"));
114 msdk_printf(MSDK_STRING(" [-robust:soft] - Recovery from GPU hang by inserting an IDR\n"));
115 msdk_printf(MSDK_STRING(" [-vbr] - variable bitrate control\n"));
116 msdk_printf(MSDK_STRING(" [-cbr] - constant bitrate control\n"));
117 msdk_printf(MSDK_STRING(" [-vcm] - Video Conferencing Mode (VCM) bitrate control method\n"));
118 msdk_printf(MSDK_STRING(" [-qvbr quality] - variable bitrate control algorithm with constant quality. Quality in range [1,51]. 1 is the best quality.\n"));
119 msdk_printf(MSDK_STRING(" [-icq quality] - Intelligent Constant Quality (ICQ) bitrate control method. In range [1,51]. 1 is the best quality.\n"));
120 msdk_printf(MSDK_STRING(" If [-la] or [-lad] options are enabled simultaneously, then LA_ICQ bitrate control method will be used.\n"));
121 msdk_printf(MSDK_STRING(" [-avbr] - average variable bitrate control algorithm \n"));
122 msdk_printf(MSDK_STRING(" [-convergence] - bitrate convergence period for avbr, in the unit of frame \n"));
123 msdk_printf(MSDK_STRING(" [-accuracy] - bitrate accuracy for avbr, in the range of [1, 100] \n"));
124 msdk_printf(MSDK_STRING(" [-cqp] - constant quantization parameter (CQP BRC) bitrate control method\n"));
125 msdk_printf(MSDK_STRING(" (by default constant bitrate control method is used), should be used along with -qpi, -qpp, -qpb.\n"));
126 msdk_printf(MSDK_STRING(" [-qpi] - constant quantizer for I frames (if bitrace control method is CQP). In range [1,51]. 0 by default, i.e.no limitations on QP.\n"));
127 msdk_printf(MSDK_STRING(" [-qpp] - constant quantizer for P frames (if bitrace control method is CQP). In range [1,51]. 0 by default, i.e.no limitations on QP.\n"));
128 msdk_printf(MSDK_STRING(" [-qpb] - constant quantizer for B frames (if bitrace control method is CQP). In range [1,51]. 0 by default, i.e.no limitations on QP.\n"));
129 #if (MFX_VERSION >= 1027)
130 msdk_printf(MSDK_STRING(" [-round_offset_in file] - use this file to set per frame inter/intra rounding offset(for AVC only)\n"));
131 #endif
132 msdk_printf(MSDK_STRING(" [-lowpower:<on,off>] - Turn this option ON to enable QuickSync Fixed Function (low-power HW) encoding mode\n"));
133 msdk_printf(MSDK_STRING(" [-ir_type] - Intra refresh type. 0 - no refresh, 1 - vertical refresh, 2 - horisontal refresh, 3 - slice refresh\n"));
134 msdk_printf(MSDK_STRING(" [-ir_cycle_size] - Number of pictures within refresh cycle starting from 2\n"));
135 msdk_printf(MSDK_STRING(" [-ir_qp_delta] - QP difference for inserted intra MBs. This is signed value in [-51, 51] range\n"));
136 msdk_printf(MSDK_STRING(" [-ir_cycle_dist] - Distance between the beginnings of the intra-refresh cycles in frames\n"));
137 msdk_printf(MSDK_STRING(" [-gpb:<on,off>] - Turn this option OFF to make HEVC encoder use regular P-frames instead of GPB\n"));
138 msdk_printf(MSDK_STRING(" [-TransformSkip:<on,off>]- Turn this option ON to enable transformskip\n"));
139 msdk_printf(MSDK_STRING(" -AvcTemporalLayers [array:Layer.Scale] Configures the temporal layers hierarchy\n"));
140 msdk_printf(MSDK_STRING(" -BaseLayerPID <pid> Sets priority ID for the base layer\n"));
141 msdk_printf(MSDK_STRING(" -SPSId <pid> Sets sequence parameter set ID\n"));
142 msdk_printf(MSDK_STRING(" -PPSId <pid> Sets picture parameter set ID\n"));
143 msdk_printf(MSDK_STRING(" -PicTimingSEI:<on,off> Enables or disables picture timing SEI\n"));
144 msdk_printf(MSDK_STRING(" -NalHrdConformance:<on,off> Enables or disables picture HRD conformance\n"));
145 msdk_printf(MSDK_STRING(" -VuiNalHrdParameters:<on,off> Enables or disables NAL HRD parameters in VUI header\n"));
146 msdk_printf(MSDK_STRING(" [-ppyr:<on,off>] - Turn this option ON to enable P-pyramid (by default the decision is made by library)\n"));
147 msdk_printf(MSDK_STRING(" [-num_slice] - number of slices in each video frame. 0 by default.\n"));
148 msdk_printf(MSDK_STRING(" If num_slice equals zero, the encoder may choose any slice partitioning allowed by the codec standard.\n"));
149 msdk_printf(MSDK_STRING(" [-mss] - maximum slice size in bytes. Supported only with -hw and h264 codec. This option is not compatible with -num_slice option.\n"));
150 msdk_printf(MSDK_STRING(" [-mfs] - maximum frame size in bytes. Supported only with h264 and hevc codec for VBR mode.\n"));
151 msdk_printf(MSDK_STRING(" [-BitrateLimit:<on,off>] - Turn this flag ON to set bitrate limitations imposed by the SDK encoder. Off by default.\n"));
152 msdk_printf(MSDK_STRING(" [-re] - enable region encode mode. Works only with h265 encoder\n"));
153 msdk_printf(MSDK_STRING(" [-trows rows] - Number of rows for tiled encoding\n"));
154 msdk_printf(MSDK_STRING(" [-tcols cols] - Number of columns for tiled encoding\n"));
155 msdk_printf(MSDK_STRING(" [-CodecProfile] - specifies codec profile\n"));
156 msdk_printf(MSDK_STRING(" [-CodecLevel] - specifies codec level\n"));
157 msdk_printf(MSDK_STRING(" [-GopOptFlag:closed] - closed gop\n"));
158 msdk_printf(MSDK_STRING(" [-GopOptFlag:strict] - strict gop\n"));
159 msdk_printf(MSDK_STRING(" [-AdaptiveI:<on,off>] - Turn Adaptive I frames on/off\n"));
160 msdk_printf(MSDK_STRING(" [-AdaptiveB:<on,off>] - Turn Adaptive B frames on/off\n"));
161 msdk_printf(MSDK_STRING(" [-InitialDelayInKB] - the decoder starts decoding after the buffer reaches the initial size InitialDelayInKB, \
162 which is equivalent to reaching an initial delay of InitialDelayInKB*8000/TargetKbps ms\n"));
163 msdk_printf(MSDK_STRING(" [-BufferSizeInKB ] - represents the maximum possible size of any compressed frames\n"));
164 msdk_printf(MSDK_STRING(" [-MaxKbps ] - for variable bitrate control, specifies the maximum bitrate at which \
165 the encoded data enters the Video Buffering Verifier buffer\n"));
166 msdk_printf(MSDK_STRING(" [-ws] - specifies sliding window size in frames\n"));
167 msdk_printf(MSDK_STRING(" [-wb] - specifies the maximum bitrate averaged over a sliding window in Kbps\n"));
168 msdk_printf(MSDK_STRING(" [-amfs:<on,off>] - adaptive max frame size. If set on, P or B frame size can exceed MaxFrameSize when the scene change is detected.\
169 It can benefit the video quality \n"));
170 #if (MFX_VERSION >= 1023)
171 msdk_printf(MSDK_STRING(" [-LowDelayBRC] - strictly obey average frame size set by MaxKbps\n"));
172 #endif
173 msdk_printf(MSDK_STRING(" [-signal:tm ] - represents transfer matrix coefficients for mfxExtVideoSignalInfo. 0 - unknown, 1 - BT709, 2 - BT601\n"));
174 msdk_printf(MSDK_STRING(" [-WeightedPred:default|implicit ] - enables weighted prediction mode\n"));
175 msdk_printf(MSDK_STRING(" [-WeightedBiPred:default|implicit ] - enables weighted bi-prediction mode\n"));
176 msdk_printf(MSDK_STRING(" [-timeout] - encoding in cycle not less than specific time in seconds\n"));
177 msdk_printf(MSDK_STRING(" [-perf_opt n] - sets number of prefetched frames. In performance mode app preallocates buffer and loads first n frames\n"));
178 msdk_printf(MSDK_STRING(" [-fps] - limits overall fps of pipeline\n"));
179 msdk_printf(MSDK_STRING(" [-uncut] - do not cut output file in looped mode (in case of -timeout option)\n"));
180 msdk_printf(MSDK_STRING(" [-dump fileName] - dump MSDK components configuration to the file in text form\n"));
181 msdk_printf(MSDK_STRING(" [-qpfile <filepath>] - if specified, the encoder will take frame parameters (frame number, QP, frame type) from text file\n"));
182 msdk_printf(MSDK_STRING(" [-tcbrctestfile <filepath>] - if specified, the encoder will take targetFrameSize parameters for TCBRC test from text file\n"));
183 msdk_printf(MSDK_STRING(" [-usei] - insert user data unregistered SEI. eg: 7fc92488825d11e7bb31be2e44b06b34:0:MSDK (uuid:type<0-preifx/1-suffix>:message)\n"));
184 msdk_printf(MSDK_STRING(" the suffix SEI for HEVCe can be inserted when CQP used or HRD disabled\n"));
185 #if (MFX_VERSION >= MFX_VERSION_NEXT)
186 msdk_printf(MSDK_STRING(" [-dblk_alpha] - alpha deblocking parameter. In range[-12,12]. 0 by default.\n"));
187 msdk_printf(MSDK_STRING(" [-dblk_beta] - beta deblocking parameter. In range[-12,12]. 0 by default.\n"));
188 #endif
189 #if (MFX_VERSION >= 1024)
190 msdk_printf(MSDK_STRING(" [-extbrc:<on,off,implicit>] - External BRC for AVC and HEVC encoders\n"));
191 #endif
192 #if (MFX_VERSION >= 1026)
193 msdk_printf(MSDK_STRING(" [-ExtBrcAdaptiveLTR:<on,off>] - Set AdaptiveLTR for implicit extbrc\n"));
194 #endif
195 msdk_printf(MSDK_STRING("Example: %s h265 -i InputYUVFile -o OutputEncodedFile -w width -h height -hw -p 2fca99749fdb49aeb121a5b63ef568f7\n"), strAppName);
196 msdk_printf(MSDK_STRING(" [-preset <default,dss,conference,gaming>] - Use particular preset for encoding parameters\n"));
197 msdk_printf(MSDK_STRING(" [-pp] - Print preset parameters\n"));
198 msdk_printf(MSDK_STRING(" [-sys] - work with linear buffer in system memory\n"));
199 #if D3D_SURFACES_SUPPORT
200 msdk_printf(MSDK_STRING(" [-d3d] - work with d3d surfaces\n"));
201 msdk_printf(MSDK_STRING(" [-d3d11] - work with d3d11 surfaces\n"));
202 msdk_printf(MSDK_STRING(" [-single_texture_d3d11 ] - single texture mode for d3d11 allocator \n"));
203 msdk_printf(MSDK_STRING("Example: %s h264|h265|mpeg2|jpeg -i InputYUVFile -o OutputEncodedFile -w width -h height -d3d -hw \n"), strAppName);
204 msdk_printf(MSDK_STRING("Example for MVC: %s mvc -i InputYUVFile_1 -i InputYUVFile_2 -o OutputEncodedFile -w width -h height \n"), strAppName);
205 #endif
206 #ifdef LIBVA_SUPPORT
207 msdk_printf(MSDK_STRING(" [-vaapi] - work with vaapi surfaces\n"));
208 msdk_printf(MSDK_STRING("Example: %s h264|mpeg2|mvc -i InputYUVFile -o OutputEncodedFile -w width -h height -angle 180 -g 300 -r 1 \n"), strAppName);
209 #endif
210 #if defined (ENABLE_V4L2_SUPPORT)
211 msdk_printf(MSDK_STRING(" [-d] - Device video node (eg: /dev/video0)\n"));
212 msdk_printf(MSDK_STRING(" [-p] - Mipi Port number (eg: Port 0)\n"));
213 msdk_printf(MSDK_STRING(" [-m] - Mipi Mode Configuration [PREVIEW/CONTINUOUS/STILL/VIDEO]\n"));
214 msdk_printf(MSDK_STRING(" [-UYVY] - Input Raw format types V4L2 Encode\n"));
215 msdk_printf(MSDK_STRING(" [-YUY2] - Input Raw format types V4L2 Encode\n"));
216 msdk_printf(MSDK_STRING(" [-i::v4l2] - To enable v4l2 option\n"));
217 msdk_printf(MSDK_STRING("Example: %s h264|mpeg2|mvc -i::v4l2 -o OutputEncodedFile -w width -h height -d /dev/video0 -UYVY -m preview -p 0\n"), strAppName);
218 #endif
219 msdk_printf(MSDK_STRING(" [-viewoutput] - instruct the MVC encoder to output each view in separate bitstream buffer. Depending on the number of -o options behaves as follows:\n"));
220 msdk_printf(MSDK_STRING(" 1: two views are encoded in single file\n"));
221 msdk_printf(MSDK_STRING(" 2: two views are encoded in separate files\n"));
222 msdk_printf(MSDK_STRING(" 3: behaves like 2 -o opitons was used and then one -o\n\n"));
223 msdk_printf(MSDK_STRING("Example: %s mvc -i InputYUVFile_1 -i InputYUVFile_2 -o OutputEncodedFile_1 -o OutputEncodedFile_2 -viewoutput -w width -h height \n"), strAppName);
224 // user module options
225 msdk_printf(MSDK_STRING("User module options: \n"));
226 msdk_printf(MSDK_STRING(" [-angle 180] - enables 180 degrees picture rotation before encoding, CPU implementation by default. Rotation requires NV12 input. Options -tff|bff, -dstw, -dsth, -d3d are not effective together with this one, -nv12 is required.\n"));
227 msdk_printf(MSDK_STRING(" [-opencl] - rotation implementation through OPENCL\n"));
228 msdk_printf(MSDK_STRING("Example: %s h264|h265|mpeg2|mvc|jpeg -i InputYUVFile -o OutputEncodedFile -w width -h height -angle 180 -opencl \n"), strAppName);
229
230 msdk_printf(MSDK_STRING("\n"));
231 }
232
ParseAdditionalParams(msdk_char * strInput[],mfxU8 nArgNum,mfxU8 & i,sInputParams * pParams)233 mfxStatus ParseAdditionalParams(msdk_char *strInput[], mfxU8 nArgNum, mfxU8& i, sInputParams* pParams)
234 {
235 if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-AvcTemporalLayers")))
236 {
237 pParams->nAvcTemp = 1;
238 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
239 mfxU16 arr[8] = { 0,0,0,0,0,0,0,0 };
240 int j;
241 msdk_sscanf(strInput[i + 1], MSDK_STRING("%hu %hu %hu %hu %hu %hu %hu %hu"), &arr[0], &arr[1], &arr[2], &arr[3], &arr[4], &arr[5], &arr[6], &arr[7]);
242 for (j = 0; j < 8; j++)
243 {
244 pParams->nAvcTemporalLayers[j] = arr[j];
245 }
246 i += 1;
247 }
248 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-u")))
249 {
250 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
251 pParams->nTargetUsage = StrToTargetUsage(strInput[++i]);
252 if (!pParams->nTargetUsage)
253 {
254 msdk_printf(MSDK_STRING("error: wrong '-u' parameter. Balanced will be used.\n"));
255 pParams->nTargetUsage = MFX_TARGETUSAGE_BALANCED;
256 }
257 }
258 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-tcbrctestfile")))
259 {
260 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
261 pParams->TCBRCFileMode = true;
262 pParams->strTCBRCFilePath = strInput[++i];
263 i += 1;
264 }
265
266 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-BaseLayerPID")))
267 {
268 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
269 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nBaseLayerPID))
270 {
271 PrintHelp(strInput[0], MSDK_STRING("BaseLayerPID is invalid"));
272 return MFX_ERR_UNSUPPORTED;
273 }
274 }
275
276 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-SPSId")))
277 {
278 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
279 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nSPSId))
280 {
281 PrintHelp(strInput[0], MSDK_STRING("SPSId is invalid"));
282 return MFX_ERR_UNSUPPORTED;
283 }
284 }
285 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-PPSId")))
286 {
287 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
288 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nPPSId))
289 {
290 PrintHelp(strInput[0], MSDK_STRING("PPSId is invalid"));
291 return MFX_ERR_UNSUPPORTED;
292 }
293 }
294 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-PicTimingSEI:on")))
295 {
296 pParams->nPicTimingSEI = MFX_CODINGOPTION_ON;
297 }
298 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-PicTimingSEI:off")))
299 {
300 pParams->nPicTimingSEI = MFX_CODINGOPTION_OFF;
301 }
302 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-NalHrdConformance:on")))
303 {
304 pParams->nNalHrdConformance = MFX_CODINGOPTION_ON;
305 }
306 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-NalHrdConformance:off")))
307 {
308 pParams->nNalHrdConformance = MFX_CODINGOPTION_OFF;
309 }
310 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-VuiNalHrdParameters:on")))
311 {
312 pParams->nVuiNalHrdParameters = MFX_CODINGOPTION_ON;
313 }
314 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-VuiNalHrdParameters:off")))
315 {
316 pParams->nVuiNalHrdParameters = MFX_CODINGOPTION_OFF;
317 }
318 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-la_ext")))
319 {
320 pParams->bEnableExtLA = true;
321 pParams->nRateControlMethod = MFX_RATECONTROL_LA_EXT;
322 }
323 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-vcm")))
324 {
325 pParams->nRateControlMethod = MFX_RATECONTROL_VCM;
326 }
327 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-p210")))
328 {
329 pParams->FileInputFourCC = MFX_FOURCC_P210;
330 }
331 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-nv16")))
332 {
333 pParams->FileInputFourCC = MFX_FOURCC_NV16;
334 }
335 #if (MFX_VERSION >= 1031)
336 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-p016")))
337 {
338 pParams->FileInputFourCC = MFX_FOURCC_P016;
339 }
340 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-y216")))
341 {
342 pParams->FileInputFourCC = MFX_FOURCC_Y216;
343 }
344 #endif
345 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::yuy2")))
346 {
347 pParams->EncodeFourCC = MFX_FOURCC_YUY2;
348 }
349 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::nv12")))
350 {
351 pParams->EncodeFourCC = MFX_FOURCC_NV12;
352 }
353 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::rgb4")))
354 {
355 pParams->EncodeFourCC = MFX_FOURCC_RGB4;
356 }
357 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::ayuv")))
358 {
359 pParams->EncodeFourCC = MFX_FOURCC_AYUV;
360 }
361 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::uyvy")))
362 {
363 pParams->EncodeFourCC = MFX_FOURCC_UYVY;
364 }
365 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::nv16")))
366 {
367 pParams->EncodeFourCC = MFX_FOURCC_NV16;
368 }
369 #if (MFX_VERSION >= 1027)
370 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::y210")))
371 {
372 pParams->EncodeFourCC = MFX_FOURCC_Y210;
373 }
374 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::y410")))
375 {
376 pParams->EncodeFourCC = MFX_FOURCC_Y410;
377 }
378 #endif
379 #if (MFX_VERSION >= 1031)
380 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::p016")))
381 {
382 pParams->EncodeFourCC = MFX_FOURCC_P016;
383 }
384 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::y216")))
385 {
386 pParams->EncodeFourCC = MFX_FOURCC_Y216;
387 }
388 #endif
389 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-fps")))
390 {
391 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
392
393 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nMaxFPS))
394 {
395 PrintHelp(strInput[0], MSDK_STRING("overall fps is invalid"));
396 return MFX_ERR_UNSUPPORTED;
397 }
398 }
399 #if (MFX_VERSION >= 1027)
400 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-TargetBitDepthLuma")))
401 {
402 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
403
404 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->TargetBitDepthLuma))
405 {
406 PrintHelp(strInput[0], MSDK_STRING("TargetBitDepthLuma is invalid"));
407 return MFX_ERR_UNSUPPORTED;
408 }
409 }
410 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-TargetBitDepthChroma")))
411 {
412 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
413
414 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->TargetBitDepthChroma))
415 {
416 PrintHelp(strInput[0], MSDK_STRING("TargetBitDepthChroma is invalid"));
417 return MFX_ERR_UNSUPPORTED;
418 }
419 }
420 #endif
421 else
422 {
423 return MFX_ERR_NOT_FOUND;
424 }
425 return MFX_ERR_NONE;
426 }
427
428
ParseInputString(msdk_char * strInput[],mfxU8 nArgNum,sInputParams * pParams)429 mfxStatus ParseInputString(msdk_char* strInput[], mfxU8 nArgNum, sInputParams* pParams)
430 {
431
432 if (1 == nArgNum)
433 {
434 PrintHelp(strInput[0], NULL);
435 return MFX_ERR_UNSUPPORTED;
436 }
437
438 MSDK_CHECK_POINTER(pParams, MFX_ERR_NULL_PTR);
439 msdk_opt_read(MSDK_CPU_ROTATE_PLUGIN, pParams->strPluginDLLPath);
440
441 // default implementation
442 pParams->bUseHWLib = true;
443 pParams->isV4L2InputEnabled = false;
444 pParams->nNumFrames = 0;
445 pParams->FileInputFourCC = MFX_FOURCC_I420;
446 pParams->EncodeFourCC = 0;
447 pParams->nPRefType = MFX_P_REF_DEFAULT;
448 pParams->QPFileMode = false;
449 pParams->TCBRCFileMode = false;
450 pParams->BitrateLimit = MFX_CODINGOPTION_OFF;
451 #if (MFX_VERSION >= 1027)
452 pParams->RoundingOffsetFile = NULL;
453 #endif
454 #if defined (ENABLE_V4L2_SUPPORT)
455 pParams->MipiPort = -1;
456 pParams->MipiMode = NONE;
457 pParams->v4l2Format = NO_FORMAT;
458 #endif
459
460 // parse command line parameters
461 for (mfxU8 i = 1; i < nArgNum; i++)
462 {
463 MSDK_CHECK_POINTER(strInput[i], MFX_ERR_NULL_PTR);
464
465 if (MSDK_CHAR('-') != strInput[i][0])
466 {
467 mfxStatus sts = StrFormatToCodecFormatFourCC(strInput[i], pParams->CodecId);
468 if (sts != MFX_ERR_NONE)
469 {
470 PrintHelp(strInput[0], MSDK_STRING("Unknown codec"));
471 return MFX_ERR_UNSUPPORTED;
472 }
473 if (!IsEncodeCodecSupported(pParams->CodecId))
474 {
475 PrintHelp(strInput[0], MSDK_STRING("Unsupported codec"));
476 return MFX_ERR_UNSUPPORTED;
477 }
478 if (pParams->CodecId == CODEC_MVC)
479 {
480 pParams->CodecId = MFX_CODEC_AVC;
481 pParams->MVC_flags |= MVC_ENABLED;
482 }
483 continue;
484 }
485
486 // process multi-character options
487 if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-dstw")))
488 {
489 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
490 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nDstWidth))
491 {
492 PrintHelp(strInput[0], MSDK_STRING("Destination picture Width is invalid"));
493 return MFX_ERR_UNSUPPORTED;
494 }
495 }
496 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-dsth")))
497 {
498 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
499 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nDstHeight))
500 {
501 PrintHelp(strInput[0], MSDK_STRING("Destination picture Height is invalid"));
502 return MFX_ERR_UNSUPPORTED;
503 }
504 }
505 #if (defined(LINUX32) || defined(LINUX64))
506 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-device")))
507 {
508 if (!pParams->strDevicePath.empty())
509 {
510 msdk_printf(MSDK_STRING("error: you can specify only one device\n"));
511 return MFX_ERR_UNSUPPORTED;
512 }
513 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
514 pParams->strDevicePath = strInput[++i];
515 }
516 #endif
517 #if (defined(_WIN64) || defined(_WIN32)) && (MFX_VERSION >= 1031)
518 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-dGfx")))
519 {
520 pParams->bPrefferdGfx = true;
521 }
522 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-iGfx")))
523 {
524 pParams->bPrefferiGfx = true;
525 }
526 #endif
527 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-trows")))
528 {
529 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
530 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nEncTileRows))
531 {
532 PrintHelp(strInput[0], MSDK_STRING("Encoding tile row count is invalid"));
533 return MFX_ERR_UNSUPPORTED;
534 }
535 }
536 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-tcols")))
537 {
538 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
539 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nEncTileCols))
540 {
541 PrintHelp(strInput[0], MSDK_STRING("Encoding tile column count is invalid"));
542 return MFX_ERR_UNSUPPORTED;
543 }
544 }
545 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-sw")))
546 {
547 pParams->bUseHWLib = false;
548 }
549 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-hw")))
550 {
551 pParams->bUseHWLib = true;
552 }
553 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-yuy2")))
554 {
555 pParams->FileInputFourCC = MFX_FOURCC_YUY2;
556 }
557 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-nv12")))
558 {
559 pParams->FileInputFourCC = MFX_FOURCC_NV12;
560 }
561 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-rgb4")))
562 {
563 pParams->FileInputFourCC = MFX_FOURCC_RGB4;
564 }
565 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-p010")))
566 {
567 pParams->FileInputFourCC = MFX_FOURCC_P010;
568 }
569 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ayuv")))
570 {
571 pParams->FileInputFourCC = MFX_FOURCC_AYUV;
572 }
573 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-uyvy")))
574 {
575 pParams->FileInputFourCC = MFX_FOURCC_UYVY;
576 }
577 #if (MFX_VERSION >= 1027)
578 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-y210")))
579 {
580 pParams->FileInputFourCC = MFX_FOURCC_Y210;
581 }
582 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-y410")))
583 {
584 pParams->FileInputFourCC = MFX_FOURCC_Y410;
585 }
586 #endif
587 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-a2rgb10")))
588 {
589 pParams->FileInputFourCC = MFX_FOURCC_A2RGB10;
590 }
591 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ec::p010")))
592 {
593 pParams->EncodeFourCC = MFX_FOURCC_P010;
594 }
595 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-tff")))
596 {
597 pParams->nPicStruct = MFX_PICSTRUCT_FIELD_TFF;
598 }
599 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-bff")))
600 {
601 pParams->nPicStruct = MFX_PICSTRUCT_FIELD_BFF;
602 }
603 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-bref")))
604 {
605 pParams->nBRefType = MFX_B_REF_PYRAMID;
606 }
607 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-nobref")))
608 {
609 pParams->nBRefType = MFX_B_REF_OFF;
610 }
611 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-idr_interval")))
612 {
613 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
614 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nIdrInterval))
615 {
616 PrintHelp(strInput[0], MSDK_STRING("IdrInterval is invalid"));
617 return MFX_ERR_UNSUPPORTED;
618 }
619 }
620 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-msb10")))
621 {
622 pParams->IsSourceMSB = true;
623 }
624 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-angle")))
625 {
626 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
627 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nRotationAngle))
628 {
629 PrintHelp(strInput[0], MSDK_STRING("Rotation Angle is invalid"));
630 return MFX_ERR_UNSUPPORTED;
631 }
632 }
633 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-opencl")))
634 {
635 msdk_opt_read(MSDK_OCL_ROTATE_PLUGIN, pParams->strPluginDLLPath);
636 pParams->nRotationAngle = 180;
637 }
638 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-viewoutput")))
639 {
640 if (!(MVC_ENABLED & pParams->MVC_flags))
641 {
642 PrintHelp(strInput[0], MSDK_STRING("-viewoutput option is supported only when mvc codec specified"));
643 return MFX_ERR_UNSUPPORTED;
644 }
645 pParams->MVC_flags |= MVC_VIEWOUTPUT;
646 }
647 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-la")))
648 {
649 if (!pParams->nRateControlMethod)
650 {
651 pParams->nRateControlMethod = MFX_RATECONTROL_LA;
652 }
653 else if (pParams->nRateControlMethod == MFX_RATECONTROL_ICQ)
654 {
655 pParams->nRateControlMethod = MFX_RATECONTROL_LA_ICQ;
656 }
657 else if (pParams->nRateControlMethod != MFX_RATECONTROL_LA &&
658 pParams->nRateControlMethod != MFX_RATECONTROL_LA_ICQ)
659 {
660 PrintHelp(strInput[0], MSDK_STRING("More than one BRC modes assigned, and another BRC mode isn't compatible with LA."));
661 return MFX_ERR_UNSUPPORTED;
662 }
663 }
664 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-lad")))
665 {
666 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
667 if (!pParams->nRateControlMethod)
668 {
669 pParams->nRateControlMethod = MFX_RATECONTROL_LA;
670 }
671 else if (pParams->nRateControlMethod == MFX_RATECONTROL_ICQ)
672 {
673 pParams->nRateControlMethod = MFX_RATECONTROL_LA_ICQ;
674 }
675 else if (pParams->nRateControlMethod != MFX_RATECONTROL_LA &&
676 pParams->nRateControlMethod != MFX_RATECONTROL_LA_ICQ &&
677 pParams->nRateControlMethod != MFX_RATECONTROL_LA_EXT)
678 {
679 PrintHelp(strInput[0], MSDK_STRING("More than one BRC modes assigned, and another BRC mode isn't compatible with LA."));
680 return MFX_ERR_UNSUPPORTED;
681 }
682
683 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nLADepth))
684 {
685 PrintHelp(strInput[0], MSDK_STRING("Look Ahead Depth is invalid"));
686 return MFX_ERR_UNSUPPORTED;
687 }
688 }
689 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-vbr")))
690 {
691 pParams->nRateControlMethod = MFX_RATECONTROL_VBR;
692 }
693 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-cbr")))
694 {
695 pParams->nRateControlMethod = MFX_RATECONTROL_CBR;
696 }
697 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-single_texture_d3d11")))
698 {
699 pParams->bSingleTexture = true;
700 }
701 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-qvbr")))
702 {
703 pParams->nRateControlMethod = MFX_RATECONTROL_QVBR;
704 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
705
706 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->QVBRQuality))
707 {
708 PrintHelp(strInput[0], MSDK_STRING("QVBRQuality param is invalid"));
709 return MFX_ERR_UNSUPPORTED;
710 }
711 }
712 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-avbr")))
713 {
714 pParams->nRateControlMethod = MFX_RATECONTROL_AVBR;
715 }
716 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-convergence")))
717 {
718 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
719 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->Convergence))
720 {
721 PrintHelp(strInput[0], MSDK_STRING("convergence is invalid"));
722 return MFX_ERR_UNSUPPORTED;
723 }
724 }
725 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-accuracy")))
726 {
727 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
728 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->Accuracy))
729 {
730 PrintHelp(strInput[0], MSDK_STRING("accuracy is invalid"));
731 return MFX_ERR_UNSUPPORTED;
732 }
733 }
734 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-mss")))
735 {
736 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
737 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nMaxSliceSize))
738 {
739 PrintHelp(strInput[0], MSDK_STRING("MaxSliceSize is invalid"));
740 return MFX_ERR_UNSUPPORTED;
741 }
742 }
743 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-mfs")))
744 {
745 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
746 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nMaxFrameSize))
747 {
748 PrintHelp(strInput[0], MSDK_STRING("MaxFrameSize is invalid"));
749 return MFX_ERR_UNSUPPORTED;
750 }
751 }
752 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-BitrateLimit:on")))
753 {
754 pParams->BitrateLimit = MFX_CODINGOPTION_ON;
755 }
756 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-BitrateLimit:off")))
757 {
758 pParams->BitrateLimit = MFX_CODINGOPTION_OFF;
759 }
760 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-qpfile")))
761 {
762 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
763 MSDK_CHECK_ERROR(msdk_strlen(strInput[i+1]), 0, MFX_ERR_NOT_INITIALIZED);
764 pParams->QPFileMode = true;
765 pParams->strQPFilePath = strInput[++i];
766 }
767 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-sys")))
768 {
769 pParams->memType = SYSTEM_MEMORY;
770 }
771 #if D3D_SURFACES_SUPPORT
772 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-d3d")))
773 {
774 pParams->memType = D3D9_MEMORY;
775 }
776 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-d3d11")))
777 {
778 pParams->memType = D3D11_MEMORY;
779 }
780 #endif
781 #ifdef LIBVA_SUPPORT
782 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-vaapi")))
783 {
784 pParams->memType = VAAPI_MEMORY;
785 }
786 #endif
787 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-async")))
788 {
789 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
790
791 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nAsyncDepth))
792 {
793 PrintHelp(strInput[0], MSDK_STRING("Async Depth is invalid"));
794 return MFX_ERR_UNSUPPORTED;
795 }
796 }
797 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-CodecLevel")))
798 {
799 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
800 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->CodecLevel))
801 {
802 PrintHelp(strInput[0], MSDK_STRING("CodecLevel is invalid"));
803 return MFX_ERR_UNSUPPORTED;
804 }
805 }
806 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-CodecProfile")))
807 {
808 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
809 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->CodecProfile))
810 {
811 PrintHelp(strInput[0], MSDK_STRING("CodecProfile is invalid"));
812 return MFX_ERR_UNSUPPORTED;
813 }
814 }
815 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-GopOptFlag:closed")))
816 {
817 pParams->GopOptFlag = MFX_GOP_CLOSED;
818 }
819 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-GopOptFlag:strict")))
820 {
821 pParams->GopOptFlag = MFX_GOP_STRICT;
822 }
823 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-AdaptiveI:on")))
824 {
825 pParams->AdaptiveI = MFX_CODINGOPTION_ON;
826 }
827 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-AdaptiveI:off")))
828 {
829 pParams->AdaptiveI = MFX_CODINGOPTION_OFF;
830 }
831 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-AdaptiveB:on")))
832 {
833 pParams->AdaptiveB = MFX_CODINGOPTION_ON;
834 }
835 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-AdaptiveB:off")))
836 {
837 pParams->AdaptiveB = MFX_CODINGOPTION_OFF;
838 }
839 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-InitialDelayInKB")))
840 {
841 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
842 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->InitialDelayInKB))
843 {
844 PrintHelp(strInput[0], MSDK_STRING("InitialDelayInKB is invalid"));
845 return MFX_ERR_UNSUPPORTED;
846 }
847 }
848 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-MaxKbps")))
849 {
850 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
851 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->MaxKbps))
852 {
853 PrintHelp(strInput[0], MSDK_STRING("MaxKbps is invalid"));
854 return MFX_ERR_UNSUPPORTED;
855 }
856 }
857 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-LowDelayBRC")))
858 {
859 pParams->LowDelayBRC = MFX_CODINGOPTION_ON;
860 }
861 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-BufferSizeInKB")))
862 {
863 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
864 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->BufferSizeInKB))
865 {
866 PrintHelp(strInput[0], MSDK_STRING("BufferSizeInKB is invalid"));
867 return MFX_ERR_UNSUPPORTED;
868 }
869 }
870 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ws")))
871 {
872 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
873 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->WinBRCSize))
874 {
875 PrintHelp(strInput[0], MSDK_STRING("Sliding window size is invalid"));
876 return MFX_ERR_UNSUPPORTED;
877 }
878 }
879 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-wb")))
880 {
881 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
882 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->WinBRCMaxAvgKbps))
883 {
884 PrintHelp(strInput[0], MSDK_STRING("Sliding window bitrate is invalid"));
885 return MFX_ERR_UNSUPPORTED;
886 }
887 }
888 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-timeout")))
889 {
890 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
891
892 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nTimeout))
893 {
894 PrintHelp(strInput[0], MSDK_STRING("Timeout is invalid"));
895 return MFX_ERR_UNSUPPORTED;
896 }
897 }
898 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-signal:tm")))
899 {
900 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
901
902 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->TransferMatrix))
903 {
904 PrintHelp(strInput[0], MSDK_STRING("Transfer matrix param is invalid"));
905 return MFX_ERR_UNSUPPORTED;
906 }
907 }
908 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ir_type")))
909 {
910 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
911
912 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->IntRefType))
913 {
914 PrintHelp(strInput[0], MSDK_STRING("Intra refresh type is invalid"));
915 return MFX_ERR_UNSUPPORTED;
916 }
917 }
918 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ir_cycle_size")))
919 {
920 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
921
922 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->IntRefCycleSize))
923 {
924 PrintHelp(strInput[0], MSDK_STRING("IR refresh cycle size param is invalid"));
925 return MFX_ERR_UNSUPPORTED;
926 }
927 }
928 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ir_qp_delta")))
929 {
930 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
931
932 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->IntRefQPDelta))
933 {
934 PrintHelp(strInput[0], MSDK_STRING("IR QP delta param is invalid"));
935 return MFX_ERR_UNSUPPORTED;
936 }
937 }
938 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ir_cycle_dist")))
939 {
940 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
941
942 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->IntRefCycleDist))
943 {
944 PrintHelp(strInput[0], MSDK_STRING("IR cycle distance param is invalid"));
945 return MFX_ERR_UNSUPPORTED;
946 }
947 }
948 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-perf_opt")))
949 {
950 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
951
952 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nPerfOpt))
953 {
954 PrintHelp(strInput[0], MSDK_STRING("perf_opt is invalid"));
955 return MFX_ERR_UNSUPPORTED;
956 }
957 }
958 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-WeightedPred:default")))
959 {
960 pParams->WeightedPred = MFX_WEIGHTED_PRED_DEFAULT;
961 }
962 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-WeightedPred:implicit")))
963 {
964 pParams->WeightedPred = MFX_WEIGHTED_PRED_IMPLICIT;
965 }
966 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-WeightedBiPred:default")))
967 {
968 pParams->WeightedBiPred = MFX_WEIGHTED_PRED_DEFAULT;
969 }
970 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-WeightedBiPred:implicit")))
971 {
972 pParams->WeightedBiPred = MFX_WEIGHTED_PRED_IMPLICIT;
973 }
974 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-uncut")))
975 {
976 pParams->bUncut = true;
977 }
978 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-gpucopy::on")))
979 {
980 pParams->gpuCopy = MFX_GPUCOPY_ON;
981 }
982 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-gpucopy::off")))
983 {
984 pParams->gpuCopy = MFX_GPUCOPY_OFF;
985 }
986 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-dump")))
987 {
988 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
989 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->DumpFileName))
990 {
991 PrintHelp(strInput[0], MSDK_STRING("File Name for dumping MSDK library configuration should be provided"));
992 return MFX_ERR_UNSUPPORTED;
993 }
994 }
995 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-usei")))
996 {
997 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
998 if (msdk_strlen(strInput[i + 1]) > MSDK_MAX_USER_DATA_UNREG_SEI_LEN)
999 {
1000 PrintHelp(strInput[0], MSDK_STRING("error: '-usei' arguments is too long\n"));
1001 return MFX_ERR_UNSUPPORTED;
1002 }
1003 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->uSEI))
1004 {
1005 PrintHelp(strInput[0], MSDK_STRING("error: option '-usei' expects arguments\n"));
1006 return MFX_ERR_UNSUPPORTED;
1007 }
1008 if (msdk_strlen(pParams->uSEI) < 32)
1009 {
1010 PrintHelp(strInput[0], MSDK_STRING("error: option '-usei' expects at least 32 char uuid\n"));
1011 return MFX_ERR_UNSUPPORTED;
1012 }
1013 }
1014 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-icq")))
1015 {
1016 if (!pParams->nRateControlMethod)
1017 {
1018 pParams->nRateControlMethod = MFX_RATECONTROL_ICQ;
1019 }
1020 else if (pParams->nRateControlMethod == MFX_RATECONTROL_LA)
1021 {
1022 pParams->nRateControlMethod = MFX_RATECONTROL_LA_ICQ;
1023 }
1024 else
1025 {
1026 PrintHelp(strInput[0], MSDK_STRING("More than one BRC modes assigned, and another BRC mode isn't compatible with ICQ.\n"));
1027 return MFX_ERR_UNSUPPORTED;
1028 }
1029
1030 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1031 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->ICQQuality))
1032 {
1033 PrintHelp(strInput[0], MSDK_STRING("ICQQuality is invalid"));
1034 return MFX_ERR_UNSUPPORTED;
1035 }
1036 }
1037 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-cqp")))
1038 {
1039 pParams->nRateControlMethod = MFX_RATECONTROL_CQP;
1040 }
1041 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-qpi")))
1042 {
1043 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1044 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nQPI))
1045 {
1046 PrintHelp(strInput[0], MSDK_STRING("Quantizer for I frames is invalid"));
1047 return MFX_ERR_UNSUPPORTED;
1048 }
1049 }
1050 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-qpp")))
1051 {
1052 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1053 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nQPP))
1054 {
1055 PrintHelp(strInput[0], MSDK_STRING("Quantizer for P frames is invalid"));
1056 return MFX_ERR_UNSUPPORTED;
1057 }
1058 }
1059 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-qpb")))
1060 {
1061 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1062 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nQPB))
1063 {
1064 PrintHelp(strInput[0], MSDK_STRING("Quantizer for B frames is invalid"));
1065 return MFX_ERR_UNSUPPORTED;
1066 }
1067 }
1068 #if (MFX_VERSION >= 1027)
1069 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-round_offset_in")))
1070 {
1071 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1072 pParams->RoundingOffsetFile = strInput[++i];
1073 }
1074 #endif
1075 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-gpb:on")))
1076 {
1077 pParams->nGPB = MFX_CODINGOPTION_ON;
1078 }
1079 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-gpb:off")))
1080 {
1081 pParams->nGPB = MFX_CODINGOPTION_OFF;
1082 }
1083 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-TransformSkip:on")))
1084 {
1085 pParams->nTransformSkip = MFX_CODINGOPTION_ON;
1086 }
1087 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-TransformSkip:off")))
1088 {
1089 pParams->nTransformSkip = MFX_CODINGOPTION_OFF;
1090 }
1091 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ppyr:on")))
1092 {
1093 pParams->nPRefType = MFX_P_REF_PYRAMID;
1094 }
1095 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ppyr:off")))
1096 {
1097 pParams->nPRefType = MFX_P_REF_SIMPLE;
1098 }
1099 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-num_active_P")))
1100 {
1101 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1102 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nNumRefActiveP))
1103 {
1104 PrintHelp(strInput[0], MSDK_STRING("Number of active reference for P frames is invalid"));
1105 return MFX_ERR_UNSUPPORTED;
1106 }
1107 }
1108 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-num_active_BL0")))
1109 {
1110 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1111 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nNumRefActiveBL0))
1112 {
1113 PrintHelp(strInput[0], MSDK_STRING("Number of active reference for B frames (L0) is invalid"));
1114 return MFX_ERR_UNSUPPORTED;
1115 }
1116 }
1117 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-num_active_BL1")))
1118 {
1119 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1120 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nNumRefActiveBL1))
1121 {
1122 PrintHelp(strInput[0], MSDK_STRING("Number of active reference for B frames (L1) is invalid"));
1123 return MFX_ERR_UNSUPPORTED;
1124 }
1125 }
1126 #if (MFX_VERSION >= 1024)
1127 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-extbrc:on")))
1128 {
1129 pParams->nExtBRC= EXTBRC_ON;
1130 }
1131 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-extbrc:off")))
1132 {
1133 pParams->nExtBRC = EXTBRC_OFF;
1134 }
1135 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-extbrc:implicit")))
1136 {
1137 pParams->nExtBRC = EXTBRC_IMPLICIT;
1138 }
1139 #endif
1140 #if (MFX_VERSION >= 1026)
1141 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ExtBrcAdaptiveLTR:on")))
1142 {
1143 pParams->ExtBrcAdaptiveLTR = MFX_CODINGOPTION_ON;
1144 }
1145 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-ExtBrcAdaptiveLTR:off")))
1146 {
1147 pParams->ExtBrcAdaptiveLTR = MFX_CODINGOPTION_OFF;;
1148 }
1149 #endif
1150 #if (MFX_VERSION >= MFX_VERSION_NEXT)
1151 else if(0 == msdk_strcmp(strInput[i], MSDK_STRING("-dblk_alpha")))
1152 {
1153 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1154 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->DeblockingAlphaTcOffset))
1155 {
1156 PrintHelp(strInput[0], MSDK_STRING("Alpha deblocking parameter is invalid"));
1157 return MFX_ERR_UNSUPPORTED;
1158 }
1159 }
1160 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-dblk_beta")))
1161 {
1162 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1163 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->DeblockingBetaOffset))
1164 {
1165 PrintHelp(strInput[0], MSDK_STRING("Beta deblocking parameter is invalid"));
1166 return MFX_ERR_UNSUPPORTED;
1167 }
1168 }
1169 #endif
1170 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-pp")))
1171 {
1172 pParams->shouldPrintPresets = true;
1173 }
1174 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-preset")))
1175 {
1176 msdk_char presetName[MSDK_MAX_FILENAME_LEN];
1177 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1178 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], presetName))
1179 {
1180 PrintHelp(strInput[0], MSDK_STRING("Preset Name is not defined"));
1181 return MFX_ERR_UNSUPPORTED;
1182 }
1183
1184 pParams->PresetMode = CPresetManager::PresetNameToMode(presetName);
1185 if (pParams->PresetMode == PRESET_MAX_MODES)
1186 {
1187 PrintHelp(strInput[0], MSDK_STRING("Preset Name is invalid"));
1188 return MFX_ERR_UNSUPPORTED;
1189 }
1190 }
1191 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-amfs:on")))
1192 {
1193 pParams->nAdaptiveMaxFrameSize = MFX_CODINGOPTION_ON;
1194 }
1195 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-amfs:off")))
1196 {
1197 pParams->nAdaptiveMaxFrameSize = MFX_CODINGOPTION_OFF;
1198 }
1199 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-qsv-ff")))
1200 {
1201 pParams->enableQSVFF=true;
1202 }
1203 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-lowpower:on")))
1204 {
1205 pParams->enableQSVFF=true;
1206 }
1207 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-lowpower:off")))
1208 {
1209 pParams->enableQSVFF=false;
1210 }
1211 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-robust:soft")))
1212 {
1213 pParams->bSoftRobustFlag = true;
1214 }
1215 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-num_slice")))
1216 {
1217 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1218 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nNumSlice))
1219 {
1220 PrintHelp(strInput[0], MSDK_STRING("Number of slices is invalid"));
1221 return MFX_ERR_UNSUPPORTED;
1222 }
1223 }
1224 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-n")))
1225 {
1226
1227 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1228 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nNumFrames))
1229 {
1230 PrintHelp(strInput[0], MSDK_STRING("Number of frames is invalid"));
1231 return MFX_ERR_UNSUPPORTED;
1232 }
1233 }
1234 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-w")))
1235 {
1236
1237 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1238 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nWidth))
1239 {
1240 PrintHelp(strInput[0], MSDK_STRING("Width is invalid"));
1241 return MFX_ERR_UNSUPPORTED;
1242 }
1243 }
1244 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-h")))
1245 {
1246
1247 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1248 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nHeight))
1249 {
1250 PrintHelp(strInput[0], MSDK_STRING("Height of frames is invalid"));
1251 return MFX_ERR_UNSUPPORTED;
1252 }
1253 }
1254 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-b")))
1255 {
1256
1257 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1258 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nBitRate))
1259 {
1260 PrintHelp(strInput[0], MSDK_STRING("Bitrate is invalid"));
1261 return MFX_ERR_UNSUPPORTED;
1262 }
1263 }
1264 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-f")))
1265 {
1266
1267 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1268 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->dFrameRate))
1269 {
1270 PrintHelp(strInput[0], MSDK_STRING("Framerate is invalid"));
1271 return MFX_ERR_UNSUPPORTED;
1272 }
1273 }
1274 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-x")))
1275 {
1276
1277 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1278 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nNumRefFrame))
1279 {
1280 PrintHelp(strInput[0], MSDK_STRING("NumRefFrames is invalid"));
1281 return MFX_ERR_UNSUPPORTED;
1282 }
1283 }
1284 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-g")))
1285 {
1286
1287 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1288 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nGopPicSize))
1289 {
1290 PrintHelp(strInput[0], MSDK_STRING("GopSize is invalid"));
1291 return MFX_ERR_UNSUPPORTED;
1292 }
1293 }
1294 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-r")))
1295 {
1296 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1297 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nGopRefDist))
1298 {
1299 PrintHelp(strInput[0], MSDK_STRING("GopRefDist is invalid"));
1300 return MFX_ERR_UNSUPPORTED;
1301 }
1302 }
1303 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-i")))
1304 {
1305 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1306 pParams->InputFiles.push_back(strInput[++i]);
1307
1308 }
1309 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-o")))
1310 {
1311 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1312 pParams->dstFileBuff.push_back(strInput[++i]);
1313 }
1314 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-p")))
1315 {
1316 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1317 pParams->pluginParams = ParsePluginGuid(strInput[++i]);
1318 if (AreGuidsEqual(pParams->pluginParams.pluginGuid, MSDK_PLUGINGUID_NULL))
1319 {
1320 msdk_printf(MSDK_STRING("error: invalid encoder guid\n"));
1321 return MFX_ERR_UNSUPPORTED;
1322 }
1323 }
1324 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-q")))
1325 {
1326 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1327 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nQuality))
1328 {
1329 PrintHelp(strInput[0], MSDK_STRING("Quality is invalid"));
1330 return MFX_ERR_UNSUPPORTED;
1331 }
1332 }
1333 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-?")))
1334 {
1335 PrintHelp(strInput[0], NULL);
1336 return MFX_ERR_UNSUPPORTED;
1337 }
1338 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-path")))
1339 {
1340 VAL_CHECK(i + 1 >= nArgNum, i, strInput[i]);
1341 i++;
1342 pParams->pluginParams = ParsePluginPath(strInput[i]);
1343 }
1344 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-re")))
1345 {
1346 pParams->UseRegionEncode = true;
1347 }
1348 #if defined (ENABLE_V4L2_SUPPORT)
1349 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-d")))
1350 {
1351 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1352 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->DeviceName))
1353 {
1354 PrintHelp(strInput[0], MSDK_STRING("Device name is invalid"));
1355 return MFX_ERR_UNSUPPORTED;
1356 }
1357 }
1358 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-YUY2")))
1359 {
1360 pParams->v4l2Format = YUY2;
1361 }
1362 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-UYVY")))
1363 {
1364 pParams->v4l2Format = UYVY;
1365
1366 }
1367 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-p")))
1368 {
1369 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1370 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->MipiPort))
1371 {
1372 PrintHelp(strInput[0], MSDK_STRING("Mipi-port is invalid"));
1373 return MFX_ERR_UNSUPPORTED;
1374 }
1375 }
1376 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-m")))
1377 {
1378 VAL_CHECK(i+1 >= nArgNum, i, strInput[i]);
1379 if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->MipiModeName))
1380 {
1381 PrintHelp(strInput[0], MSDK_STRING("Device name is invalid"));
1382 return MFX_ERR_UNSUPPORTED;
1383 }
1384
1385 if(strcasecmp(pParams->MipiModeName,"STILL") == 0)
1386 pParams->MipiMode = STILL;
1387 else if(strcasecmp(pParams->MipiModeName,"VIDEO") == 0)
1388 pParams->MipiMode = VIDEO;
1389 else if(strcasecmp(pParams->MipiModeName,"PREVIEW") == 0)
1390 pParams->MipiMode = PREVIEW;
1391 else if(strcasecmp(pParams->MipiModeName,"CONTINUOUS") == 0)
1392 pParams->MipiMode = CONTINUOUS;
1393 else
1394 pParams->MipiMode = NONE;
1395 }
1396 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-i::v4l2")))
1397 {
1398 pParams->isV4L2InputEnabled = true;
1399 }
1400 #endif
1401 else
1402 {
1403 mfxStatus sts = ParseAdditionalParams(strInput, nArgNum, i, pParams);
1404 if (sts < MFX_ERR_NONE)
1405 {
1406 msdk_printf(MSDK_STRING("Unknown option: %s\n"), strInput[i]);
1407 PrintHelp(strInput[0], NULL);
1408 return MFX_ERR_UNSUPPORTED;
1409 }
1410 }
1411 }
1412
1413 if(!pParams->memType) {
1414 pParams->memType = pParams->bUseHWLib ?
1415 #if defined(_WIN32) || defined(_WIN64)
1416 D3D11_MEMORY
1417 #else
1418 VAAPI_MEMORY
1419 #endif
1420 : SYSTEM_MEMORY;
1421 }
1422
1423 #if defined (ENABLE_V4L2_SUPPORT)
1424 if (pParams->isV4L2InputEnabled)
1425 {
1426 if (0 == msdk_strlen(pParams->DeviceName))
1427 {
1428 PrintHelp(strInput[0], MSDK_STRING("Device Name not found"));
1429 return MFX_ERR_UNSUPPORTED;
1430 }
1431
1432 if ((pParams->MipiPort > -1 && pParams->MipiMode == NONE) ||
1433 (pParams->MipiPort < 0 && pParams->MipiMode != NONE))
1434 {
1435 PrintHelp(strInput[0], MSDK_STRING("Invalid Mipi Configuration\n"));
1436 return MFX_ERR_UNSUPPORTED;
1437 }
1438
1439 if (pParams->v4l2Format == NO_FORMAT)
1440 {
1441 PrintHelp(strInput[0], MSDK_STRING("NO input v4l2 format\n"));
1442 return MFX_ERR_UNSUPPORTED;
1443 }
1444 }
1445 #endif
1446
1447 // check if all mandatory parameters were set
1448 if (!pParams->InputFiles.size() && !pParams->isV4L2InputEnabled)
1449 {
1450 PrintHelp(strInput[0], MSDK_STRING("Source file name not found"));
1451 return MFX_ERR_UNSUPPORTED;
1452 };
1453
1454
1455 if (0 == pParams->nWidth || 0 == pParams->nHeight)
1456 {
1457 PrintHelp(strInput[0], MSDK_STRING("-w, -h must be specified"));
1458 return MFX_ERR_UNSUPPORTED;
1459 }
1460
1461 if (MFX_CODEC_MPEG2 != pParams->CodecId &&
1462 MFX_CODEC_AVC != pParams->CodecId &&
1463 MFX_CODEC_JPEG != pParams->CodecId &&
1464 MFX_CODEC_HEVC != pParams->CodecId &&
1465 MFX_CODEC_VP9 != pParams->CodecId)
1466 {
1467 PrintHelp(strInput[0], MSDK_STRING("Unknown codec"));
1468 return MFX_ERR_UNSUPPORTED;
1469 }
1470
1471 if (!pParams->EncodeFourCC)
1472 {
1473 if (pParams->FileInputFourCC == MFX_FOURCC_UYVY)
1474 // use YUY2 to get chroma subsampling 4:2:2 in encoded image
1475 pParams->EncodeFourCC = MFX_FOURCC_YUY2;
1476 else if (pParams->FileInputFourCC == MFX_FOURCC_I420)
1477 pParams->EncodeFourCC = MFX_FOURCC_NV12;
1478 else
1479 pParams->EncodeFourCC = pParams->FileInputFourCC;
1480 }
1481
1482 if (MFX_CODEC_JPEG != pParams->CodecId && MFX_CODEC_HEVC != pParams->CodecId &&
1483 pParams->EncodeFourCC == MFX_FOURCC_YUY2 &&
1484 !pParams->isV4L2InputEnabled)
1485 {
1486 PrintHelp(strInput[0], MSDK_STRING("-yuy2 option is supported only for JPEG or HEVC encoder"));
1487 return MFX_ERR_UNSUPPORTED;
1488 }
1489
1490 if (MFX_CODEC_HEVC != pParams->CodecId && MFX_CODEC_VP9 != pParams->CodecId && (pParams->EncodeFourCC == MFX_FOURCC_P010) )
1491 {
1492 PrintHelp(strInput[0], MSDK_STRING("P010 surfaces are supported only for HEVC and VP9 encoder"));
1493 return MFX_ERR_UNSUPPORTED;
1494 }
1495
1496 // check parameters validity
1497 if (pParams->nRotationAngle != 0 && pParams->nRotationAngle != 180)
1498 {
1499 PrintHelp(strInput[0], MSDK_STRING("Angles other than 180 degrees are not supported."));
1500 return MFX_ERR_UNSUPPORTED; // other than 180 are not supported
1501 }
1502
1503 if (pParams->nQuality && (MFX_CODEC_JPEG != pParams->CodecId))
1504 {
1505 PrintHelp(strInput[0], MSDK_STRING("-q option is supported only for JPEG encoder"));
1506 return MFX_ERR_UNSUPPORTED;
1507 }
1508
1509 if ((pParams->nTargetUsage || pParams->nBitRate) && (MFX_CODEC_JPEG == pParams->CodecId))
1510 {
1511 PrintHelp(strInput[0], MSDK_STRING("-u and -b options are supported only for H.264, MPEG2 and MVC encoders. For JPEG encoder use -q"));
1512 return MFX_ERR_UNSUPPORTED;
1513 }
1514
1515 if (!pParams->nQuality && (MFX_CODEC_JPEG == pParams->CodecId))
1516 {
1517 PrintHelp(strInput[0], MSDK_STRING("-q must be specified for JPEG encoder"));
1518 return MFX_ERR_UNSUPPORTED;
1519 }
1520
1521 if (MFX_TRANSFERMATRIX_UNKNOWN != pParams->TransferMatrix &&
1522 MFX_TRANSFERMATRIX_BT601 != pParams->TransferMatrix &&
1523 MFX_TRANSFERMATRIX_BT709 != pParams->TransferMatrix)
1524 {
1525 PrintHelp(strInput[0], MSDK_STRING("Invalid transfer matrix type"));
1526 return MFX_ERR_UNSUPPORTED;
1527 }
1528
1529 // set default values for optional parameters that were not set or were set incorrectly
1530 mfxU32 nviews = (mfxU32)pParams->InputFiles.size();
1531 if ((nviews <= 1) || (nviews > 2))
1532 {
1533 if (!(MVC_ENABLED & pParams->MVC_flags))
1534 {
1535 pParams->numViews = 1;
1536 }
1537 else
1538 {
1539 PrintHelp(strInput[0], MSDK_STRING("Only 2 views are supported right now in this sample."));
1540 return MFX_ERR_UNSUPPORTED;
1541 }
1542 }
1543 else
1544 {
1545 pParams->numViews = nviews;
1546 }
1547
1548 if (pParams->dFrameRate <= 0)
1549 {
1550 pParams->dFrameRate = 30;
1551 }
1552
1553 // if no destination picture width or height wasn't specified set it to the source picture size
1554 if (pParams->nDstWidth == 0)
1555 {
1556 pParams->nDstWidth = pParams->nWidth;
1557 }
1558
1559 if (pParams->nDstHeight == 0)
1560 {
1561 pParams->nDstHeight = pParams->nHeight;
1562 }
1563
1564 if (!pParams->nPicStruct)
1565 {
1566 pParams->nPicStruct = MFX_PICSTRUCT_PROGRESSIVE;
1567 }
1568
1569 if ((pParams->nRateControlMethod == MFX_RATECONTROL_LA) && (!pParams->bUseHWLib))
1570 {
1571 PrintHelp(strInput[0], MSDK_STRING("Look ahead BRC is supported only with -hw option!"));
1572 return MFX_ERR_UNSUPPORTED;
1573 }
1574
1575 if ((pParams->nMaxSliceSize) && (!pParams->bUseHWLib))
1576 {
1577 PrintHelp(strInput[0], MSDK_STRING("MaxSliceSize option is supported only with -hw option!"));
1578 return MFX_ERR_UNSUPPORTED;
1579 }
1580
1581 if ((pParams->nMaxSliceSize) && (pParams->nNumSlice))
1582 {
1583 PrintHelp(strInput[0], MSDK_STRING("-mss and -num_slice options are not compatible!"));
1584 return MFX_ERR_UNSUPPORTED;
1585 }
1586
1587 if (pParams->nRateControlMethod == MFX_RATECONTROL_LA &&
1588 pParams->CodecId == MFX_CODEC_HEVC)
1589 {
1590 pParams->bEnableExtLA = true;
1591 pParams->nRateControlMethod = MFX_RATECONTROL_LA_EXT;
1592 }
1593
1594 if ((pParams->nMaxSliceSize) && (pParams->CodecId != MFX_CODEC_AVC) && (pParams->CodecId != MFX_CODEC_HEVC))
1595 {
1596 PrintHelp(strInput[0], MSDK_STRING("MaxSliceSize option is supported only with H.264 and H.265(HEVC) encoder!"));
1597 return MFX_ERR_UNSUPPORTED;
1598 }
1599
1600 if ( (pParams->nRateControlMethod == MFX_RATECONTROL_LA ||
1601 pParams->nRateControlMethod == MFX_RATECONTROL_LA_EXT ||
1602 pParams->nRateControlMethod == MFX_RATECONTROL_LA_ICQ ||
1603 pParams->nRateControlMethod == MFX_RATECONTROL_LA_HRD) &&
1604 pParams->nLADepth > 100 )
1605 {
1606 PrintHelp(strInput[0], MSDK_STRING("Unsupported value of -lad parameter, must be in range [1,100] or 0 for automatic selection"));
1607 return MFX_ERR_UNSUPPORTED;
1608 }
1609
1610 if (pParams->nNumRefActiveP || pParams->nNumRefActiveBL0 || pParams->nNumRefActiveBL1)
1611 {
1612 if (pParams->CodecId != MFX_CODEC_HEVC)
1613 {
1614 PrintHelp(strInput[0], MSDK_STRING("NumRefActiveP/BL0/BL1 are supported only with HEVC encoder"));
1615 return MFX_ERR_UNSUPPORTED;
1616 }
1617 }
1618
1619 // not all options are supported if rotate plugin is enabled
1620 if (pParams->nRotationAngle == 180 && (
1621 MFX_PICSTRUCT_PROGRESSIVE != pParams->nPicStruct ||
1622 pParams->nDstWidth != pParams->nWidth ||
1623 pParams->nDstHeight != pParams->nHeight ||
1624 MVC_ENABLED & pParams->MVC_flags ||
1625 pParams->nRateControlMethod == MFX_RATECONTROL_LA))
1626 {
1627 PrintHelp(strInput[0], MSDK_STRING("Some of the command line options are not supported with rotation plugin!"));
1628 return MFX_ERR_UNSUPPORTED;
1629 }
1630
1631 // Ignoring user-defined Async Depth for LA
1632 if (pParams->nMaxSliceSize)
1633 {
1634 pParams->nAsyncDepth = 1;
1635 }
1636
1637 if(pParams->UseRegionEncode)
1638 {
1639 if(pParams->CodecId != MFX_CODEC_HEVC)
1640 {
1641 msdk_printf(MSDK_STRING("Region encode option is compatible with h265(HEVC) encoder only.\nRegion encoding is disabled\n"));
1642 pParams->UseRegionEncode=false;
1643 }
1644 if (pParams->nWidth != pParams->nDstWidth ||
1645 pParams->nHeight != pParams->nDstHeight ||
1646 pParams->nRotationAngle!=0)
1647 {
1648 msdk_printf(MSDK_STRING("Region encode option is not compatible with VPP processing and rotation plugin.\nRegion encoding is disabled\n"));
1649 pParams->UseRegionEncode=false;
1650 }
1651 }
1652
1653 if (pParams->dstFileBuff.size() == 0)
1654 {
1655 msdk_printf(MSDK_STRING("File output is disabled as -o option isn't specified\n"));
1656 }
1657
1658 #if (defined(_WIN64) || defined(_WIN32)) && (MFX_VERSION >= 1031)
1659 if (pParams->bPrefferdGfx && pParams->bPrefferiGfx)
1660 {
1661 msdk_printf(MSDK_STRING("Warning: both dGfx and iGfx flags set. iGfx will be preffered"));
1662 pParams->bPrefferdGfx = false;
1663 }
1664 #endif
1665
1666 mfxU16 mfxU16Limit = std::numeric_limits<mfxU16>::max();
1667 if (pParams->MaxKbps > mfxU16Limit || pParams->nBitRate > mfxU16Limit ||
1668 pParams->InitialDelayInKB > mfxU16Limit || pParams->BufferSizeInKB > mfxU16Limit)
1669 {
1670 mfxU32 maxVal = std::max<mfxU32>({ pParams->MaxKbps,
1671 pParams->nBitRate,
1672 pParams->InitialDelayInKB,
1673 pParams->BufferSizeInKB });
1674 pParams->nBitRateMultiplier = (mfxU16)std::ceil(static_cast<double>(maxVal) / mfxU16Limit);
1675 msdk_printf(MSDK_STRING("WARNING: BitRateMultiplier(-bm) was updated, new value - %d. \n"), pParams->nBitRateMultiplier);
1676
1677 auto recalculate = [mfxU16Limit, pParams] (mfxU32 ¶m, msdk_string paramName)
1678 {
1679 if (param)
1680 {
1681 if (param > mfxU16Limit)
1682 msdk_printf(MSDK_STRING("WARNING: %s (%d) > allow limit (%d). \n"), paramName.c_str(), param, mfxU16Limit);
1683 param = param / pParams->nBitRateMultiplier;
1684 msdk_printf(MSDK_STRING("WARNING: %s was updated, new value: %d. \n"), paramName.c_str(), param);
1685 }
1686 };
1687
1688 recalculate(pParams->MaxKbps, MSDK_STRING("MaxKbps"));
1689 recalculate(pParams->nBitRate, MSDK_STRING("nBitRate(-b)"));
1690 recalculate(pParams->InitialDelayInKB, MSDK_STRING("InitialDelayInKB"));
1691 recalculate(pParams->BufferSizeInKB, MSDK_STRING("BufferSizeInKB"));
1692 }
1693
1694 return MFX_ERR_NONE;
1695 }
1696
ModifyParamsUsingPresets(sInputParams & params)1697 void ModifyParamsUsingPresets(sInputParams& params)
1698 {
1699 COutputPresetParameters presetParams = CPresetManager::Inst.GetPreset(params.PresetMode, params.CodecId,params.dFrameRate, params.nWidth, params.nHeight, params.bUseHWLib);
1700
1701 if (params.shouldPrintPresets)
1702 {
1703 msdk_printf(MSDK_STRING("Preset-controlled parameters (%s):\n"), presetParams.PresetName.c_str());
1704 }
1705 MODIFY_AND_PRINT_PARAM(params.nAdaptiveMaxFrameSize, AdaptiveMaxFrameSize,params.shouldPrintPresets);
1706 MODIFY_AND_PRINT_PARAM(params.nAsyncDepth, AsyncDepth, params.shouldPrintPresets);
1707 MODIFY_AND_PRINT_PARAM(params.nBRefType, BRefType, params.shouldPrintPresets);
1708 // MODIFY_AND_PRINT_PARAM(params., EnableBPyramid);
1709 // MODIFY_AND_PRINT_PARAM(params., EnablePPyramid);
1710 MODIFY_AND_PRINT_PARAM(params.nGopPicSize, GopPicSize, params.shouldPrintPresets);
1711 MODIFY_AND_PRINT_PARAM(params.nGopRefDist, GopRefDist, params.shouldPrintPresets);
1712 MODIFY_AND_PRINT_PARAM(params.IntRefCycleDist, IntRefCycleDist, params.shouldPrintPresets);
1713 MODIFY_AND_PRINT_PARAM(params.IntRefCycleSize, IntRefCycleSize, params.shouldPrintPresets);
1714 MODIFY_AND_PRINT_PARAM(params.IntRefQPDelta, IntRefQPDelta, params.shouldPrintPresets);
1715 MODIFY_AND_PRINT_PARAM(params.IntRefType, IntRefType, params.shouldPrintPresets);
1716 MODIFY_AND_PRINT_PARAM(params.nLADepth, LookAheadDepth, params.shouldPrintPresets);
1717 MODIFY_AND_PRINT_PARAM(params.LowDelayBRC, LowDelayBRC, params.shouldPrintPresets);
1718 MODIFY_AND_PRINT_PARAM(params.nMaxFrameSize, MaxFrameSize, params.shouldPrintPresets);
1719 if (!params.nRateControlMethod)
1720 {
1721 // Use preset ExtBRC parameter only if rate control mode was not set manually
1722 MODIFY_AND_PRINT_PARAM_EXT(params.nExtBRC, ExtBRCUsage, (ExtBRCType)presetParams.ExtBRCUsage, params.shouldPrintPresets);
1723 }
1724 MODIFY_AND_PRINT_PARAM(params.nRateControlMethod, RateControlMethod, params.shouldPrintPresets);
1725
1726 if (params.nRateControlMethod != MFX_RATECONTROL_CQP)
1727 {
1728 MODIFY_AND_PRINT_PARAM(params.nBitRate, TargetKbps, params.shouldPrintPresets);
1729 MODIFY_AND_PRINT_PARAM(params.MaxKbps, MaxKbps, params.shouldPrintPresets);
1730 presetParams.BufferSizeInKB = (mfxU16)params.nBitRate / 8; // Update bitrate to reflect manually set bitrate. BufferSize should be enough for 1 second of video
1731 MODIFY_AND_PRINT_PARAM(params.BufferSizeInKB, BufferSizeInKB, params.shouldPrintPresets);
1732 }
1733
1734 MODIFY_AND_PRINT_PARAM(params.nTargetUsage, TargetUsage, params.shouldPrintPresets);
1735 MODIFY_AND_PRINT_PARAM(params.WeightedBiPred, WeightedBiPred, params.shouldPrintPresets);
1736 MODIFY_AND_PRINT_PARAM(params.WeightedPred, WeightedPred, params.shouldPrintPresets);
1737 if (params.shouldPrintPresets)
1738 {
1739 msdk_printf(MSDK_STRING("\n"));
1740 }
1741 }
1742
CreatePipeline(const sInputParams & params)1743 CEncodingPipeline* CreatePipeline(const sInputParams& params)
1744 {
1745 if(params.UseRegionEncode)
1746 {
1747 return new CRegionEncodingPipeline;
1748 }
1749 else if(params.nRotationAngle)
1750 {
1751 return new CUserPipeline;
1752 }
1753 else
1754 {
1755 return new CEncodingPipeline;
1756 }
1757 }
1758
1759
1760 #if defined(_WIN32) || defined(_WIN64)
_tmain(int argc,msdk_char * argv[])1761 int _tmain(int argc, msdk_char *argv[])
1762 #else
1763 int main(int argc, char *argv[])
1764 #endif
1765 {
1766 sInputParams Params = {}; // input parameters from command line
1767 std::unique_ptr<CEncodingPipeline> pPipeline;
1768
1769 mfxStatus sts = MFX_ERR_NONE; // return value check
1770
1771 // Parsing Input stream workign with presets
1772 sts = ParseInputString(argv, (mfxU8)argc, &Params);
1773 ModifyParamsUsingPresets(Params);
1774
1775 MSDK_CHECK_PARSE_RESULT(sts, MFX_ERR_NONE, 1);
1776
1777 // Choosing which pipeline to use
1778 pPipeline.reset(CreatePipeline(Params));
1779
1780 MSDK_CHECK_POINTER(pPipeline.get(), MFX_ERR_MEMORY_ALLOC);
1781
1782 if (MVC_ENABLED & Params.MVC_flags)
1783 {
1784 pPipeline->SetNumView(Params.numViews);
1785 }
1786
1787 sts = pPipeline->Init(&Params);
1788 MSDK_CHECK_STATUS(sts, "pPipeline->Init failed");
1789
1790 pPipeline->PrintInfo();
1791
1792 msdk_printf(MSDK_STRING("Processing started\n"));
1793
1794 if (pPipeline->CaptureStartV4L2Pipeline() != MFX_ERR_NONE)
1795 {
1796 msdk_printf(MSDK_STRING("V4l2 failure terminating the program\n"));
1797 return 0;
1798 }
1799
1800 for (;;)
1801 {
1802 sts = pPipeline->Run();
1803
1804 if (MFX_ERR_DEVICE_LOST == sts || MFX_ERR_DEVICE_FAILED == sts)
1805 {
1806 msdk_printf(MSDK_STRING("\nERROR: Hardware device was lost or returned an unexpected error. Recovering...\n"));
1807 sts = pPipeline->ResetDevice();
1808 MSDK_CHECK_STATUS(sts, "pPipeline->ResetDevice failed");
1809
1810 sts = pPipeline->ResetMFXComponents(&Params);
1811 MSDK_CHECK_STATUS(sts, "pPipeline->ResetMFXComponents failed");
1812 continue;
1813 }
1814 else
1815 {
1816 MSDK_CHECK_STATUS(sts, "pPipeline->Run failed");
1817 break;
1818 }
1819 }
1820
1821 pPipeline->CaptureStopV4L2Pipeline();
1822
1823 pPipeline->Close();
1824
1825 msdk_printf(MSDK_STRING("\nProcessing finished\n"));
1826
1827 return 0;
1828 }
1829