WebM Codec SDK
vpx_temporal_svc_encoder
1 /*
2  * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3  *
4  * Use of this source code is governed by a BSD-style license
5  * that can be found in the LICENSE file in the root of the source
6  * tree. An additional intellectual property rights grant can be found
7  * in the file PATENTS. All contributing project authors may
8  * be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 // This is an example demonstrating how to implement a multi-layer VPx
12 // encoding scheme based on temporal scalability for video applications
13 // that benefit from a scalable bitstream.
14 
15 #include <assert.h>
16 #include <math.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 
21 #include "./vpx_config.h"
22 #include "../vpx_ports/vpx_timer.h"
23 #include "vpx/vp8cx.h"
24 #include "vpx/vpx_encoder.h"
25 
26 #include "../tools_common.h"
27 #include "../video_writer.h"
28 
29 #define ROI_MAP 0
30 
31 #define zero(Dest) memset(&Dest, 0, sizeof(Dest));
32 
33 static const char *exec_name;
34 
35 void usage_exit(void) { exit(EXIT_FAILURE); }
36 
37 // Denoiser states for vp8, for temporal denoising.
38 enum denoiserStateVp8 {
39  kVp8DenoiserOff,
40  kVp8DenoiserOnYOnly,
41  kVp8DenoiserOnYUV,
42  kVp8DenoiserOnYUVAggressive,
43  kVp8DenoiserOnAdaptive
44 };
45 
46 // Denoiser states for vp9, for temporal denoising.
47 enum denoiserStateVp9 {
48  kVp9DenoiserOff,
49  kVp9DenoiserOnYOnly,
50  // For SVC: denoise the top two spatial layers.
51  kVp9DenoiserOnYTwoSpatialLayers
52 };
53 
54 static int mode_to_num_layers[13] = { 1, 2, 2, 3, 3, 3, 3, 5, 2, 3, 3, 3, 3 };
55 
56 // For rate control encoding stats.
57 struct RateControlMetrics {
58  // Number of input frames per layer.
59  int layer_input_frames[VPX_TS_MAX_LAYERS];
60  // Total (cumulative) number of encoded frames per layer.
61  int layer_tot_enc_frames[VPX_TS_MAX_LAYERS];
62  // Number of encoded non-key frames per layer.
63  int layer_enc_frames[VPX_TS_MAX_LAYERS];
64  // Framerate per layer layer (cumulative).
65  double layer_framerate[VPX_TS_MAX_LAYERS];
66  // Target average frame size per layer (per-frame-bandwidth per layer).
67  double layer_pfb[VPX_TS_MAX_LAYERS];
68  // Actual average frame size per layer.
69  double layer_avg_frame_size[VPX_TS_MAX_LAYERS];
70  // Average rate mismatch per layer (|target - actual| / target).
71  double layer_avg_rate_mismatch[VPX_TS_MAX_LAYERS];
72  // Actual encoding bitrate per layer (cumulative).
73  double layer_encoding_bitrate[VPX_TS_MAX_LAYERS];
74  // Average of the short-time encoder actual bitrate.
75  // TODO(marpan): Should we add these short-time stats for each layer?
76  double avg_st_encoding_bitrate;
77  // Variance of the short-time encoder actual bitrate.
78  double variance_st_encoding_bitrate;
79  // Window (number of frames) for computing short-timee encoding bitrate.
80  int window_size;
81  // Number of window measurements.
82  int window_count;
83  int layer_target_bitrate[VPX_MAX_LAYERS];
84 };
85 
86 // Note: these rate control metrics assume only 1 key frame in the
87 // sequence (i.e., first frame only). So for temporal pattern# 7
88 // (which has key frame for every frame on base layer), the metrics
89 // computation will be off/wrong.
90 // TODO(marpan): Update these metrics to account for multiple key frames
91 // in the stream.
92 static void set_rate_control_metrics(struct RateControlMetrics *rc,
93  vpx_codec_enc_cfg_t *cfg) {
94  unsigned int i = 0;
95  // Set the layer (cumulative) framerate and the target layer (non-cumulative)
96  // per-frame-bandwidth, for the rate control encoding stats below.
97  const double framerate = cfg->g_timebase.den / cfg->g_timebase.num;
98  rc->layer_framerate[0] = framerate / cfg->ts_rate_decimator[0];
99  rc->layer_pfb[0] =
100  1000.0 * rc->layer_target_bitrate[0] / rc->layer_framerate[0];
101  for (i = 0; i < cfg->ts_number_layers; ++i) {
102  if (i > 0) {
103  rc->layer_framerate[i] = framerate / cfg->ts_rate_decimator[i];
104  rc->layer_pfb[i] =
105  1000.0 *
106  (rc->layer_target_bitrate[i] - rc->layer_target_bitrate[i - 1]) /
107  (rc->layer_framerate[i] - rc->layer_framerate[i - 1]);
108  }
109  rc->layer_input_frames[i] = 0;
110  rc->layer_enc_frames[i] = 0;
111  rc->layer_tot_enc_frames[i] = 0;
112  rc->layer_encoding_bitrate[i] = 0.0;
113  rc->layer_avg_frame_size[i] = 0.0;
114  rc->layer_avg_rate_mismatch[i] = 0.0;
115  }
116  rc->window_count = 0;
117  rc->window_size = 15;
118  rc->avg_st_encoding_bitrate = 0.0;
119  rc->variance_st_encoding_bitrate = 0.0;
120 }
121 
122 static void printout_rate_control_summary(struct RateControlMetrics *rc,
123  vpx_codec_enc_cfg_t *cfg,
124  int frame_cnt) {
125  unsigned int i = 0;
126  int tot_num_frames = 0;
127  double perc_fluctuation = 0.0;
128  printf("Total number of processed frames: %d\n\n", frame_cnt - 1);
129  printf("Rate control layer stats for %d layer(s):\n\n",
130  cfg->ts_number_layers);
131  for (i = 0; i < cfg->ts_number_layers; ++i) {
132  const int num_dropped =
133  (i > 0) ? (rc->layer_input_frames[i] - rc->layer_enc_frames[i])
134  : (rc->layer_input_frames[i] - rc->layer_enc_frames[i] - 1);
135  tot_num_frames += rc->layer_input_frames[i];
136  rc->layer_encoding_bitrate[i] = 0.001 * rc->layer_framerate[i] *
137  rc->layer_encoding_bitrate[i] /
138  tot_num_frames;
139  rc->layer_avg_frame_size[i] =
140  rc->layer_avg_frame_size[i] / rc->layer_enc_frames[i];
141  rc->layer_avg_rate_mismatch[i] =
142  100.0 * rc->layer_avg_rate_mismatch[i] / rc->layer_enc_frames[i];
143  printf("For layer#: %d \n", i);
144  printf("Bitrate (target vs actual): %d %f \n", rc->layer_target_bitrate[i],
145  rc->layer_encoding_bitrate[i]);
146  printf("Average frame size (target vs actual): %f %f \n", rc->layer_pfb[i],
147  rc->layer_avg_frame_size[i]);
148  printf("Average rate_mismatch: %f \n", rc->layer_avg_rate_mismatch[i]);
149  printf(
150  "Number of input frames, encoded (non-key) frames, "
151  "and perc dropped frames: %d %d %f \n",
152  rc->layer_input_frames[i], rc->layer_enc_frames[i],
153  100.0 * num_dropped / rc->layer_input_frames[i]);
154  printf("\n");
155  }
156  rc->avg_st_encoding_bitrate = rc->avg_st_encoding_bitrate / rc->window_count;
157  rc->variance_st_encoding_bitrate =
158  rc->variance_st_encoding_bitrate / rc->window_count -
159  (rc->avg_st_encoding_bitrate * rc->avg_st_encoding_bitrate);
160  perc_fluctuation = 100.0 * sqrt(rc->variance_st_encoding_bitrate) /
161  rc->avg_st_encoding_bitrate;
162  printf("Short-time stats, for window of %d frames: \n", rc->window_size);
163  printf("Average, rms-variance, and percent-fluct: %f %f %f \n",
164  rc->avg_st_encoding_bitrate, sqrt(rc->variance_st_encoding_bitrate),
165  perc_fluctuation);
166  if ((frame_cnt - 1) != tot_num_frames)
167  die("Error: Number of input frames not equal to output! \n");
168 }
169 
170 #if ROI_MAP
171 static void set_roi_map(const char *enc_name, vpx_codec_enc_cfg_t *cfg,
172  vpx_roi_map_t *roi) {
173  unsigned int i, j;
174  int block_size = 0;
175  uint8_t is_vp8 = strncmp(enc_name, "vp8", 3) == 0 ? 1 : 0;
176  uint8_t is_vp9 = strncmp(enc_name, "vp9", 3) == 0 ? 1 : 0;
177  if (!is_vp8 && !is_vp9) {
178  die("unsupported codec.");
179  }
180  zero(*roi);
181 
182  block_size = is_vp9 && !is_vp8 ? 8 : 16;
183 
184  // ROI is based on the segments (4 for vp8, 8 for vp9), smallest unit for
185  // segment is 16x16 for vp8, 8x8 for vp9.
186  roi->rows = (cfg->g_h + block_size - 1) / block_size;
187  roi->cols = (cfg->g_w + block_size - 1) / block_size;
188 
189  // Applies delta QP on the segment blocks, varies from -63 to 63.
190  // Setting to negative means lower QP (better quality).
191  // Below we set delta_q to the extreme (-63) to show strong effect.
192  // VP8 uses the first 4 segments. VP9 uses all 8 segments.
193  zero(roi->delta_q);
194  roi->delta_q[1] = -63;
195 
196  // Applies delta loopfilter strength on the segment blocks, varies from -63 to
197  // 63. Setting to positive means stronger loopfilter. VP8 uses the first 4
198  // segments. VP9 uses all 8 segments.
199  zero(roi->delta_lf);
200 
201  if (is_vp8) {
202  // Applies skip encoding threshold on the segment blocks, varies from 0 to
203  // UINT_MAX. Larger value means more skipping of encoding is possible.
204  // This skip threshold only applies on delta frames.
205  zero(roi->static_threshold);
206  }
207 
208  if (is_vp9) {
209  // Apply skip segment. Setting to 1 means this block will be copied from
210  // previous frame.
211  zero(roi->skip);
212  }
213 
214  if (is_vp9) {
215  // Apply ref frame segment.
216  // -1 : Do not apply this segment.
217  // 0 : Froce using intra.
218  // 1 : Force using last.
219  // 2 : Force using golden.
220  // 3 : Force using alfref but not used in non-rd pickmode for 0 lag.
221  memset(roi->ref_frame, -1, sizeof(roi->ref_frame));
222  roi->ref_frame[1] = 1;
223  }
224 
225  // Use 2 states: 1 is center square, 0 is the rest.
226  roi->roi_map =
227  (uint8_t *)calloc(roi->rows * roi->cols, sizeof(*roi->roi_map));
228  for (i = 0; i < roi->rows; ++i) {
229  for (j = 0; j < roi->cols; ++j) {
230  if (i > (roi->rows >> 2) && i < ((roi->rows * 3) >> 2) &&
231  j > (roi->cols >> 2) && j < ((roi->cols * 3) >> 2)) {
232  roi->roi_map[i * roi->cols + j] = 1;
233  }
234  }
235  }
236 }
237 #endif
238 
239 // Temporal scaling parameters:
240 // NOTE: The 3 prediction frames cannot be used interchangeably due to
241 // differences in the way they are handled throughout the code. The
242 // frames should be allocated to layers in the order LAST, GF, ARF.
243 // Other combinations work, but may produce slightly inferior results.
244 static void set_temporal_layer_pattern(int layering_mode,
245  vpx_codec_enc_cfg_t *cfg,
246  int *layer_flags,
247  int *flag_periodicity) {
248  switch (layering_mode) {
249  case 0: {
250  // 1-layer.
251  int ids[1] = { 0 };
252  cfg->ts_periodicity = 1;
253  *flag_periodicity = 1;
254  cfg->ts_number_layers = 1;
255  cfg->ts_rate_decimator[0] = 1;
256  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
257  // Update L only.
258  layer_flags[0] =
260  break;
261  }
262  case 1: {
263  // 2-layers, 2-frame period.
264  int ids[2] = { 0, 1 };
265  cfg->ts_periodicity = 2;
266  *flag_periodicity = 2;
267  cfg->ts_number_layers = 2;
268  cfg->ts_rate_decimator[0] = 2;
269  cfg->ts_rate_decimator[1] = 1;
270  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
271 #if 1
272  // 0=L, 1=GF, Intra-layer prediction enabled.
273  layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF |
276  layer_flags[1] =
278 #else
279  // 0=L, 1=GF, Intra-layer prediction disabled.
280  layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_UPD_GF |
283  layer_flags[1] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
285 #endif
286  break;
287  }
288  case 2: {
289  // 2-layers, 3-frame period.
290  int ids[3] = { 0, 1, 1 };
291  cfg->ts_periodicity = 3;
292  *flag_periodicity = 3;
293  cfg->ts_number_layers = 2;
294  cfg->ts_rate_decimator[0] = 3;
295  cfg->ts_rate_decimator[1] = 1;
296  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
297  // 0=L, 1=GF, Intra-layer prediction enabled.
298  layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
301  layer_flags[1] = layer_flags[2] =
304  break;
305  }
306  case 3: {
307  // 3-layers, 6-frame period.
308  int ids[6] = { 0, 2, 2, 1, 2, 2 };
309  cfg->ts_periodicity = 6;
310  *flag_periodicity = 6;
311  cfg->ts_number_layers = 3;
312  cfg->ts_rate_decimator[0] = 6;
313  cfg->ts_rate_decimator[1] = 3;
314  cfg->ts_rate_decimator[2] = 1;
315  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
316  // 0=L, 1=GF, 2=ARF, Intra-layer prediction enabled.
317  layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
320  layer_flags[3] =
322  layer_flags[1] = layer_flags[2] = layer_flags[4] = layer_flags[5] =
324  break;
325  }
326  case 4: {
327  // 3-layers, 4-frame period.
328  int ids[4] = { 0, 2, 1, 2 };
329  cfg->ts_periodicity = 4;
330  *flag_periodicity = 4;
331  cfg->ts_number_layers = 3;
332  cfg->ts_rate_decimator[0] = 4;
333  cfg->ts_rate_decimator[1] = 2;
334  cfg->ts_rate_decimator[2] = 1;
335  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
336  // 0=L, 1=GF, 2=ARF, Intra-layer prediction disabled.
337  layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
340  layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
342  layer_flags[1] = layer_flags[3] =
345  break;
346  }
347  case 5: {
348  // 3-layers, 4-frame period.
349  int ids[4] = { 0, 2, 1, 2 };
350  cfg->ts_periodicity = 4;
351  *flag_periodicity = 4;
352  cfg->ts_number_layers = 3;
353  cfg->ts_rate_decimator[0] = 4;
354  cfg->ts_rate_decimator[1] = 2;
355  cfg->ts_rate_decimator[2] = 1;
356  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
357  // 0=L, 1=GF, 2=ARF, Intra-layer prediction enabled in layer 1, disabled
358  // in layer 2.
359  layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
362  layer_flags[2] =
364  layer_flags[1] = layer_flags[3] =
367  break;
368  }
369  case 6: {
370  // 3-layers, 4-frame period.
371  int ids[4] = { 0, 2, 1, 2 };
372  cfg->ts_periodicity = 4;
373  *flag_periodicity = 4;
374  cfg->ts_number_layers = 3;
375  cfg->ts_rate_decimator[0] = 4;
376  cfg->ts_rate_decimator[1] = 2;
377  cfg->ts_rate_decimator[2] = 1;
378  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
379  // 0=L, 1=GF, 2=ARF, Intra-layer prediction enabled.
380  layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
383  layer_flags[2] =
385  layer_flags[1] = layer_flags[3] =
387  break;
388  }
389  case 7: {
390  // NOTE: Probably of academic interest only.
391  // 5-layers, 16-frame period.
392  int ids[16] = { 0, 4, 3, 4, 2, 4, 3, 4, 1, 4, 3, 4, 2, 4, 3, 4 };
393  cfg->ts_periodicity = 16;
394  *flag_periodicity = 16;
395  cfg->ts_number_layers = 5;
396  cfg->ts_rate_decimator[0] = 16;
397  cfg->ts_rate_decimator[1] = 8;
398  cfg->ts_rate_decimator[2] = 4;
399  cfg->ts_rate_decimator[3] = 2;
400  cfg->ts_rate_decimator[4] = 1;
401  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
402  layer_flags[0] = VPX_EFLAG_FORCE_KF;
403  layer_flags[1] = layer_flags[3] = layer_flags[5] = layer_flags[7] =
404  layer_flags[9] = layer_flags[11] = layer_flags[13] = layer_flags[15] =
407  layer_flags[2] = layer_flags[6] = layer_flags[10] = layer_flags[14] =
409  layer_flags[4] = layer_flags[12] =
411  layer_flags[8] = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF;
412  break;
413  }
414  case 8: {
415  // 2-layers, with sync point at first frame of layer 1.
416  int ids[2] = { 0, 1 };
417  cfg->ts_periodicity = 2;
418  *flag_periodicity = 8;
419  cfg->ts_number_layers = 2;
420  cfg->ts_rate_decimator[0] = 2;
421  cfg->ts_rate_decimator[1] = 1;
422  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
423  // 0=L, 1=GF.
424  // ARF is used as predictor for all frames, and is only updated on
425  // key frame. Sync point every 8 frames.
426 
427  // Layer 0: predict from L and ARF, update L and G.
428  layer_flags[0] =
430  // Layer 1: sync point: predict from L and ARF, and update G.
431  layer_flags[1] =
433  // Layer 0, predict from L and ARF, update L.
434  layer_flags[2] =
436  // Layer 1: predict from L, G and ARF, and update G.
437  layer_flags[3] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
439  // Layer 0.
440  layer_flags[4] = layer_flags[2];
441  // Layer 1.
442  layer_flags[5] = layer_flags[3];
443  // Layer 0.
444  layer_flags[6] = layer_flags[4];
445  // Layer 1.
446  layer_flags[7] = layer_flags[5];
447  break;
448  }
449  case 9: {
450  // 3-layers: Sync points for layer 1 and 2 every 8 frames.
451  int ids[4] = { 0, 2, 1, 2 };
452  cfg->ts_periodicity = 4;
453  *flag_periodicity = 8;
454  cfg->ts_number_layers = 3;
455  cfg->ts_rate_decimator[0] = 4;
456  cfg->ts_rate_decimator[1] = 2;
457  cfg->ts_rate_decimator[2] = 1;
458  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
459  // 0=L, 1=GF, 2=ARF.
460  layer_flags[0] = VPX_EFLAG_FORCE_KF | VP8_EFLAG_NO_REF_GF |
463  layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
465  layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
467  layer_flags[3] = layer_flags[5] =
469  layer_flags[4] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
471  layer_flags[6] =
473  layer_flags[7] = VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
475  break;
476  }
477  case 10: {
478  // 3-layers structure where ARF is used as predictor for all frames,
479  // and is only updated on key frame.
480  // Sync points for layer 1 and 2 every 8 frames.
481 
482  int ids[4] = { 0, 2, 1, 2 };
483  cfg->ts_periodicity = 4;
484  *flag_periodicity = 8;
485  cfg->ts_number_layers = 3;
486  cfg->ts_rate_decimator[0] = 4;
487  cfg->ts_rate_decimator[1] = 2;
488  cfg->ts_rate_decimator[2] = 1;
489  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
490  // 0=L, 1=GF, 2=ARF.
491  // Layer 0: predict from L and ARF; update L and G.
492  layer_flags[0] =
494  // Layer 2: sync point: predict from L and ARF; update none.
495  layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF |
498  // Layer 1: sync point: predict from L and ARF; update G.
499  layer_flags[2] =
501  // Layer 2: predict from L, G, ARF; update none.
502  layer_flags[3] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
504  // Layer 0: predict from L and ARF; update L.
505  layer_flags[4] =
507  // Layer 2: predict from L, G, ARF; update none.
508  layer_flags[5] = layer_flags[3];
509  // Layer 1: predict from L, G, ARF; update G.
510  layer_flags[6] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
511  // Layer 2: predict from L, G, ARF; update none.
512  layer_flags[7] = layer_flags[3];
513  break;
514  }
515  case 11: {
516  // 3-layers structure with one reference frame.
517  // This works same as temporal_layering_mode 3.
518  // This was added to compare with vp9_spatial_svc_encoder.
519 
520  // 3-layers, 4-frame period.
521  int ids[4] = { 0, 2, 1, 2 };
522  cfg->ts_periodicity = 4;
523  *flag_periodicity = 4;
524  cfg->ts_number_layers = 3;
525  cfg->ts_rate_decimator[0] = 4;
526  cfg->ts_rate_decimator[1] = 2;
527  cfg->ts_rate_decimator[2] = 1;
528  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
529  // 0=L, 1=GF, 2=ARF, Intra-layer prediction disabled.
530  layer_flags[0] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
532  layer_flags[2] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
534  layer_flags[1] = VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF |
536  layer_flags[3] = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_ARF |
538  break;
539  }
540  case 12:
541  default: {
542  // 3-layers structure as in case 10, but no sync/refresh points for
543  // layer 1 and 2.
544  int ids[4] = { 0, 2, 1, 2 };
545  cfg->ts_periodicity = 4;
546  *flag_periodicity = 8;
547  cfg->ts_number_layers = 3;
548  cfg->ts_rate_decimator[0] = 4;
549  cfg->ts_rate_decimator[1] = 2;
550  cfg->ts_rate_decimator[2] = 1;
551  memcpy(cfg->ts_layer_id, ids, sizeof(ids));
552  // 0=L, 1=GF, 2=ARF.
553  // Layer 0: predict from L and ARF; update L.
554  layer_flags[0] =
556  layer_flags[4] = layer_flags[0];
557  // Layer 1: predict from L, G, ARF; update G.
558  layer_flags[2] = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
559  layer_flags[6] = layer_flags[2];
560  // Layer 2: predict from L, G, ARF; update none.
561  layer_flags[1] = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
563  layer_flags[3] = layer_flags[1];
564  layer_flags[5] = layer_flags[1];
565  layer_flags[7] = layer_flags[1];
566  break;
567  }
568  }
569 }
570 
571 int main(int argc, char **argv) {
572  VpxVideoWriter *outfile[VPX_TS_MAX_LAYERS] = { NULL };
573  vpx_codec_ctx_t codec;
575  int frame_cnt = 0;
576  vpx_image_t raw;
577  vpx_codec_err_t res;
578  unsigned int width;
579  unsigned int height;
580  uint32_t error_resilient = 0;
581  int speed;
582  int frame_avail;
583  int got_data;
584  int flags = 0;
585  unsigned int i;
586  int pts = 0; // PTS starts at 0.
587  int frame_duration = 1; // 1 timebase tick per frame.
588  int layering_mode = 0;
589  int layer_flags[VPX_TS_MAX_PERIODICITY] = { 0 };
590  int flag_periodicity = 1;
591 #if ROI_MAP
592  vpx_roi_map_t roi;
593 #endif
594  vpx_svc_layer_id_t layer_id = { 0, 0 };
595  const VpxInterface *encoder = NULL;
596  FILE *infile = NULL;
597  struct RateControlMetrics rc;
598  int64_t cx_time = 0;
599  const int min_args_base = 13;
600 #if CONFIG_VP9_HIGHBITDEPTH
601  vpx_bit_depth_t bit_depth = VPX_BITS_8;
602  int input_bit_depth = 8;
603  const int min_args = min_args_base + 1;
604 #else
605  const int min_args = min_args_base;
606 #endif // CONFIG_VP9_HIGHBITDEPTH
607  double sum_bitrate = 0.0;
608  double sum_bitrate2 = 0.0;
609  double framerate = 30.0;
610 
611  zero(rc.layer_target_bitrate);
612 
613  exec_name = argv[0];
614  // Check usage and arguments.
615  if (argc < min_args) {
616 #if CONFIG_VP9_HIGHBITDEPTH
617  die("Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
618  "<rate_num> <rate_den> <speed> <frame_drop_threshold> "
619  "<error_resilient> <threads> <mode> "
620  "<Rate_0> ... <Rate_nlayers-1> <bit-depth> \n",
621  argv[0]);
622 #else
623  die("Usage: %s <infile> <outfile> <codec_type(vp8/vp9)> <width> <height> "
624  "<rate_num> <rate_den> <speed> <frame_drop_threshold> "
625  "<error_resilient> <threads> <mode> "
626  "<Rate_0> ... <Rate_nlayers-1> \n",
627  argv[0]);
628 #endif // CONFIG_VP9_HIGHBITDEPTH
629  }
630 
631  encoder = get_vpx_encoder_by_name(argv[3]);
632  if (!encoder) die("Unsupported codec.");
633 
634  printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
635 
636  width = (unsigned int)strtoul(argv[4], NULL, 0);
637  height = (unsigned int)strtoul(argv[5], NULL, 0);
638  if (width < 16 || width % 2 || height < 16 || height % 2) {
639  die("Invalid resolution: %d x %d", width, height);
640  }
641 
642  layering_mode = (int)strtol(argv[12], NULL, 0);
643  if (layering_mode < 0 || layering_mode > 13) {
644  die("Invalid layering mode (0..12) %s", argv[12]);
645  }
646 
647  if (argc != min_args + mode_to_num_layers[layering_mode]) {
648  die("Invalid number of arguments");
649  }
650 
651 #if CONFIG_VP9_HIGHBITDEPTH
652  switch (strtol(argv[argc - 1], NULL, 0)) {
653  case 8:
654  bit_depth = VPX_BITS_8;
655  input_bit_depth = 8;
656  break;
657  case 10:
658  bit_depth = VPX_BITS_10;
659  input_bit_depth = 10;
660  break;
661  case 12:
662  bit_depth = VPX_BITS_12;
663  input_bit_depth = 12;
664  break;
665  default: die("Invalid bit depth (8, 10, 12) %s", argv[argc - 1]);
666  }
667  if (!vpx_img_alloc(
668  &raw, bit_depth == VPX_BITS_8 ? VPX_IMG_FMT_I420 : VPX_IMG_FMT_I42016,
669  width, height, 32)) {
670  die("Failed to allocate image", width, height);
671  }
672 #else
673  if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, width, height, 32)) {
674  die("Failed to allocate image", width, height);
675  }
676 #endif // CONFIG_VP9_HIGHBITDEPTH
677 
678  // Populate encoder configuration.
679  res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
680  if (res) {
681  printf("Failed to get config: %s\n", vpx_codec_err_to_string(res));
682  return EXIT_FAILURE;
683  }
684 
685  // Update the default configuration with our settings.
686  cfg.g_w = width;
687  cfg.g_h = height;
688 
689 #if CONFIG_VP9_HIGHBITDEPTH
690  if (bit_depth != VPX_BITS_8) {
691  cfg.g_bit_depth = bit_depth;
692  cfg.g_input_bit_depth = input_bit_depth;
693  cfg.g_profile = 2;
694  }
695 #endif // CONFIG_VP9_HIGHBITDEPTH
696 
697  // Timebase format e.g. 30fps: numerator=1, demoninator = 30.
698  cfg.g_timebase.num = (int)strtol(argv[6], NULL, 0);
699  cfg.g_timebase.den = (int)strtol(argv[7], NULL, 0);
700 
701  speed = (int)strtol(argv[8], NULL, 0);
702  if (speed < 0) {
703  die("Invalid speed setting: must be positive");
704  }
705 
706  for (i = min_args_base;
707  (int)i < min_args_base + mode_to_num_layers[layering_mode]; ++i) {
708  rc.layer_target_bitrate[i - 13] = (int)strtol(argv[i], NULL, 0);
709  if (strncmp(encoder->name, "vp8", 3) == 0)
710  cfg.ts_target_bitrate[i - 13] = rc.layer_target_bitrate[i - 13];
711  else if (strncmp(encoder->name, "vp9", 3) == 0)
712  cfg.layer_target_bitrate[i - 13] = rc.layer_target_bitrate[i - 13];
713  }
714 
715  // Real time parameters.
716  cfg.rc_dropframe_thresh = (unsigned int)strtoul(argv[9], NULL, 0);
717  cfg.rc_end_usage = VPX_CBR;
718  cfg.rc_min_quantizer = 2;
719  cfg.rc_max_quantizer = 56;
720  if (strncmp(encoder->name, "vp9", 3) == 0) cfg.rc_max_quantizer = 52;
721  cfg.rc_undershoot_pct = 50;
722  cfg.rc_overshoot_pct = 50;
723  cfg.rc_buf_initial_sz = 600;
724  cfg.rc_buf_optimal_sz = 600;
725  cfg.rc_buf_sz = 1000;
726 
727  // Disable dynamic resizing by default.
728  cfg.rc_resize_allowed = 0;
729 
730  // Use 1 thread as default.
731  cfg.g_threads = (unsigned int)strtoul(argv[11], NULL, 0);
732 
733  error_resilient = (uint32_t)strtoul(argv[10], NULL, 0);
734  if (error_resilient != 0 && error_resilient != 1) {
735  die("Invalid value for error resilient (0, 1): %d.", error_resilient);
736  }
737  // Enable error resilient mode.
738  cfg.g_error_resilient = error_resilient;
739  cfg.g_lag_in_frames = 0;
740  cfg.kf_mode = VPX_KF_AUTO;
741 
742  // Disable automatic keyframe placement.
743  cfg.kf_min_dist = cfg.kf_max_dist = 3000;
744 
746 
747  set_temporal_layer_pattern(layering_mode, &cfg, layer_flags,
748  &flag_periodicity);
749 
750  set_rate_control_metrics(&rc, &cfg);
751 
752  // Target bandwidth for the whole stream.
753  // Set to layer_target_bitrate for highest layer (total bitrate).
754  cfg.rc_target_bitrate = rc.layer_target_bitrate[cfg.ts_number_layers - 1];
755 
756  // Open input file.
757  if (!(infile = fopen(argv[1], "rb"))) {
758  die("Failed to open %s for reading", argv[1]);
759  }
760 
761  framerate = cfg.g_timebase.den / cfg.g_timebase.num;
762  // Open an output file for each stream.
763  for (i = 0; i < cfg.ts_number_layers; ++i) {
764  char file_name[PATH_MAX];
765  VpxVideoInfo info;
766  info.codec_fourcc = encoder->fourcc;
767  info.frame_width = cfg.g_w;
768  info.frame_height = cfg.g_h;
769  info.time_base.numerator = cfg.g_timebase.num;
770  info.time_base.denominator = cfg.g_timebase.den;
771 
772  snprintf(file_name, sizeof(file_name), "%s_%d.ivf", argv[2], i);
773  outfile[i] = vpx_video_writer_open(file_name, kContainerIVF, &info);
774  if (!outfile[i]) die("Failed to open %s for writing", file_name);
775 
776  assert(outfile[i] != NULL);
777  }
778  // No spatial layers in this encoder.
779  cfg.ss_number_layers = 1;
780 
781 // Initialize codec.
782 #if CONFIG_VP9_HIGHBITDEPTH
783  if (vpx_codec_enc_init(
784  &codec, encoder->codec_interface(), &cfg,
785  bit_depth == VPX_BITS_8 ? 0 : VPX_CODEC_USE_HIGHBITDEPTH))
786 #else
787  if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0))
788 #endif // CONFIG_VP9_HIGHBITDEPTH
789  die_codec(&codec, "Failed to initialize encoder");
790 
791  if (strncmp(encoder->name, "vp8", 3) == 0) {
792  vpx_codec_control(&codec, VP8E_SET_CPUUSED, -speed);
793  vpx_codec_control(&codec, VP8E_SET_NOISE_SENSITIVITY, kVp8DenoiserOff);
796 #if ROI_MAP
797  set_roi_map(encoder->name, &cfg, &roi);
798  if (vpx_codec_control(&codec, VP8E_SET_ROI_MAP, &roi))
799  die_codec(&codec, "Failed to set ROI map");
800 #endif
801 
802  } else if (strncmp(encoder->name, "vp9", 3) == 0) {
803  vpx_svc_extra_cfg_t svc_params;
804  memset(&svc_params, 0, sizeof(svc_params));
805  vpx_codec_control(&codec, VP8E_SET_CPUUSED, speed);
810  vpx_codec_control(&codec, VP9E_SET_NOISE_SENSITIVITY, kVp9DenoiserOff);
814 #if ROI_MAP
815  set_roi_map(encoder->name, &cfg, &roi);
816  if (vpx_codec_control(&codec, VP9E_SET_ROI_MAP, &roi))
817  die_codec(&codec, "Failed to set ROI map");
819 #endif
820  // TODO(marpan/jianj): There is an issue with row-mt for low resolutons at
821  // high speed settings, disable its use for those cases for now.
822  if (cfg.g_threads > 1 && ((cfg.g_w > 320 && cfg.g_h > 240) || speed < 7))
824  else
826  if (vpx_codec_control(&codec, VP9E_SET_SVC, layering_mode > 0 ? 1 : 0))
827  die_codec(&codec, "Failed to set SVC");
828  for (i = 0; i < cfg.ts_number_layers; ++i) {
829  svc_params.max_quantizers[i] = cfg.rc_max_quantizer;
830  svc_params.min_quantizers[i] = cfg.rc_min_quantizer;
831  }
832  svc_params.scaling_factor_num[0] = cfg.g_h;
833  svc_params.scaling_factor_den[0] = cfg.g_h;
834  vpx_codec_control(&codec, VP9E_SET_SVC_PARAMETERS, &svc_params);
835  }
836  if (strncmp(encoder->name, "vp8", 3) == 0) {
838  }
840  // This controls the maximum target size of the key frame.
841  // For generating smaller key frames, use a smaller max_intra_size_pct
842  // value, like 100 or 200.
843  {
844  const int max_intra_size_pct = 1000;
846  max_intra_size_pct);
847  }
848 
849  frame_avail = 1;
850  while (frame_avail || got_data) {
851  struct vpx_usec_timer timer;
852  vpx_codec_iter_t iter = NULL;
853  const vpx_codec_cx_pkt_t *pkt;
854  // Update the temporal layer_id. No spatial layers in this test.
855  layer_id.spatial_layer_id = 0;
856  layer_id.temporal_layer_id =
857  cfg.ts_layer_id[frame_cnt % cfg.ts_periodicity];
858  if (strncmp(encoder->name, "vp9", 3) == 0) {
859  vpx_codec_control(&codec, VP9E_SET_SVC_LAYER_ID, &layer_id);
860  } else if (strncmp(encoder->name, "vp8", 3) == 0) {
862  layer_id.temporal_layer_id);
863  }
864  flags = layer_flags[frame_cnt % flag_periodicity];
865  if (layering_mode == 0) flags = 0;
866  frame_avail = vpx_img_read(&raw, infile);
867  if (frame_avail) ++rc.layer_input_frames[layer_id.temporal_layer_id];
868  vpx_usec_timer_start(&timer);
869  if (vpx_codec_encode(&codec, frame_avail ? &raw : NULL, pts, 1, flags,
870  VPX_DL_REALTIME)) {
871  die_codec(&codec, "Failed to encode frame");
872  }
873  vpx_usec_timer_mark(&timer);
874  cx_time += vpx_usec_timer_elapsed(&timer);
875  // Reset KF flag.
876  if (layering_mode != 7) {
877  layer_flags[0] &= ~VPX_EFLAG_FORCE_KF;
878  }
879  got_data = 0;
880  while ((pkt = vpx_codec_get_cx_data(&codec, &iter))) {
881  got_data = 1;
882  switch (pkt->kind) {
884  for (i = cfg.ts_layer_id[frame_cnt % cfg.ts_periodicity];
885  i < cfg.ts_number_layers; ++i) {
886  vpx_video_writer_write_frame(outfile[i], pkt->data.frame.buf,
887  pkt->data.frame.sz, pts);
888  ++rc.layer_tot_enc_frames[i];
889  rc.layer_encoding_bitrate[i] += 8.0 * pkt->data.frame.sz;
890  // Keep count of rate control stats per layer (for non-key frames).
891  if (i == cfg.ts_layer_id[frame_cnt % cfg.ts_periodicity] &&
892  !(pkt->data.frame.flags & VPX_FRAME_IS_KEY)) {
893  rc.layer_avg_frame_size[i] += 8.0 * pkt->data.frame.sz;
894  rc.layer_avg_rate_mismatch[i] +=
895  fabs(8.0 * pkt->data.frame.sz - rc.layer_pfb[i]) /
896  rc.layer_pfb[i];
897  ++rc.layer_enc_frames[i];
898  }
899  }
900  // Update for short-time encoding bitrate states, for moving window
901  // of size rc->window, shifted by rc->window / 2.
902  // Ignore first window segment, due to key frame.
903  if (frame_cnt > rc.window_size) {
904  sum_bitrate += 0.001 * 8.0 * pkt->data.frame.sz * framerate;
905  if (frame_cnt % rc.window_size == 0) {
906  rc.window_count += 1;
907  rc.avg_st_encoding_bitrate += sum_bitrate / rc.window_size;
908  rc.variance_st_encoding_bitrate +=
909  (sum_bitrate / rc.window_size) *
910  (sum_bitrate / rc.window_size);
911  sum_bitrate = 0.0;
912  }
913  }
914  // Second shifted window.
915  if (frame_cnt > rc.window_size + rc.window_size / 2) {
916  sum_bitrate2 += 0.001 * 8.0 * pkt->data.frame.sz * framerate;
917  if (frame_cnt > 2 * rc.window_size &&
918  frame_cnt % rc.window_size == 0) {
919  rc.window_count += 1;
920  rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
921  rc.variance_st_encoding_bitrate +=
922  (sum_bitrate2 / rc.window_size) *
923  (sum_bitrate2 / rc.window_size);
924  sum_bitrate2 = 0.0;
925  }
926  }
927  break;
928  default: break;
929  }
930  }
931  ++frame_cnt;
932  pts += frame_duration;
933  }
934  fclose(infile);
935  printout_rate_control_summary(&rc, &cfg, frame_cnt);
936  printf("\n");
937  printf("Frame cnt and encoding time/FPS stats for encoding: %d %f %f \n",
938  frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
939  1000000 * (double)frame_cnt / (double)cx_time);
940 
941  if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
942 
943  // Try to rewrite the output file headers with the actual frame count.
944  for (i = 0; i < cfg.ts_number_layers; ++i) vpx_video_writer_close(outfile[i]);
945 
946  vpx_img_free(&raw);
947 #if ROI_MAP
948  free(roi.roi_map);
949 #endif
950  return EXIT_SUCCESS;
951 }
unsigned int rc_buf_initial_sz
Decoder Buffer Initial Size.
Definition: vpx_encoder.h:556
int min_quantizers[12]
Definition: vpx_encoder.h:719
unsigned char * roi_map
Definition: vp8cx.h:674
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
#define VP8_EFLAG_NO_REF_LAST
Don&#39;t reference the last frame.
Definition: vp8cx.h:58
#define VP8_EFLAG_NO_UPD_GF
Don&#39;t update the golden frame.
Definition: vp8cx.h:88
Image Descriptor.
Definition: vpx_image.h:88
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.
const char * vpx_codec_err_to_string(vpx_codec_err_t err)
Convert error number to printable string.
int delta_q[8]
Definition: vp8cx.h:678
#define VPX_TS_MAX_LAYERS
Definition: vpx_encoder.h:40
Codec control function to set content type.
Definition: vp8cx.h:457
struct vpx_rational g_timebase
Stream timebase units.
Definition: vpx_encoder.h:354
Definition: vpx_encoder.h:241
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
unsigned int cols
Definition: vp8cx.h:676
unsigned int rc_buf_sz
Decoder Buffer Size.
Definition: vpx_encoder.h:547
#define VP8_EFLAG_NO_REF_GF
Don&#39;t reference the golden frame.
Definition: vp8cx.h:66
unsigned int g_input_bit_depth
Bit-depth of the input frames.
Definition: vpx_encoder.h:340
enum vpx_kf_mode kf_mode
Keyframe placement mode.
Definition: vpx_encoder.h:612
int den
Definition: vpx_encoder.h:228
vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img, vpx_codec_pts_t pts, unsigned long duration, vpx_enc_frame_flags_t flags, unsigned long deadline)
Encode a frame.
unsigned int rc_max_quantizer
Maximum (Worst Quality) Quantizer.
Definition: vpx_encoder.h:498
Codec control function to pass an ROI map to encoder.
Definition: vp8cx.h:130
unsigned int rc_min_quantizer
Minimum (Best Quality) Quantizer.
Definition: vpx_encoder.h:488
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
Definition: vpx_encoder.h:256
Codec control function to set row level multi-threading.
Definition: vp8cx.h:564
int spatial_layer_id
Definition: vp8cx.h:747
Codec control function to set Max data rate for Intra frames.
Definition: vp8cx.h:251
#define VPX_CODEC_USE_HIGHBITDEPTH
Definition: vpx_encoder.h:96
Encoder output packet.
Definition: vpx_encoder.h:165
unsigned int rc_overshoot_pct
Rate control adaptation overshoot control.
Definition: vpx_encoder.h:532
Codec control function to set parameters for SVC.
Definition: vp8cx.h:438
unsigned int ts_rate_decimator[5]
Frame rate decimation factor for each temporal layer.
Definition: vpx_encoder.h:674
unsigned int rc_buf_optimal_sz
Decoder Buffer Optimal Size.
Definition: vpx_encoder.h:565
unsigned int kf_min_dist
Keyframe minimum interval.
Definition: vpx_encoder.h:621
unsigned int g_profile
Bitstream profile to use.
Definition: vpx_encoder.h:306
Codec control function to set number of tile columns.
Definition: vp8cx.h:345
unsigned int ts_layer_id[16]
Template defining the membership of frames to temporal layers.
Definition: vpx_encoder.h:692
struct vpx_codec_cx_pkt::@1::@2 frame
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:55
int scaling_factor_num[12]
Definition: vpx_encoder.h:720
unsigned int g_w
Width of the frame.
Definition: vpx_encoder.h:315
unsigned int static_threshold[4]
Definition: vp8cx.h:684
unsigned int ts_target_bitrate[5]
Target bitrate for each temporal layer.
Definition: vpx_encoder.h:667
enum vpx_bit_depth vpx_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
unsigned int rc_undershoot_pct
Rate control adaptation undershoot control.
Definition: vpx_encoder.h:517
Codec control function to set adaptive quantization mode.
Definition: vp8cx.h:392
int skip[8]
Definition: vp8cx.h:681
unsigned int g_h
Height of the frame.
Definition: vpx_encoder.h:324
int delta_lf[8]
Definition: vp8cx.h:679
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
Boost percentage for Golden Frame in CBR mode.
Definition: vp8cx.h:595
vp9 svc layer parameters
Definition: vp8cx.h:746
Codec control function to set the temporal layer id.
Definition: vp8cx.h:298
#define VP8_EFLAG_NO_UPD_LAST
Don&#39;t update the last frame.
Definition: vp8cx.h:81
void vpx_img_free(vpx_image_t *img)
Close an image descriptor.
Codec control function to set the number of token partitions.
Definition: vp8cx.h:188
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
control function to set noise sensitivity
Definition: vp8cx.h:170
Definition: vpx_codec.h:220
int ref_frame[8]
Definition: vp8cx.h:682
Boost percentage for Golden Frame in CBR mode.
Definition: vp8cx.h:287
unsigned int g_threads
Maximum number of threads to use.
Definition: vpx_encoder.h:296
unsigned int ss_number_layers
Number of spatial coding layers.
Definition: vpx_encoder.h:640
Codec control function to pass an ROI map to encoder.
Definition: vp8cx.h:430
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.
#define vpx_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for vpx_codec_enc_init_ver()
Definition: vpx_encoder.h:757
Codec control function to set encoder screen content mode.
Definition: vp8cx.h:306
unsigned int rc_resize_allowed
Enable/disable spatial resampling, if supported by the codec.
Definition: vpx_encoder.h:414
Bypass mode. Used when application needs to control temporal layering. This will only work when the n...
Definition: vp8cx.h:652
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
int temporal_layer_id
Definition: vp8cx.h:748
Codec control function to enable/disable periodic Q boost.
Definition: vp8cx.h:407
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.
#define VPX_TS_MAX_PERIODICITY
Definition: vpx_encoder.h:37
Codec control function to turn on/off SVC in encoder.
Definition: vp8cx.h:424
#define vpx_codec_control(ctx, id, data)
vpx_codec_control wrapper macro
Definition: vpx_codec.h:404
unsigned int ts_periodicity
Length of the sequence defining frame temporal layer membership.
Definition: vpx_encoder.h:683
#define VP8_EFLAG_NO_REF_ARF
Don&#39;t reference the alternate reference frame.
Definition: vp8cx.h:74
vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx)
Destroy a codec instance.
unsigned int rows
Definition: vp8cx.h:675
Codec control function to enable frame parallel decoding feature.
Definition: vp8cx.h:379
Definition: vpx_codec.h:218
int scaling_factor_den[12]
Definition: vpx_encoder.h:721
Codec control function to set the threshold for MBs treated static.
Definition: vp8cx.h:182
#define VPX_FRAME_IS_KEY
Definition: vpx_encoder.h:122
Definition: vpx_codec.h:219
#define VPX_EFLAG_FORCE_KF
Definition: vpx_encoder.h:268
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:187
vpx region of interest map
Definition: vp8cx.h:669
Definition: vpx_encoder.h:153
int max_quantizers[12]
Definition: vpx_encoder.h:718
vp9 svc extra configure parameters
Definition: vpx_encoder.h:717
vpx_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition: vpx_encoder.h:362
#define VP8_EFLAG_NO_UPD_ARF
Don&#39;t update the alternate reference frame.
Definition: vp8cx.h:95
#define VP8_EFLAG_NO_UPD_ENTROPY
Disable entropy update.
Definition: vp8cx.h:116
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
Codec context structure.
Definition: vpx_codec.h:197