 |
libxcoder
5.4.0
|
Go to the documentation of this file.
35 #elif __linux__ || __APPLE__
40 static void print_usage(
void)
43 "Video scaling demo application directly using Netint Libxcoder version %s\n"
44 "Usage: ni_xcoder_scale [options]\n"
47 "-h | --help Show this message.\n"
48 "-v | --version Print version info.\n"
49 "-i | --input (Required) Input file path.\n"
50 "-o | --output (Required) Output file path.\n"
51 " Can be specified multiple (max %d) times\n"
52 " to run multiple scaling instances simultaneously.\n"
53 "-l | --loglevel Set loglevel of this application and libxcoder API.\n"
54 " [none, fatal, error, info, debug, trace]\n"
56 "-c | --card Set card index to use.\n"
57 " See `ni_rsrc_mon` for info of cards on system.\n"
59 "-r | --repeat To loop input X times. Must be a positive integer\n"
61 "-p | --pix_fmt Indicate the pixel format of the input.\n"
62 " [yuv420p, yuv420p10le, nv12, p010le, rgba, bgra, argb, abgr, bgr0]\n"
63 " (Default: yuv420p)\n"
64 "-s | --size (Required) Resolution of input file in format WIDTHxHEIGHT.\n"
65 " (eg. '1920x1080')\n"
66 "-f | --vf Video filter params. The only supported filter in this demo is:\n"
67 " ni_quadra_scale - supported params [width, height, format]\n"
68 " e.g. ni_quadra_scale=width=1280:height=720:format=yuv420p\n"
73 int main(
int argc,
char *argv[])
79 FILE *input_fp = NULL;
81 int o_index = 0, f_index = 0;
83 int input_width = 0, input_height = 0;
87 int chunk_size = 0, eos = 0;
107 const char *opt_string =
"hvi:o:l:c:r:p:s:f:";
108 static struct option long_options[] = {
122 while ((opt =
getopt_long(argc, argv, opt_string, long_options, &opt_index)) != -1)
145 for (i = 0; i < o_index; i++)
147 if (0 == strcmp(out_filename[i],
optarg))
167 "Must be one of [none, fatal, error, info, debug, trace]\n",
optarg);
173 xcoderGUID = (int)strtol(
optarg, &n, 10);
174 if (n ==
optarg || *n !=
'\0' || xcoderGUID < 0)
177 "Must be a non-negative integer\n",
optarg);
187 "Must be a positive integer\n",
optarg);
197 "Must be one of [yuv420p, yuv420p10le, nv12, p010le, rgba, gbra, argb, abgr, bgr0, yuv444p]\n",
204 input_width = (int)strtol(
optarg, &n, 10);
205 input_height =
atoi(n + 1);
206 if ((*n !=
'x') || (input_width <= 0 || input_height <= 0))
209 "Must be in format [WIDTHxHEIGHT] (e.g. 1920x1080)\n",
optarg);
221 ni_strcpy(filter_conf_params[f_index],
sizeof(filter_conf_params[f_index]),
optarg);
231 if (!in_filename[0]) {
250 ni_fopen(&(input_fp), in_filename,
"rb");
262 output_total = o_index;
263 for (i = 0; i < output_total; i++)
265 if (strcmp(out_filename[i],
"null") != 0 &&
266 strcmp(out_filename[i],
"/dev/null") != 0)
269 ni_fopen(&(output_fp[i]), out_filename[i],
"wb");
280 ni_log(
NI_LOG_INFO,
"Note: Requested NULL output for index %d, no output file will be generated\n", i);
284 for (i = 0; i < output_total; i++)
286 output_width[i] = input_width;
287 output_height[i] = input_height;
297 for (i = 0; i < output_total; i++)
299 if (filter_conf_params[i][0])
304 ni_log(
NI_LOG_ERROR,
"Error: failed to parse filter parameters: %s\n", filter_conf_params[i]);
309 if (!scale_params[i].enabled)
323 output_width[i] = scale_params[i].
width;
324 output_height[i] = scale_params[i].
height;
325 bit_depth_factor[i] = 1;
328 bit_depth_factor[i] = 2;
341 for (i = 0; i < output_total; i++)
343 ni_log(
NI_LOG_INFO,
"(Task %d) Starting to scale: video resolution %dx%d -> %dx%d\n",
344 i, input_width, input_height, output_width[i], output_height[i]);
352 chunk_size =
read_yuv_from_file(&ctx, input_fp, yuv_buf, input_width, input_height, pix_fmt,
362 input_height, eos ? NULL : yuv_buf);
371 for (i = 0; i < output_total; i++)
385 p_hwframe->
bit_depth = bit_depth_factor[i];
391 ret =
hwdl_frame(&sca_ctx[i], &download_frame[i], &scaled_frame[i].data.
frame,
400 ret =
write_rawvideo_data(output_fp[i], (output_width[i] * bit_depth_factor[i] + 127) / 128 * 128,
401 (output_height[i] + 1) / 2 * 2, output_width[i], output_height[i],
418 for (i = 0; i < output_total; i++)
426 for (i = 0; i < output_total; i++)
433 for (i = 0; i < output_total; i++)
436 if (output_fp[i] != NULL)
438 fclose(output_fp[i]);
int uploader_open_session(ni_session_context_t *p_upl_ctx, int iXcoderGUID, int width, int height, ni_pix_fmt_t pix_fmt, int is_p2p, int pool_size)
Uploader session open.
int write_rawvideo_data(FILE *p_file, int input_aligned_width, int input_aligned_height, int output_width, int output_height, int format, ni_frame_t *p_out_frame)
Write hwdl data to files.
ni_pix_fmt_t gc620_to_ni_pix_fmt(int pix_fmt)
uint64_t get_total_file_size(FILE *fp)
ni_retcode_t ni_frame_buffer_free(ni_frame_t *p_frame)
Free frame buffer that was previously allocated with either ni_frame_buffer_alloc or ni_encoder_frame...
void ni_hw_frame_ref(const niFrameSurface1_t *p_surface)
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
void ni_hw_frame_unref(uint16_t hwframe_index)
int retrieve_filter_params(char filter_params[], ni_scale_params_t *scale_params, ni_drawbox_params_t *drawbox_params)
ni_pts_queue * enc_pts_queue[MAX_OUTPUT_FILES]
struct timeval current_time
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
uint64_t ni_gettime_ns(void)
#define required_argument
#define NI_XCODER_REVISION
uint64_t curr_file_offset
struct timeval previous_time
ni_log_level_t arg_to_ni_log_level(const char *arg_str)
Convert terminal arg string to ni_log_level_t.
int ni_to_gc620_pix_fmt(ni_pix_fmt_t pix_fmt)
uint64_t num_frames_received
#define MAX_YUV_FRAME_SIZE
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
int getopt_long(int argc, char *argv[], const char *optstring, const struct option *longopts, int *longindex)
@ NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
ni_pix_fmt_t ni_pixel_format_search(const char *name)
void ni_device_session_context_clear(ni_session_context_t *p_ctx)
Clear already allocated session context.
uint8_t * p_data[NI_MAX_NUM_DATA_POINTERS]
union _ni_session_data_io::@19 data
int hwdl_frame(ni_session_context_t *p_ctx, ni_session_data_io_t *p_session_data, ni_frame_t *p_src_frame, int output_format)
Download hw frames by HwDesc.
int read_yuv_from_file(ni_demo_context_t *p_ctx, FILE *pfs, void *yuv_buf, int width, int height, ni_pix_fmt_t pix_fmt, ni_sw_pix_fmt_t sw_pix_fmt, int *eos, ni_session_run_state_t run_state)
int ni_posix_memalign(void **memptr, size_t alignment, size_t size)
Allocate aligned memory.
int scale_filter(ni_session_context_t *p_ctx, ni_frame_t *p_frame_in, ni_session_data_io_t *p_data_out, int iXcoderGUID, int scale_width, int scale_height, int in_format, int out_format)
Do a scale and/or format-change operation.
ni_session_run_state_t session_run_state
#define ni_aligned_free(p_memptr)
ni_retcode_t ni_device_session_context_init(ni_session_context_t *p_ctx)
Initialize already allocated session context to a known state.
int upload_send_data_get_desc(ni_demo_context_t *p_ctx, ni_session_context_t *p_upl_ctx, ni_session_data_io_t *p_swin_data, ni_session_data_io_t *p_in_data, int input_video_width, int input_video_height, void *yuv_buf)
Read from input file, upload to encoder, retrieve HW descriptor.
int main(int argc, char *argv[])
Implementation of getopt() and getopt_long() for Windows environment.
ni_retcode_t ni_device_session_close(ni_session_context_t *p_ctx, int eos_recieved, ni_device_type_t device_type)
Close device session that was previously opened by calling ni_device_session_open() If device_type is...
@ NI_PIXEL_PLANAR_FORMAT_PLANAR
ni_retcode_t ni_fopen(FILE **fp, const char *filename, const char *mode)