38 #elif __linux__ || __APPLE__
46 "Multi-threaded video transcoding demo application directly using Netint Libxcoder version %s\n"
47 "Usage: ni_xcoder_multithread_transcode [options]\n"
50 "-h | --help Show this message.\n"
51 "-v | --version Print version info.\n"
52 "-i | --input (Required) Input file path.\n"
53 "-o | --output (Required) Output file path.\n"
54 " Can be specified multiple (max %d) times\n"
55 " to run multiple encoding instances simultaneously.\n"
56 "-m | --dec-codec (Required) Decoder codec format. Must match the codec of input file.\n"
57 " [a|avc, h|hevc, v|vp9]\n"
58 "-n | --enc-codec (Required) Encoder codec format.\n"
59 " [a|avc, h|hevc, x|av1] (x is in ivf container format)\n"
60 "-l | --loglevel Set loglevel of this application and libxcoder API.\n"
61 " [none, fatal, error, info, debug, trace]\n"
63 "-c | --card Set card index to use.\n"
64 " See `ni_rsrc_mon` for info of cards on system.\n"
66 "-r | --repeat To loop input X times. Must be a positive integer\n"
68 "-d | --decoder-params Decoding params. See \"Decoding Parameters\" chapter in\n"
69 " QuadraIntegration&ProgrammingGuide*.pdf for help.\n"
71 "-e | --encoder-params Encoding params. See \"Encoding Parameters\" chapter in\n"
72 " QuadraIntegration&ProgrammingGuide*.pdf for help.\n"
73 " Can be specified multiple (max %d) times,\n"
74 " must match the number of -o specified.\n"
76 "-g | --encoder-gop Custom GOP for encoding. See \"Custom Gop Structure\" chapter in\n"
77 " QuadraIntegration&ProgrammingGuide*.pdf for help.\n"
78 " gopPresetIdx must be set to 0 to be in effect.\n"
80 "-u | --user-data-sei-passthru (No argument) Enable user data unregistered SEI passthrough when specified\n"
81 "-f | --vf Video filter params. The only supported filters in this demo are:\n"
82 " ni_quadra_scale - supported params [width, height, format]\n"
83 " e.g. ni_quadra_scale=width=1280:height=720:format=yuv420p\n"
84 " ni_quadra_drawbox - supported params [x, y, width, height]\n"
85 " e.g. ni_quadra_drawbox=x=300:y=150:width=600:height=400\n"
90 int main(
int argc,
char *argv[])
97 int o_index = 0, e_index = 0, g_index = 0;
99 int input_width = 0, input_height = 0, output_width = 0, output_height = 0, bit_depth = 8;
100 int dec_codec_format = -1, enc_codec_format = -1;
104 char dec_conf_params[2048] = {0};
105 char filter_conf_params[2048] = {0};
108 int user_data_sei_passthru = 0;
121 void *p_stream_info = NULL;
122 int fps_num = 30, fps_den = 1, bitrate = 200000;
128 ni_pthread_t dec_send_tid, dec_recv_tid, enc_send_tid, enc_recv_tid;
137 const char *opt_string =
"hvi:o:m:n:l:c:r:d:e:g:uf:";
138 static struct option long_options[] = {
151 {
"user-data-sei-passthru",
no_argument, NULL,
'u'},
156 while ((opt =
getopt_long(argc, argv, opt_string, long_options, &opt_index)) != -1)
169 strcpy(in_filename,
optarg);
179 for (i = 0; i < o_index; i++)
181 if (0 == strcmp(out_filename[i],
optarg))
189 strcpy(out_filename[o_index],
optarg);
194 for (i = 0; i < strlen(
optarg); i++)
198 if (strcmp(
optarg,
"a") == 0 || strcmp(
optarg,
"avc") == 0)
202 else if (strcmp(
optarg,
"h") == 0 || strcmp(
optarg,
"hevc") == 0)
206 else if (strcmp(
optarg,
"v") == 0 || strcmp(
optarg,
"vp9") == 0)
213 "Must be one of [a|avc, h|hevc, v|vp9]\n",
optarg);
220 for (i = 0; i < strlen(
optarg); i++)
224 if (strcmp(
optarg,
"a") == 0 || strcmp(
optarg,
"avc") == 0)
228 else if (strcmp(
optarg,
"h") == 0 || strcmp(
optarg,
"hevc") == 0)
232 else if (strcmp(
optarg,
"x") == 0 || strcmp(
optarg,
"av1") == 0)
239 "Must be one of [a|avc, h|hevc, x|av1]\n",
optarg);
253 "Must be one of [none, fatal, error, info, debug, trace]\n",
optarg);
259 xcoderGUID = (int)strtol(
optarg, &n, 10);
260 if (n ==
optarg || *n !=
'\0' || xcoderGUID < 0)
263 "Must be a non-negative integer\n",
optarg);
273 "Must be a positive integer\n",
optarg);
279 strcpy(dec_conf_params,
optarg);
288 strcpy(enc_conf_params[e_index],
optarg);
298 strcpy(enc_gop_params[g_index],
optarg);
302 user_data_sei_passthru = 1;
305 strcpy(filter_conf_params,
optarg);
314 if (!in_filename[0]) {
326 if (dec_codec_format == -1) {
332 if (enc_codec_format == -1) {
345 output_total = o_index;
346 for (i = 0; i < output_total; i++)
348 if (strcmp(out_filename[i],
"null") != 0 &&
349 strcmp(out_filename[i],
"/dev/null") != 0)
351 output_fp[i] = fopen(out_filename[i],
"wb");
362 ni_log(
NI_LOG_INFO,
"Note: Requested NULL output for index %d, no output file will be generated\n", i);
367 if (!p_dec_api_param)
375 if (!p_enc_api_param)
388 "ERROR: Failed to probe input file as H.264, file format not supported!\n");
393 input_width = avc_sps.
width;
394 input_height = avc_sps.
height;
396 bit_depth, input_width, input_height);
403 "ERROR: Failed to probe input file as H.265, file format not supported!\n");
407 input_width = (int)(hevc_sps.
width -
410 input_height = (int)(hevc_sps.
height -
413 ni_log(
NI_LOG_INFO,
"Using probed H.265 source info: %d bits, resolution %dx%d\n",
414 bit_depth, input_width, input_height);
421 "ERROR: Failed to probe input file as VP9, file format not supported!\n");
424 bit_depth = vp9_info.
profile ? 10 : 8;
425 input_width = vp9_info.
width;
426 input_height = vp9_info.
height;
428 "Using probed VP9 source info: %d bits, resolution %dx%d, timebase %u/%u\n",
429 bit_depth, input_width, input_height,
474 for (i = 0; i < output_total; i++)
484 for (i = 0; i < output_total; i++)
490 p_stream_info = &avc_sps;
492 p_stream_info = &hevc_sps;
495 p_stream_info = &vp9_info;
500 output_width = input_width;
501 output_height = input_height;
503 if (filter_conf_params[0])
506 ni_log(
NI_LOG_ERROR,
"Error: filters are only supported when hwframe is enabled (out=hw)\n");
513 ni_log(
NI_LOG_ERROR,
"Error: failed to parse filter parameters: %s\n", filter_conf_params);
526 output_width = scale_params.
width;
527 output_height = scale_params.
height;
529 else if (drawbox_params.
enabled)
557 ni_log(
NI_LOG_INFO,
"Starting to transcode: HWFrames %d, video resolution %dx%d -> %dx%d\n",
558 dec_ctx.
hw_action, input_width, input_height, output_width, output_height);
588 "Error: create decoder send thread failed in transcode "
596 "Error: create decoder receive thread failed in "
615 else if (drawbox_params.
enabled)
620 ret =
encoder_open(enc_ctx, p_enc_api_param, output_total, enc_conf_params, enc_gop_params,
621 p_ni_frame, output_width, output_height, fps_num, fps_den, bitrate,
623 xcoderGUID, p_hwframe, 1,
false);
649 "in transcode mode\n");
656 "failed in transcode mode\n");
673 for (i = 0; i < output_total; i++)
676 if (output_fp[i] != NULL)
678 fclose(output_fp[i]);
694 free(p_dec_api_param);
695 free(p_enc_api_param);