24 #include "../tools_common.h" 25 #include "../video_writer.h" 27 #include "../vpx_ports/vpx_timer.h" 28 #include "./svc_context.h" 31 #include "../vpxstats.h" 32 #include "vp9/encoder/vp9_encoder.h" 33 #define OUTPUT_RC_STATS 1 35 static const arg_def_t skip_frames_arg =
36 ARG_DEF(
"s",
"skip-frames", 1,
"input frames to skip");
37 static const arg_def_t frames_arg =
38 ARG_DEF(
"f",
"frames", 1,
"number of frames to encode");
39 static const arg_def_t threads_arg =
40 ARG_DEF(
"th",
"threads", 1,
"number of threads to use");
42 static const arg_def_t output_rc_stats_arg =
43 ARG_DEF(
"rcstat",
"output_rc_stats", 1,
"output rc stats");
45 static const arg_def_t width_arg = ARG_DEF(
"w",
"width", 1,
"source width");
46 static const arg_def_t height_arg = ARG_DEF(
"h",
"height", 1,
"source height");
47 static const arg_def_t timebase_arg =
48 ARG_DEF(
"t",
"timebase", 1,
"timebase (num/den)");
49 static const arg_def_t bitrate_arg = ARG_DEF(
50 "b",
"target-bitrate", 1,
"encoding bitrate, in kilobits per second");
51 static const arg_def_t spatial_layers_arg =
52 ARG_DEF(
"sl",
"spatial-layers", 1,
"number of spatial SVC layers");
53 static const arg_def_t temporal_layers_arg =
54 ARG_DEF(
"tl",
"temporal-layers", 1,
"number of temporal SVC layers");
55 static const arg_def_t temporal_layering_mode_arg =
56 ARG_DEF(
"tlm",
"temporal-layering-mode", 1,
57 "temporal layering scheme." 58 "VP9E_TEMPORAL_LAYERING_MODE");
59 static const arg_def_t kf_dist_arg =
60 ARG_DEF(
"k",
"kf-dist", 1,
"number of frames between keyframes");
61 static const arg_def_t scale_factors_arg =
62 ARG_DEF(
"r",
"scale-factors", 1,
"scale factors (lowest to highest layer)");
63 static const arg_def_t passes_arg =
64 ARG_DEF(
"p",
"passes", 1,
"Number of passes (1/2)");
65 static const arg_def_t pass_arg =
66 ARG_DEF(NULL,
"pass", 1,
"Pass to execute (1/2)");
67 static const arg_def_t fpf_name_arg =
68 ARG_DEF(NULL,
"fpf", 1,
"First pass statistics file name");
69 static const arg_def_t min_q_arg =
70 ARG_DEF(NULL,
"min-q", 1,
"Minimum quantizer");
71 static const arg_def_t max_q_arg =
72 ARG_DEF(NULL,
"max-q", 1,
"Maximum quantizer");
73 static const arg_def_t min_bitrate_arg =
74 ARG_DEF(NULL,
"min-bitrate", 1,
"Minimum bitrate");
75 static const arg_def_t max_bitrate_arg =
76 ARG_DEF(NULL,
"max-bitrate", 1,
"Maximum bitrate");
77 static const arg_def_t lag_in_frame_arg =
78 ARG_DEF(NULL,
"lag-in-frames", 1,
79 "Number of frame to input before " 80 "generating any outputs");
81 static const arg_def_t rc_end_usage_arg =
82 ARG_DEF(NULL,
"rc-end-usage", 1,
"0 - 3: VBR, CBR, CQ, Q");
83 static const arg_def_t speed_arg =
84 ARG_DEF(
"sp",
"speed", 1,
"speed configuration");
85 static const arg_def_t aqmode_arg =
86 ARG_DEF(
"aq",
"aqmode", 1,
"aq-mode off/on");
87 static const arg_def_t bitrates_arg =
88 ARG_DEF(
"bl",
"bitrates", 1,
"bitrates[sl * num_tl + tl]");
89 static const arg_def_t dropframe_thresh_arg =
90 ARG_DEF(NULL,
"drop-frame", 1,
"Temporal resampling threshold (buf %)");
91 static const struct arg_enum_list tune_content_enum[] = {
92 {
"default", VP9E_CONTENT_DEFAULT },
93 {
"screen", VP9E_CONTENT_SCREEN },
94 {
"film", VP9E_CONTENT_FILM },
98 static const arg_def_t tune_content_arg = ARG_DEF_ENUM(
99 NULL,
"tune-content", 1,
"Tune content type", tune_content_enum);
100 static const arg_def_t inter_layer_pred_arg = ARG_DEF(
101 NULL,
"inter-layer-pred", 1,
"0 - 3: On, Off, Key-frames, Constrained");
103 #if CONFIG_VP9_HIGHBITDEPTH 104 static const struct arg_enum_list bitdepth_enum[] = {
108 static const arg_def_t bitdepth_arg = ARG_DEF_ENUM(
109 "d",
"bit-depth", 1,
"Bit depth for codec 8, 10 or 12. ", bitdepth_enum);
110 #endif // CONFIG_VP9_HIGHBITDEPTH 112 static const arg_def_t *svc_args[] = { &frames_arg,
128 &temporal_layers_arg,
129 &temporal_layering_mode_arg,
134 &output_rc_stats_arg,
137 #if CONFIG_VP9_HIGHBITDEPTH 143 &dropframe_thresh_arg,
145 &inter_layer_pred_arg,
148 static const uint32_t default_frames_to_skip = 0;
149 static const uint32_t default_frames_to_code = 60 * 60;
150 static const uint32_t default_width = 1920;
151 static const uint32_t default_height = 1080;
152 static const uint32_t default_timebase_num = 1;
153 static const uint32_t default_timebase_den = 60;
154 static const uint32_t default_bitrate = 1000;
155 static const uint32_t default_spatial_layers = 5;
156 static const uint32_t default_temporal_layers = 1;
157 static const uint32_t default_kf_dist = 100;
158 static const uint32_t default_temporal_layering_mode = 0;
159 static const uint32_t default_output_rc_stats = 0;
160 static const int32_t default_speed = -1;
161 static const uint32_t default_threads = 0;
164 const char *input_filename;
165 const char *output_filename;
166 uint32_t frames_to_code;
167 uint32_t frames_to_skip;
168 struct VpxInputContext input_ctx;
173 int inter_layer_pred;
176 static const char *exec_name;
178 void usage_exit(
void) {
179 fprintf(stderr,
"Usage: %s <options> input_filename output_filename\n",
181 fprintf(stderr,
"Options:\n");
182 arg_show_usage(stderr, svc_args);
186 static void parse_command_line(
int argc,
const char **argv_,
187 AppInput *app_input, SvcContext *svc_ctx,
196 const char *fpf_file_name = NULL;
197 unsigned int min_bitrate = 0;
198 unsigned int max_bitrate = 0;
199 char string_options[1024] = { 0 };
202 svc_ctx->log_level = SVC_LOG_DEBUG;
203 svc_ctx->spatial_layers = default_spatial_layers;
204 svc_ctx->temporal_layers = default_temporal_layers;
205 svc_ctx->temporal_layering_mode = default_temporal_layering_mode;
207 svc_ctx->output_rc_stat = default_output_rc_stats;
209 svc_ctx->speed = default_speed;
210 svc_ctx->threads = default_threads;
218 enc_cfg->
g_w = default_width;
219 enc_cfg->
g_h = default_height;
228 app_input->frames_to_code = default_frames_to_code;
229 app_input->frames_to_skip = default_frames_to_skip;
232 argv = argv_dup(argc - 1, argv_ + 1);
233 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
236 if (arg_match(&arg, &frames_arg, argi)) {
237 app_input->frames_to_code = arg_parse_uint(&arg);
238 }
else if (arg_match(&arg, &width_arg, argi)) {
239 enc_cfg->
g_w = arg_parse_uint(&arg);
240 }
else if (arg_match(&arg, &height_arg, argi)) {
241 enc_cfg->
g_h = arg_parse_uint(&arg);
242 }
else if (arg_match(&arg, &timebase_arg, argi)) {
243 enc_cfg->
g_timebase = arg_parse_rational(&arg);
244 }
else if (arg_match(&arg, &bitrate_arg, argi)) {
246 }
else if (arg_match(&arg, &skip_frames_arg, argi)) {
247 app_input->frames_to_skip = arg_parse_uint(&arg);
248 }
else if (arg_match(&arg, &spatial_layers_arg, argi)) {
249 svc_ctx->spatial_layers = arg_parse_uint(&arg);
250 }
else if (arg_match(&arg, &temporal_layers_arg, argi)) {
251 svc_ctx->temporal_layers = arg_parse_uint(&arg);
253 }
else if (arg_match(&arg, &output_rc_stats_arg, argi)) {
254 svc_ctx->output_rc_stat = arg_parse_uint(&arg);
256 }
else if (arg_match(&arg, &speed_arg, argi)) {
257 svc_ctx->speed = arg_parse_uint(&arg);
258 }
else if (arg_match(&arg, &aqmode_arg, argi)) {
259 svc_ctx->aqmode = arg_parse_uint(&arg);
260 }
else if (arg_match(&arg, &threads_arg, argi)) {
261 svc_ctx->threads = arg_parse_uint(&arg);
262 }
else if (arg_match(&arg, &temporal_layering_mode_arg, argi)) {
265 if (svc_ctx->temporal_layering_mode) {
268 }
else if (arg_match(&arg, &kf_dist_arg, argi)) {
271 }
else if (arg_match(&arg, &scale_factors_arg, argi)) {
272 strncat(string_options,
" scale-factors=",
273 sizeof(string_options) - strlen(string_options) - 1);
274 strncat(string_options, arg.val,
275 sizeof(string_options) - strlen(string_options) - 1);
276 }
else if (arg_match(&arg, &bitrates_arg, argi)) {
277 strncat(string_options,
" bitrates=",
278 sizeof(string_options) - strlen(string_options) - 1);
279 strncat(string_options, arg.val,
280 sizeof(string_options) - strlen(string_options) - 1);
281 }
else if (arg_match(&arg, &passes_arg, argi)) {
282 passes = arg_parse_uint(&arg);
283 if (passes < 1 || passes > 2) {
284 die(
"Error: Invalid number of passes (%d)\n", passes);
286 }
else if (arg_match(&arg, &pass_arg, argi)) {
287 pass = arg_parse_uint(&arg);
288 if (pass < 1 || pass > 2) {
289 die(
"Error: Invalid pass selected (%d)\n", pass);
291 }
else if (arg_match(&arg, &fpf_name_arg, argi)) {
292 fpf_file_name = arg.val;
293 }
else if (arg_match(&arg, &min_q_arg, argi)) {
294 strncat(string_options,
" min-quantizers=",
295 sizeof(string_options) - strlen(string_options) - 1);
296 strncat(string_options, arg.val,
297 sizeof(string_options) - strlen(string_options) - 1);
298 }
else if (arg_match(&arg, &max_q_arg, argi)) {
299 strncat(string_options,
" max-quantizers=",
300 sizeof(string_options) - strlen(string_options) - 1);
301 strncat(string_options, arg.val,
302 sizeof(string_options) - strlen(string_options) - 1);
303 }
else if (arg_match(&arg, &min_bitrate_arg, argi)) {
304 min_bitrate = arg_parse_uint(&arg);
305 }
else if (arg_match(&arg, &max_bitrate_arg, argi)) {
306 max_bitrate = arg_parse_uint(&arg);
307 }
else if (arg_match(&arg, &lag_in_frame_arg, argi)) {
309 }
else if (arg_match(&arg, &rc_end_usage_arg, argi)) {
311 #if CONFIG_VP9_HIGHBITDEPTH 312 }
else if (arg_match(&arg, &bitdepth_arg, argi)) {
313 enc_cfg->
g_bit_depth = arg_parse_enum_or_int(&arg);
328 die(
"Error: Invalid bit depth selected (%d)\n", enc_cfg->
g_bit_depth);
331 #endif // CONFIG_VP9_HIGHBITDEPTH 332 }
else if (arg_match(&arg, &dropframe_thresh_arg, argi)) {
334 }
else if (arg_match(&arg, &tune_content_arg, argi)) {
335 app_input->tune_content = arg_parse_uint(&arg);
336 }
else if (arg_match(&arg, &inter_layer_pred_arg, argi)) {
337 app_input->inter_layer_pred = arg_parse_uint(&arg);
344 if (strlen(string_options) > 0)
345 vpx_svc_set_options(svc_ctx, string_options + 1);
347 if (passes == 0 || passes == 1) {
349 fprintf(stderr,
"pass is ignored since there's only one pass\n");
354 die(
"pass must be specified when passes is 2\n");
357 if (fpf_file_name == NULL) {
358 die(
"fpf must be specified when passes is 2\n");
363 if (!stats_open_file(&app_input->rc_stats, fpf_file_name, 0)) {
364 fatal(
"Failed to open statistics store");
368 if (!stats_open_file(&app_input->rc_stats, fpf_file_name, 1)) {
369 fatal(
"Failed to open statistics store");
373 app_input->passes = passes;
374 app_input->pass = pass;
378 if (min_bitrate > 0) {
382 if (max_bitrate > 0) {
389 for (argi = argv; *argi; ++argi)
390 if (argi[0][0] ==
'-' && strlen(argi[0]) > 1)
391 die(
"Error: Unrecognized option %s\n", *argi);
393 if (argv[0] == NULL || argv[1] == 0) {
396 app_input->input_filename = argv[0];
397 app_input->output_filename = argv[1];
400 if (enc_cfg->
g_w < 16 || enc_cfg->
g_w % 2 || enc_cfg->
g_h < 16 ||
402 die(
"Invalid resolution: %d x %d\n", enc_cfg->
g_w, enc_cfg->
g_h);
405 "Codec %s\nframes: %d, skip: %d\n" 407 "width %d, height: %d,\n" 408 "num: %d, den: %d, bitrate: %d,\n" 411 app_input->frames_to_skip, svc_ctx->spatial_layers, enc_cfg->
g_w,
418 struct RateControlStats {
437 double avg_st_encoding_bitrate;
439 double variance_st_encoding_bitrate;
448 static void set_rate_control_stats(
struct RateControlStats *rc,
459 rc->layer_framerate[layer] = framerate;
463 rc->layer_pfb[layer] =
467 (rc->layer_framerate[layer] - rc->layer_framerate[layer - 1]);
470 rc->layer_framerate[layer];
472 rc->layer_input_frames[layer] = 0;
473 rc->layer_enc_frames[layer] = 0;
474 rc->layer_tot_enc_frames[layer] = 0;
475 rc->layer_encoding_bitrate[layer] = 0.0;
476 rc->layer_avg_frame_size[layer] = 0.0;
477 rc->layer_avg_rate_mismatch[layer] = 0.0;
480 rc->window_count = 0;
481 rc->window_size = 15;
482 rc->avg_st_encoding_bitrate = 0.0;
483 rc->variance_st_encoding_bitrate = 0.0;
486 static void printout_rate_control_summary(
struct RateControlStats *rc,
490 double perc_fluctuation = 0.0;
491 int tot_num_frames = 0;
492 printf(
"Total number of processed frames: %d\n\n", frame_cnt - 1);
493 printf(
"Rate control layer stats for sl%d tl%d layer(s):\n\n",
499 const int num_dropped =
501 ? (rc->layer_input_frames[layer] - rc->layer_enc_frames[layer])
502 : (rc->layer_input_frames[layer] - rc->layer_enc_frames[layer] -
504 tot_num_frames += rc->layer_input_frames[layer];
505 rc->layer_encoding_bitrate[layer] = 0.001 * rc->layer_framerate[layer] *
506 rc->layer_encoding_bitrate[layer] /
508 rc->layer_avg_frame_size[layer] =
509 rc->layer_avg_frame_size[layer] / rc->layer_enc_frames[layer];
510 rc->layer_avg_rate_mismatch[layer] = 100.0 *
511 rc->layer_avg_rate_mismatch[layer] /
512 rc->layer_enc_frames[layer];
513 printf(
"For layer#: sl%d tl%d \n", sl, tl);
514 printf(
"Bitrate (target vs actual): %d %f.0 kbps\n",
516 rc->layer_encoding_bitrate[layer]);
517 printf(
"Average frame size (target vs actual): %f %f bits\n",
518 rc->layer_pfb[layer], rc->layer_avg_frame_size[layer]);
519 printf(
"Average rate_mismatch: %f\n", rc->layer_avg_rate_mismatch[layer]);
521 "Number of input frames, encoded (non-key) frames, " 522 "and percent dropped frames: %d %d %f.0 \n",
523 rc->layer_input_frames[layer], rc->layer_enc_frames[layer],
524 100.0 * num_dropped / rc->layer_input_frames[layer]);
528 rc->avg_st_encoding_bitrate = rc->avg_st_encoding_bitrate / rc->window_count;
529 rc->variance_st_encoding_bitrate =
530 rc->variance_st_encoding_bitrate / rc->window_count -
531 (rc->avg_st_encoding_bitrate * rc->avg_st_encoding_bitrate);
532 perc_fluctuation = 100.0 * sqrt(rc->variance_st_encoding_bitrate) /
533 rc->avg_st_encoding_bitrate;
534 printf(
"Short-time stats, for window of %d frames: \n", rc->window_size);
535 printf(
"Average, rms-variance, and percent-fluct: %f %f %f \n",
536 rc->avg_st_encoding_bitrate, sqrt(rc->variance_st_encoding_bitrate),
538 printf(
"Num of input, num of encoded (super) frames: %d %d \n", frame_cnt,
542 vpx_codec_err_t parse_superframe_index(
const uint8_t *data,
size_t data_sz,
543 uint64_t sizes[8],
int *count) {
552 marker = *(data + data_sz - 1);
555 if ((marker & 0xe0) == 0xc0) {
556 const uint32_t frames = (marker & 0x7) + 1;
557 const uint32_t mag = ((marker >> 3) & 0x3) + 1;
558 const size_t index_sz = 2 + mag * frames;
565 const uint8_t marker2 = *(data + data_sz - index_sz);
576 const uint8_t *x = &data[data_sz - index_sz + 1];
578 for (i = 0; i < frames; ++i) {
579 uint32_t this_sz = 0;
581 for (j = 0; j < mag; ++j) this_sz |= (*x++) << (j * 8);
595 static void set_frame_flags_bypass_mode_ex0(
596 int tl,
int num_spatial_layers,
int is_key_frame,
599 for (sl = 0; sl < num_spatial_layers; ++sl)
602 for (sl = 0; sl < num_spatial_layers; ++sl) {
617 }
else if (tl == 1) {
619 ref_frame_config->
gld_fb_idx[sl] = num_spatial_layers + sl - 1;
620 ref_frame_config->
alt_fb_idx[sl] = num_spatial_layers + sl;
647 }
else if (tl == 1) {
657 if (sl < num_spatial_layers - 1) {
663 }
else if (sl == num_spatial_layers - 1) {
677 static void set_frame_flags_bypass_mode_ex1(
678 int tl,
int num_spatial_layers,
int is_key_frame,
681 for (sl = 0; sl < num_spatial_layers; ++sl)
740 int main(
int argc,
const char **argv) {
742 VpxVideoWriter *writer = NULL;
749 uint32_t frame_cnt = 0;
753 int frame_duration = 1;
755 int end_of_stream = 0;
756 int frames_received = 0;
759 struct RateControlStats rc;
763 double sum_bitrate = 0.0;
764 double sum_bitrate2 = 0.0;
765 double framerate = 30.0;
767 struct vpx_usec_timer timer;
769 memset(&svc_ctx, 0,
sizeof(svc_ctx));
770 memset(&app_input, 0,
sizeof(AppInput));
771 memset(&info, 0,
sizeof(VpxVideoInfo));
773 memset(&rc, 0,
sizeof(
struct RateControlStats));
775 parse_command_line(argc, argv, &app_input, &svc_ctx, &enc_cfg);
778 #if CONFIG_VP9_HIGHBITDEPTH 781 : VPX_IMG_FMT_I42016,
782 enc_cfg.
g_w, enc_cfg.
g_h, 32)) {
783 die(
"Failed to allocate image %dx%d\n", enc_cfg.
g_w, enc_cfg.
g_h);
787 die(
"Failed to allocate image %dx%d\n", enc_cfg.
g_w, enc_cfg.
g_h);
789 #endif // CONFIG_VP9_HIGHBITDEPTH 791 if (!(infile = fopen(app_input.input_filename,
"rb")))
792 die(
"Failed to open %s for reading\n", app_input.input_filename);
795 if (vpx_svc_init(&svc_ctx, &codec, vpx_codec_vp9_cx(), &enc_cfg) !=
797 die(
"Failed to initialize encoder\n");
802 rc.avg_st_encoding_bitrate = 0.0;
803 rc.variance_st_encoding_bitrate = 0.0;
804 if (svc_ctx.output_rc_stat) {
805 set_rate_control_stats(&rc, &enc_cfg);
810 info.codec_fourcc = VP9_FOURCC;
814 if (!(app_input.passes == 2 && app_input.pass == 1)) {
817 vpx_video_writer_open(app_input.output_filename, kContainerIVF, &info);
819 die(
"Failed to open %s for writing\n", app_input.output_filename);
824 if (svc_ctx.output_rc_stat) {
826 char file_name[PATH_MAX];
828 snprintf(file_name,
sizeof(file_name),
"%s_s%d.ivf",
829 app_input.output_filename, sl);
830 outfile[sl] = vpx_video_writer_open(file_name, kContainerIVF, &info);
831 if (!outfile[sl]) die(
"Failed to open %s for writing", file_name);
837 for (i = 0; i < app_input.frames_to_skip; ++i) vpx_img_read(&raw, infile);
839 if (svc_ctx.speed != -1)
841 if (svc_ctx.threads) {
843 if (svc_ctx.threads > 1)
848 if (svc_ctx.speed >= 5 && svc_ctx.aqmode == 1)
850 if (svc_ctx.speed >= 5)
855 app_input.inter_layer_pred);
862 for (sl = 0; sl < (
unsigned int)svc_ctx.spatial_layers; ++sl)
868 while (!end_of_stream) {
876 int example_pattern = 0;
877 if (frame_cnt >= app_input.frames_to_code || !vpx_img_read(&raw, infile)) {
890 layer_id.spatial_layer_id = 0;
892 if (frame_cnt % 2 == 0) {
893 layer_id.temporal_layer_id = 0;
895 layer_id.temporal_layer_id_per_spatial[i] = 0;
897 layer_id.temporal_layer_id = 1;
899 layer_id.temporal_layer_id_per_spatial[i] = 1;
901 if (example_pattern == 1) {
903 assert(svc_ctx.spatial_layers == 2);
904 assert(svc_ctx.temporal_layers == 2);
905 if (frame_cnt % 2 == 0) {
907 layer_id.temporal_layer_id_per_spatial[0] = 0;
908 layer_id.temporal_layer_id_per_spatial[1] = 0;
909 layer_id.spatial_layer_id = 0;
912 layer_id.temporal_layer_id_per_spatial[1] = 1;
913 layer_id.spatial_layer_id = 1;
919 if (example_pattern == 0) {
920 set_frame_flags_bypass_mode_ex0(layer_id.temporal_layer_id,
921 svc_ctx.spatial_layers, frame_cnt == 0,
923 }
else if (example_pattern == 1) {
924 set_frame_flags_bypass_mode_ex1(layer_id.temporal_layer_id,
925 svc_ctx.spatial_layers, frame_cnt == 0,
928 ref_frame_config.
duration[0] = frame_duration * 1;
929 ref_frame_config.
duration[1] = frame_duration * 1;
937 layer_id.temporal_layer_id];
943 tl = (frame_cnt % 2 != 0);
945 if (frame_cnt % 2 != 0) tl = 2;
946 if ((frame_cnt > 1) && ((frame_cnt - 2) % 4 == 0)) tl = 1;
952 vpx_usec_timer_start(&timer);
953 res = vpx_svc_encode(
954 &svc_ctx, &codec, (end_of_stream ? NULL : &raw), pts, frame_duration,
956 vpx_usec_timer_mark(&timer);
957 cx_time += vpx_usec_timer_elapsed(&timer);
961 die_codec(&codec,
"Failed to encode frame");
965 switch (cx_pkt->
kind) {
967 SvcInternal_t *
const si = (SvcInternal_t *)svc_ctx.internal;
971 uint64_t sizes_parsed[8];
974 vp9_zero(sizes_parsed);
976 vpx_video_writer_write_frame(writer, cx_pkt->
data.
frame.buf,
981 if (svc_ctx.output_rc_stat) {
982 int num_layers_encoded = 0;
984 parse_superframe_index(cx_pkt->
data.
frame.buf,
991 if (cx_pkt->
data.
frame.spatial_layer_encoded[sl]) {
992 sizes[sl] = sizes_parsed[num_layers_encoded];
993 num_layers_encoded++;
998 uint64_t tot_size = 0;
999 for (sl2 = 0; sl2 <= sl; ++sl2) {
1000 if (cx_pkt->
data.
frame.spatial_layer_encoded[sl2])
1001 tot_size += sizes[sl2];
1004 vpx_video_writer_write_frame(
1005 outfile[sl], cx_pkt->
data.
frame.buf, (
size_t)(tot_size),
1009 if (cx_pkt->
data.
frame.spatial_layer_encoded[sl]) {
1010 for (tl = layer_id.temporal_layer_id;
1013 ++rc.layer_tot_enc_frames[layer];
1014 rc.layer_encoding_bitrate[layer] += 8.0 * sizes[sl];
1017 if (tl == (
unsigned int)layer_id.temporal_layer_id &&
1019 rc.layer_avg_frame_size[layer] += 8.0 * sizes[sl];
1020 rc.layer_avg_rate_mismatch[layer] +=
1021 fabs(8.0 * sizes[sl] - rc.layer_pfb[layer]) /
1022 rc.layer_pfb[layer];
1023 ++rc.layer_enc_frames[layer];
1032 if (frame_cnt > (
unsigned int)rc.window_size) {
1034 if (cx_pkt->
data.
frame.spatial_layer_encoded[sl])
1035 sum_bitrate += 0.001 * 8.0 * sizes[sl] * framerate;
1037 if (frame_cnt % rc.window_size == 0) {
1038 rc.window_count += 1;
1039 rc.avg_st_encoding_bitrate += sum_bitrate / rc.window_size;
1040 rc.variance_st_encoding_bitrate +=
1041 (sum_bitrate / rc.window_size) *
1042 (sum_bitrate / rc.window_size);
1049 (
unsigned int)(rc.window_size + rc.window_size / 2)) {
1051 sum_bitrate2 += 0.001 * 8.0 * sizes[sl] * framerate;
1054 if (frame_cnt > (
unsigned int)(2 * rc.window_size) &&
1055 frame_cnt % rc.window_size == 0) {
1056 rc.window_count += 1;
1057 rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
1058 rc.variance_st_encoding_bitrate +=
1059 (sum_bitrate2 / rc.window_size) *
1060 (sum_bitrate2 / rc.window_size);
1073 si->bytes_sum[0] += (int)cx_pkt->
data.
frame.sz;
1086 if (!end_of_stream) {
1088 pts += frame_duration;
1092 printf(
"Processed %d frames\n", frame_cnt);
1095 if (svc_ctx.output_rc_stat) {
1096 printout_rate_control_summary(&rc, &enc_cfg, frame_cnt);
1101 if (app_input.passes == 2) stats_close(&app_input.rc_stats, 1);
1103 vpx_video_writer_close(writer);
1106 if (svc_ctx.output_rc_stat) {
1108 vpx_video_writer_close(outfile[sl]);
1112 printf(
"Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",
1113 frame_cnt, 1000 * (
float)cx_time / (
double)(frame_cnt * 1000000),
1114 1000000 * (
double)frame_cnt / (
double)cx_time);
1117 vpx_svc_dump_statistics(&svc_ctx);
1118 vpx_svc_release(&svc_ctx);
1119 return EXIT_SUCCESS;
vpx_fixed_buf_t twopass_stats
Definition: vpx_encoder.h:188
unsigned int ts_number_layers
Number of temporal coding layers.
Definition: vpx_encoder.h:660
Codec control function to set encoder internal speed settings.
Definition: vp8cx.h:155
#define VPX_MAX_LAYERS
Definition: vpx_encoder.h:46
int reference_alt_ref[5]
Definition: vp8cx.h:812
Image Descriptor.
Definition: vpx_image.h:71
Describes the encoder algorithm interface to applications.
const char * vpx_codec_iface_name(vpx_codec_iface_t *iface)
Return the name for a given interface.
Codec control function to constrain the inter-layer prediction (prediction of lower spatial resolutio...
Definition: vp8cx.h:613
const char * vpx_codec_err_to_string(vpx_codec_err_t err)
Convert error number to printable string.
int lst_fb_idx[5]
Definition: vp8cx.h:802
Codec control function to set content type.
Definition: vp8cx.h:457
struct vpx_rational g_timebase
Stream timebase units.
Definition: vpx_encoder.h:354
Codec control function to set noise sensitivity.
Definition: vp8cx.h:415
unsigned int layer_target_bitrate[12]
Target bitrate for each spatial/temporal layer.
Definition: vpx_encoder.h:700
SVC_LAYER_DROP_MODE framedrop_mode
Definition: vp8cx.h:838
unsigned int g_input_bit_depth
Bit-depth of the input frames.
Definition: vpx_encoder.h:340
int den
Definition: vpx_encoder.h:228
Definition: vpx_encoder.h:154
int framedrop_thresh[5]
Definition: vp8cx.h:836
unsigned int kf_max_dist
Keyframe maximum interval.
Definition: vpx_encoder.h:630
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition: vpx_encoder.h:383
Encoder configuration structure.
Definition: vpx_encoder.h:276
int reference_golden[5]
Definition: vp8cx.h:811
The coded data for this stream is corrupt or incomplete.
Definition: vpx_codec.h:130
Codec control function to set row level multi-threading.
Definition: vp8cx.h:564
Codec control function to set Max data rate for Intra frames.
Definition: vp8cx.h:251
Encoder output packet.
Definition: vpx_encoder.h:165
void * buf
Definition: vpx_encoder.h:103
unsigned int ts_rate_decimator[5]
Frame rate decimation factor for each temporal layer.
Definition: vpx_encoder.h:674
unsigned int kf_min_dist
Keyframe minimum interval.
Definition: vpx_encoder.h:621
Definition: vpx_encoder.h:234
vp9 svc frame dropping parameters.
Definition: vp8cx.h:835
unsigned int g_profile
Bitstream profile to use.
Definition: vpx_encoder.h:306
Definition: vpx_encoder.h:235
Codec control function to set number of tile columns.
Definition: vp8cx.h:345
struct vpx_codec_cx_pkt::@1::@2 frame
#define VPX_SS_MAX_LAYERS
Definition: vpx_encoder.h:52
vpx_image_t * vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
Definition: vpx_image.h:42
unsigned int g_w
Width of the frame.
Definition: vpx_encoder.h:315
int reference_last[5]
Definition: vp8cx.h:810
int update_buffer_slot[5]
Definition: vp8cx.h:805
Codec control function to set adaptive quantization mode.
Definition: vp8cx.h:392
Codec control function to get svc layer ID.
Definition: vp8cx.h:465
unsigned int g_h
Height of the frame.
Definition: vpx_encoder.h:324
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:166
unsigned int rc_dropframe_thresh
Temporal resampling configuration, if supported by the codec.
Definition: vpx_encoder.h:405
vp9 svc layer parameters
Definition: vp8cx.h:786
Operation completed without error.
Definition: vpx_codec.h:92
void vpx_img_free(vpx_image_t *img)
Close an image descriptor.
unsigned int rc_target_bitrate
Target data rate.
Definition: vpx_encoder.h:474
#define VPX_DL_REALTIME
deadline parameter analogous to VPx REALTIME mode.
Definition: vpx_encoder.h:846
int num
Definition: vpx_encoder.h:227
Definition: vpx_codec.h:220
Codec control function to set the frame flags and buffer indices for spatial layers. The frame flags and buffer indices are set using the struct vpx_svc_ref_frame_config defined below.
Definition: vp8cx.h:539
enum vpx_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: vpx_encoder.h:369
Codec control function to set mode and thresholds for frame dropping in SVC. Drop frame thresholds ar...
Definition: vp8cx.h:622
#define VPX_DL_GOOD_QUALITY
deadline parameter analogous to VPx GOOD QUALITY mode.
Definition: vpx_encoder.h:848
unsigned int ss_number_layers
Number of spatial coding layers.
Definition: vpx_encoder.h:640
vpx_bit_depth_t g_bit_depth
Bit-depth of the codec.
Definition: vpx_encoder.h:332
Provides definitions for using VP8 or VP9 encoder algorithm within the vpx Codec Interface.
Bypass mode. Used when application needs to control temporal layering. This will only work when the n...
Definition: vp8cx.h:692
vpx_codec_err_t
Algorithm return codes.
Definition: vpx_codec.h:90
const vpx_codec_cx_pkt_t * vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter)
Encoded data iterator.
union vpx_codec_cx_pkt::@1 data
int temporal_layering_mode
Temporal layering mode indicating which temporal layering scheme to use.
Definition: vpx_encoder.h:709
vpx_fixed_buf_t rc_twopass_stats_in
Two-pass stats buffer.
Definition: vpx_encoder.h:461
vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, unsigned int reserved)
Get a default configuration.
int max_consec_drop
Definition: vp8cx.h:839
Definition: vpx_encoder.h:242
#define vpx_codec_control(ctx, id, data)
vpx_codec_control wrapper macro
Definition: vpx_codec.h:404
vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx)
Destroy a codec instance.
size_t sz
Definition: vpx_encoder.h:104
Definition: vpx_codec.h:218
vp9 svc frame flag parameters.
Definition: vp8cx.h:801
Codec control function to set the threshold for MBs treated static.
Definition: vp8cx.h:182
int64_t duration[5]
Definition: vp8cx.h:813
#define VPX_FRAME_IS_KEY
Definition: vpx_encoder.h:122
Definition: vpx_codec.h:219
int alt_fb_idx[5]
Definition: vp8cx.h:804
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:187
Definition: vpx_encoder.h:153
unsigned int rc_2pass_vbr_maxsection_pct
Two-pass mode per-GOP maximum bitrate.
Definition: vpx_encoder.h:593
vpx_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition: vpx_encoder.h:362
unsigned int rc_2pass_vbr_minsection_pct
Two-pass mode per-GOP minimum bitrate.
Definition: vpx_encoder.h:586
int gld_fb_idx[5]
Definition: vp8cx.h:803
Codec control function to set svc layer for spatial and temporal.
Definition: vp8cx.h:447
enum vpx_rc_mode rc_end_usage
Rate control algorithm to use.
Definition: vpx_encoder.h:454
Definition: vpx_encoder.h:233
Codec context structure.
Definition: vpx_codec.h:197