WebM VP8 Codec SDK
vpx_encoder.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 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 #ifndef VPX_VPX_ENCODER_H_
11 #define VPX_VPX_ENCODER_H_
12 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include "./vpx_codec.h"
33 
37 #define VPX_TS_MAX_PERIODICITY 16
38 
40 #define VPX_TS_MAX_LAYERS 5
41 
43 #define MAX_PERIODICITY VPX_TS_MAX_PERIODICITY
44 
46 #define MAX_LAYERS VPX_TS_MAX_LAYERS
47 
49 #define VPX_SS_MAX_LAYERS 5
50 
52 #define VPX_SS_DEFAULT_LAYERS 1
53 
62 #define VPX_ENCODER_ABI_VERSION (3 + VPX_CODEC_ABI_VERSION)
74 #define VPX_CODEC_CAP_PSNR 0x10000
81 #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
82 
83 
91 #define VPX_CODEC_USE_PSNR 0x10000
92 #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000
100  typedef struct vpx_fixed_buf {
101  void *buf;
102  size_t sz;
111  typedef int64_t vpx_codec_pts_t;
113 
121  typedef uint32_t vpx_codec_frame_flags_t;
122 #define VPX_FRAME_IS_KEY 0x1
123 #define VPX_FRAME_IS_DROPPABLE 0x2
126 #define VPX_FRAME_IS_INVISIBLE 0x4
128 #define VPX_FRAME_IS_FRAGMENT 0x8
137  typedef uint32_t vpx_codec_er_flags_t;
138 #define VPX_ERROR_RESILIENT_DEFAULT 0x1
140 #define VPX_ERROR_RESILIENT_PARTITIONS 0x2
155  enum vpx_codec_cx_pkt_kind {
160 #if CONFIG_SPATIAL_SVC
161  VPX_CODEC_SPATIAL_SVC_LAYER_SIZES,
162 #endif
163  VPX_CODEC_CUSTOM_PKT = 256
164  };
165 
166 
172  typedef struct vpx_codec_cx_pkt {
174  union {
175  struct {
176  void *buf;
177  size_t sz;
180  unsigned long duration;
183  int partition_id;
190  } frame;
193  struct vpx_psnr_pkt {
194  unsigned int samples[4];
195  uint64_t sse[4];
196  double psnr[4];
197  } psnr;
198  struct vpx_fixed_buf raw;
199 #if CONFIG_SPATIAL_SVC
200  size_t layer_sizes[VPX_SS_MAX_LAYERS];
201 #endif
202 
203  /* This packet size is fixed to allow codecs to extend this
204  * interface without having to manage storage for raw packets,
205  * i.e., if it's smaller than 128 bytes, you can store in the
206  * packet list directly.
207  */
208  char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)];
209  } data;
217  typedef struct vpx_rational {
218  int num;
219  int den;
220  } vpx_rational_t;
224  enum vpx_enc_pass {
228  };
229 
232  enum vpx_rc_mode {
233  VPX_VBR,
234  VPX_CBR,
235  VPX_CQ,
236  VPX_Q,
237  };
248  enum vpx_kf_mode {
250  VPX_KF_AUTO,
251  VPX_KF_DISABLED = 0
252  };
253 
254 
262  typedef long vpx_enc_frame_flags_t;
263 #define VPX_EFLAG_FORCE_KF (1<<0)
272  typedef struct vpx_codec_enc_cfg {
273  /*
274  * generic settings (g)
275  */
284  unsigned int g_usage;
286 
293  unsigned int g_threads;
294 
295 
304  unsigned int g_profile;
315  unsigned int g_w;
316 
325  unsigned int g_h;
326 
327 
340  struct vpx_rational g_timebase;
341 
342 
349  vpx_codec_er_flags_t g_error_resilient;
350 
351 
357  enum vpx_enc_pass g_pass;
358 
359 
372  unsigned int g_lag_in_frames;
373 
374 
375  /*
376  * rate control settings (rc)
377  */
378 
395  unsigned int rc_dropframe_thresh;
396 
397 
405  unsigned int rc_resize_allowed;
406 
412  unsigned int rc_scaled_width;
413 
419  unsigned int rc_scaled_height;
420 
427  unsigned int rc_resize_up_thresh;
428 
429 
436  unsigned int rc_resize_down_thresh;
437 
438 
447  enum vpx_rc_mode rc_end_usage;
448 
455  struct vpx_fixed_buf rc_twopass_stats_in;
456 
462  struct vpx_fixed_buf rc_firstpass_mb_stats_in;
463 
468  unsigned int rc_target_bitrate;
469 
470 
471  /*
472  * quantizer settings
473  */
474 
484  unsigned int rc_min_quantizer;
485 
486 
495  unsigned int rc_max_quantizer;
496 
498  /*
499  * bitrate tolerance
500  */
501 
502 
513  unsigned int rc_undershoot_pct;
514 
515 
526  unsigned int rc_overshoot_pct;
527 
528 
529  /*
530  * decoder buffer model parameters
531  */
532 
533 
543  unsigned int rc_buf_sz;
544 
545 
553  unsigned int rc_buf_initial_sz;
554 
555 
563  unsigned int rc_buf_optimal_sz;
564 
565 
566  /*
567  * 2 pass rate control parameters
568  */
569 
570 
579  unsigned int rc_2pass_vbr_bias_pct;
587  unsigned int rc_2pass_vbr_minsection_pct;
588 
589 
595  unsigned int rc_2pass_vbr_maxsection_pct;
596 
597 
598  /*
599  * keyframing settings (kf)
600  */
601 
608  enum vpx_kf_mode kf_mode;
609 
610 
618  unsigned int kf_min_dist;
619 
620 
628  unsigned int kf_max_dist;
629 
630  /*
631  * Spatial scalability settings (ss)
632  */
633 
638  unsigned int ss_number_layers;
639 
645  int ss_enable_auto_alt_ref[VPX_SS_MAX_LAYERS];
646 
652  unsigned int ss_target_bitrate[VPX_SS_MAX_LAYERS];
653 
658  unsigned int ts_number_layers;
659 
665  unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS];
666 
672  unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS];
673 
681  unsigned int ts_periodicity;
682 
690  unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY];
717  vpx_codec_iface_t *iface,
718  vpx_codec_enc_cfg_t *cfg,
719  vpx_codec_flags_t flags,
720  int ver);
721 
722 
727 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
728  vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
729 
730 
752  vpx_codec_iface_t *iface,
753  vpx_codec_enc_cfg_t *cfg,
754  int num_enc,
755  vpx_codec_flags_t flags,
756  vpx_rational_t *dsf,
757  int ver);
758 
759 
764 #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
765  vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
766  VPX_ENCODER_ABI_VERSION)
767 
768 
789  vpx_codec_enc_cfg_t *cfg,
790  unsigned int usage);
791 
792 
808  const vpx_codec_enc_cfg_t *cfg);
809 
810 
823 
824 
825 #define VPX_DL_REALTIME (1)
827 #define VPX_DL_GOOD_QUALITY (1000000)
829 #define VPX_DL_BEST_QUALITY (0)
867  vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx,
868  const vpx_image_t *img,
869  vpx_codec_pts_t pts,
870  unsigned long duration,
871  vpx_enc_frame_flags_t flags,
872  unsigned long deadline);
873 
918  const vpx_fixed_buf_t *buf,
919  unsigned int pad_before,
920  unsigned int pad_after);
921 
922 
947  vpx_codec_iter_t *iter);
948 
949 
963 
964 
966 #ifdef __cplusplus
967 }
968 #endif
969 #endif // VPX_VPX_ENCODER_H_
970 
Rational Number.
Definition: vpx_encoder.h:230
struct vpx_fixed_buf twopass_stats
Definition: vpx_encoder.h:204
struct vpx_codec_iface vpx_codec_iface_t
Codec interface structure.
Definition: vpx_codec.h:173
vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx, const vpx_fixed_buf_t *buf, unsigned int pad_before, unsigned int pad_after)
Set compressed data output buffer.
Definition: vpx_encoder.h:249
Image Descriptor.
Definition: vpx_image.h:102
vpx_codec_pts_t pts
Definition: vpx_encoder.h:191
vpx_kf_mode
Keyframe placement mode.
Definition: vpx_encoder.h:261
#define VPX_TS_MAX_LAYERS
Definition: vpx_encoder.h:40
Definition: vpx_encoder.h:247
struct vpx_codec_enc_cfg vpx_codec_enc_cfg_t
Encoder configuration structure.
struct vpx_fixed_buf vpx_fixed_buf_t
Generic fixed size buffer structure.
struct vpx_fixed_buf raw
Definition: vpx_encoder.h:211
int den
Definition: vpx_encoder.h:232
Definition: vpx_encoder.h:170
int partition_id
Definition: vpx_encoder.h:196
vpx_enc_pass
Multi-pass Encoding Pass.
Definition: vpx_encoder.h:237
Encoder configuration structure.
Definition: vpx_encoder.h:285
Definition: vpx_encoder.h:176
Definition: vpx_encoder.h:172
Definition: vpx_encoder.h:263
Encoder output packet.
Definition: vpx_encoder.h:185
void * buf
Definition: vpx_encoder.h:102
vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx, const vpx_codec_enc_cfg_t *cfg)
Set or change configuration.
Generic fixed size buffer structure.
Definition: vpx_encoder.h:101
uint32_t vpx_codec_frame_flags_t
Compressed Frame Flags.
Definition: vpx_encoder.h:122
Definition: vpx_encoder.h:239
Definition: vpx_encoder.h:240
struct vpx_codec_cx_pkt::@1::@2 frame
#define VPX_SS_MAX_LAYERS
Definition: vpx_encoder.h:49
uint64_t sse[4]
Definition: vpx_encoder.h:208
size_t sz
Definition: vpx_encoder.h:190
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:186
long vpx_enc_frame_flags_t
Encoded Frame Flags.
Definition: vpx_encoder.h:275
int num
Definition: vpx_encoder.h:231
char pad[128-sizeof(enum vpx_codec_cx_pkt_kind)]
Definition: vpx_encoder.h:221
vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, unsigned int usage)
Get a default configuration.
long vpx_codec_flags_t
Initialization-time Feature Enabling.
Definition: vpx_codec.h:165
vpx_codec_cx_pkt_kind
Encoder output packet variants.
Definition: vpx_encoder.h:168
Definition: vpx_encoder.h:246
double psnr[4]
Definition: vpx_encoder.h:209
Definition: vpx_encoder.h:262
unsigned int samples[4]
Definition: vpx_encoder.h:207
vpx_rc_mode
Rate control mode.
Definition: vpx_encoder.h:245
vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, vpx_codec_flags_t flags, int ver)
Initialize an encoder instance.
const vpx_image_t * vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx)
Get Preview Frame.
unsigned long duration
Definition: vpx_encoder.h:193
uint32_t vpx_codec_er_flags_t
Error Resilient flags.
Definition: vpx_encoder.h:142
vpx_codec_err_t
Algorithm return codes.
Definition: vpx_codec.h:89
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
struct vpx_codec_cx_pkt vpx_codec_cx_pkt_t
Encoder output packet.
struct vpx_rational vpx_rational_t
Rational Number.
Definition: vpx_encoder.h:264
Definition: vpx_encoder.h:171
int64_t vpx_codec_pts_t
Time Stamp Type.
Definition: vpx_encoder.h:112
#define VPX_TS_MAX_PERIODICITY
Definition: vpx_encoder.h:37
vpx_fixed_buf_t * vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx)
Get global stream headers.
Definition: vpx_encoder.h:248
Describes the codec algorithm interface to applications.
vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver)
Initialize multi-encoder instance.
struct vpx_fixed_buf firstpass_mb_stats
Definition: vpx_encoder.h:205
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:188
Definition: vpx_encoder.h:169
vpx_codec_frame_flags_t flags
Definition: vpx_encoder.h:195
void * buf
Definition: vpx_encoder.h:189
Definition: vpx_encoder.h:238
Codec context structure.
Definition: vpx_codec.h:199