WebM 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_VPX_ENCODER_H_
11 #define VPX_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 VPX_MAX_LAYERS 12 // 3 temporal + 4 spatial layers are allowed.
44 
46 #define VPX_SS_MAX_LAYERS 5
47 
49 #define VPX_SS_DEFAULT_LAYERS 1
50 
59 #define VPX_ENCODER_ABI_VERSION \
60  (14 + VPX_CODEC_ABI_VERSION)
71 #define VPX_CODEC_CAP_PSNR 0x10000
78 #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
79 
87 #define VPX_CODEC_USE_PSNR 0x10000
89 #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000
90 #define VPX_CODEC_USE_HIGHBITDEPTH 0x40000
96 typedef struct vpx_fixed_buf {
97  void *buf;
98  size_t sz;
106 typedef int64_t vpx_codec_pts_t;
107 
115 typedef uint32_t vpx_codec_frame_flags_t;
116 #define VPX_FRAME_IS_KEY 0x1
119 #define VPX_FRAME_IS_DROPPABLE 0x2
121 #define VPX_FRAME_IS_INVISIBLE 0x4
123 #define VPX_FRAME_IS_FRAGMENT 0x8
124 
131 typedef uint32_t vpx_codec_er_flags_t;
133 #define VPX_ERROR_RESILIENT_DEFAULT 0x1
138 #define VPX_ERROR_RESILIENT_PARTITIONS 0x2
139 
151  VPX_CODEC_CUSTOM_PKT = 256
152 };
153 
159 typedef struct vpx_codec_cx_pkt {
161  union {
162  struct {
163  void *buf;
164  size_t sz;
168  unsigned long duration;
176  unsigned int width[VPX_SS_MAX_LAYERS];
177  unsigned int height[VPX_SS_MAX_LAYERS];
181  } frame;
184  struct vpx_psnr_pkt {
185  unsigned int samples[4];
186  uint64_t sse[4];
187  double psnr[4];
188  } psnr;
191  /* This packet size is fixed to allow codecs to extend this
192  * interface without having to manage storage for raw packets,
193  * i.e., if it's smaller than 128 bytes, you can store in the
194  * packet list directly.
195  */
196  char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)];
197  } data;
206  void *user_data);
207 
211  void *user_priv;
213 
218 typedef struct vpx_rational {
219  int num;
220  int den;
224 typedef enum vpx_enc_pass {
229 
236 };
237 
249  VPX_KF_DISABLED = 0
250 };
251 
260 #define VPX_EFLAG_FORCE_KF (1 << 0)
268 typedef struct vpx_codec_enc_cfg {
269  /*
270  * generic settings (g)
271  */
272 
277  unsigned int g_usage;
278 
285  unsigned int g_threads;
286 
295  unsigned int g_profile;
304  unsigned int g_w;
305 
313  unsigned int g_h;
314 
322 
329  unsigned int g_input_bit_depth;
330 
343  struct vpx_rational g_timebase;
344 
352 
358  enum vpx_enc_pass g_pass;
359 
372  unsigned int g_lag_in_frames;
373 
374  /*
375  * rate control settings (rc)
376  */
377 
391  unsigned int rc_dropframe_thresh;
392 
400  unsigned int rc_resize_allowed;
401 
407  unsigned int rc_scaled_width;
408 
414  unsigned int rc_scaled_height;
415 
422  unsigned int rc_resize_up_thresh;
423 
430  unsigned int rc_resize_down_thresh;
431 
441 
448 
455 
460  unsigned int rc_target_bitrate;
461 
462  /*
463  * quantizer settings
464  */
465 
473  unsigned int rc_min_quantizer;
474 
482  unsigned int rc_max_quantizer;
483 
484  /*
485  * bitrate tolerance
486  */
487 
501  unsigned int rc_undershoot_pct;
502 
516  unsigned int rc_overshoot_pct;
517 
518  /*
519  * decoder buffer model parameters
520  */
521 
531  unsigned int rc_buf_sz;
532 
540  unsigned int rc_buf_initial_sz;
541 
549  unsigned int rc_buf_optimal_sz;
550 
551  /*
552  * 2 pass rate control parameters
553  */
554 
563  unsigned int rc_2pass_vbr_bias_pct;
564 
571 
578 
585 
586  /*
587  * keyframing settings (kf)
588  */
589 
596  enum vpx_kf_mode kf_mode;
597 
605  unsigned int kf_min_dist;
606 
614  unsigned int kf_max_dist;
615 
616  /*
617  * Spatial scalability settings (ss)
618  */
619 
624  unsigned int ss_number_layers;
625 
632 
639 
644  unsigned int ts_number_layers;
645 
652 
659 
667  unsigned int ts_periodicity;
668 
677 
685 
701 typedef struct vpx_svc_parameters {
709 
733  vpx_codec_iface_t *iface,
734  const vpx_codec_enc_cfg_t *cfg,
735  vpx_codec_flags_t flags, int ver);
736 
741 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
742  vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
743 
766  int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver);
767 
772 #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
773  vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
774  VPX_ENCODER_ABI_VERSION)
775 
796  vpx_codec_enc_cfg_t *cfg,
797  unsigned int usage);
798 
814  const vpx_codec_enc_cfg_t *cfg);
815 
828 
830 #define VPX_DL_REALTIME (1)
832 #define VPX_DL_GOOD_QUALITY (1000000)
834 #define VPX_DL_BEST_QUALITY (0)
872  vpx_codec_pts_t pts, unsigned long duration,
873  vpx_enc_frame_flags_t flags,
874  unsigned long deadline);
875 
920  const vpx_fixed_buf_t *buf,
921  unsigned int pad_before,
922  unsigned int pad_after);
923 
948  vpx_codec_iter_t *iter);
949 
963 
965 #ifdef __cplusplus
966 }
967 #endif
968 #endif // VPX_VPX_VPX_ENCODER_H_
long vpx_codec_flags_t
Initialization-time Feature Enabling.
Definition: vpx_codec.h:170
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:190
enum vpx_bit_depth vpx_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
vpx_codec_err_t
Algorithm return codes.
Definition: vpx_codec.h:93
const struct vpx_codec_iface vpx_codec_iface_t
Codec interface structure.
Definition: vpx_codec.h:177
vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, const vpx_codec_enc_cfg_t *cfg, vpx_codec_flags_t flags, int ver)
Initialize an encoder instance.
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_codec_enc_cfg vpx_codec_enc_cfg_t
Encoder configuration structure.
const vpx_image_t * vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx)
Get Preview Frame.
#define VPX_TS_MAX_LAYERS
Definition: vpx_encoder.h:40
vpx_codec_cx_pkt_kind
Encoder output packet variants.
Definition: vpx_encoder.h:146
void(* vpx_codec_enc_output_cx_pkt_cb_fn_t)(vpx_codec_cx_pkt_t *pkt, void *user_data)
Encoder return output buffer callback.
Definition: vpx_encoder.h:205
vpx_enc_pass
Multi-pass Encoding Pass.
Definition: vpx_encoder.h:224
vpx_fixed_buf_t * vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx)
Get global stream headers.
struct vpx_svc_parameters vpx_svc_extra_cfg_t
vp9 svc extra configure parameters
struct vpx_fixed_buf vpx_fixed_buf_t
Generic fixed size buffer structure.
#define VPX_TS_MAX_PERIODICITY
Definition: vpx_encoder.h:37
struct vpx_codec_enc_output_cx_cb_pair vpx_codec_priv_output_cx_pkt_cb_pair_t
Callback function pointer / user data pair storage.
#define VPX_MAX_LAYERS
Definition: vpx_encoder.h:43
uint32_t vpx_codec_er_flags_t
Error Resilient flags.
Definition: vpx_encoder.h:131
int64_t vpx_codec_pts_t
Time Stamp Type.
Definition: vpx_encoder.h:106
#define VPX_SS_MAX_LAYERS
Definition: vpx_encoder.h:46
long vpx_enc_frame_flags_t
Encoded Frame Flags.
Definition: vpx_encoder.h:259
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.
vpx_kf_mode
Keyframe placement mode.
Definition: vpx_encoder.h:246
struct vpx_codec_cx_pkt vpx_codec_cx_pkt_t
Encoder output packet.
uint32_t vpx_codec_frame_flags_t
Compressed Frame Flags.
Definition: vpx_encoder.h:115
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.
const vpx_codec_cx_pkt_t * vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter)
Encoded data iterator.
struct vpx_rational vpx_rational_t
Rational Number.
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.
vpx_rc_mode
Rate control mode.
Definition: vpx_encoder.h:231
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.
@ VPX_CODEC_PSNR_PKT
Definition: vpx_encoder.h:150
@ VPX_CODEC_CX_FRAME_PKT
Definition: vpx_encoder.h:147
@ VPX_CODEC_STATS_PKT
Definition: vpx_encoder.h:148
@ VPX_CODEC_CUSTOM_PKT
Definition: vpx_encoder.h:151
@ VPX_CODEC_FPMB_STATS_PKT
Definition: vpx_encoder.h:149
@ VPX_RC_LAST_PASS
Definition: vpx_encoder.h:227
@ VPX_RC_ONE_PASS
Definition: vpx_encoder.h:225
@ VPX_RC_FIRST_PASS
Definition: vpx_encoder.h:226
@ VPX_KF_DISABLED
Definition: vpx_encoder.h:249
@ VPX_KF_FIXED
Definition: vpx_encoder.h:247
@ VPX_KF_AUTO
Definition: vpx_encoder.h:248
@ VPX_Q
Definition: vpx_encoder.h:235
@ VPX_CQ
Definition: vpx_encoder.h:234
@ VPX_CBR
Definition: vpx_encoder.h:233
@ VPX_VBR
Definition: vpx_encoder.h:232
Codec context structure.
Definition: vpx_codec.h:200
Encoder output packet.
Definition: vpx_encoder.h:159
char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)]
Definition: vpx_encoder.h:196
vpx_codec_frame_flags_t flags
Definition: vpx_encoder.h:169
vpx_fixed_buf_t twopass_stats
Definition: vpx_encoder.h:182
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:160
unsigned int samples[4]
Definition: vpx_encoder.h:185
double psnr[4]
Definition: vpx_encoder.h:187
unsigned int width[5]
Width and height of frames in this packet. VP8 will only use the first one.
Definition: vpx_encoder.h:176
struct vpx_codec_cx_pkt::@1::@2 frame
uint8_t spatial_layer_encoded[5]
Flag to indicate if spatial layer frame in this packet is encoded or dropped. VP8 will always be set ...
Definition: vpx_encoder.h:180
vpx_fixed_buf_t firstpass_mb_stats
Definition: vpx_encoder.h:183
size_t sz
Definition: vpx_encoder.h:164
void * buf
Definition: vpx_encoder.h:163
vpx_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition: vpx_encoder.h:166
vpx_fixed_buf_t raw
Definition: vpx_encoder.h:189
unsigned int height[5]
Definition: vpx_encoder.h:177
int partition_id
the partition id defines the decoding order of the partitions. Only applicable when "output partition...
Definition: vpx_encoder.h:173
uint64_t sse[4]
Definition: vpx_encoder.h:186
unsigned long duration
duration to show frame (in timebase units)
Definition: vpx_encoder.h:168
union vpx_codec_cx_pkt::@1 data
Encoder configuration structure.
Definition: vpx_encoder.h:268
unsigned int rc_resize_allowed
Enable/disable spatial resampling, if supported by the codec.
Definition: vpx_encoder.h:400
int temporal_layering_mode
Temporal layering mode indicating which temporal layering scheme to use.
Definition: vpx_encoder.h:693
unsigned int kf_min_dist
Keyframe minimum interval.
Definition: vpx_encoder.h:605
unsigned int rc_min_quantizer
Minimum (Best Quality) Quantizer.
Definition: vpx_encoder.h:473
unsigned int ts_number_layers
Number of temporal coding layers.
Definition: vpx_encoder.h:644
vpx_fixed_buf_t rc_twopass_stats_in
Two-pass stats buffer.
Definition: vpx_encoder.h:447
unsigned int rc_resize_down_thresh
Spatial resampling down watermark.
Definition: vpx_encoder.h:430
unsigned int ss_number_layers
Number of spatial coding layers.
Definition: vpx_encoder.h:624
unsigned int rc_2pass_vbr_bias_pct
Two-pass mode CBR/VBR bias.
Definition: vpx_encoder.h:563
unsigned int rc_2pass_vbr_minsection_pct
Two-pass mode per-GOP minimum bitrate.
Definition: vpx_encoder.h:570
int ss_enable_auto_alt_ref[5]
Enable auto alt reference flags for each spatial layer.
Definition: vpx_encoder.h:631
unsigned int rc_scaled_width
Internal coded frame width.
Definition: vpx_encoder.h:407
unsigned int g_profile
Bitstream profile to use.
Definition: vpx_encoder.h:295
unsigned int layer_target_bitrate[12]
Target bitrate for each spatial/temporal layer.
Definition: vpx_encoder.h:684
unsigned int g_h
Height of the frame.
Definition: vpx_encoder.h:313
enum vpx_kf_mode kf_mode
Keyframe placement mode.
Definition: vpx_encoder.h:596
unsigned int ts_layer_id[16]
Template defining the membership of frames to temporal layers.
Definition: vpx_encoder.h:676
vpx_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition: vpx_encoder.h:351
unsigned int ts_periodicity
Length of the sequence defining frame temporal layer membership.
Definition: vpx_encoder.h:667
unsigned int rc_overshoot_pct
Rate control adaptation overshoot control.
Definition: vpx_encoder.h:516
vpx_fixed_buf_t rc_firstpass_mb_stats_in
first pass mb stats buffer.
Definition: vpx_encoder.h:454
unsigned int rc_scaled_height
Internal coded frame height.
Definition: vpx_encoder.h:414
unsigned int g_usage
Deprecated: Algorithm specific "usage" value.
Definition: vpx_encoder.h:277
unsigned int g_w
Width of the frame.
Definition: vpx_encoder.h:304
unsigned int ss_target_bitrate[5]
Target bitrate for each spatial layer.
Definition: vpx_encoder.h:638
unsigned int rc_buf_sz
Decoder Buffer Size.
Definition: vpx_encoder.h:531
unsigned int rc_dropframe_thresh
Temporal resampling configuration, if supported by the codec.
Definition: vpx_encoder.h:391
struct vpx_rational g_timebase
Stream timebase units.
Definition: vpx_encoder.h:343
enum vpx_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: vpx_encoder.h:358
unsigned int rc_resize_up_thresh
Spatial resampling up watermark.
Definition: vpx_encoder.h:422
unsigned int rc_max_quantizer
Maximum (Worst Quality) Quantizer.
Definition: vpx_encoder.h:482
unsigned int rc_2pass_vbr_corpus_complexity
Two-pass corpus vbr mode complexity control Used only in VP9: A value representing the corpus midpoin...
Definition: vpx_encoder.h:584
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition: vpx_encoder.h:372
enum vpx_rc_mode rc_end_usage
Rate control algorithm to use.
Definition: vpx_encoder.h:440
unsigned int rc_buf_initial_sz
Decoder Buffer Initial Size.
Definition: vpx_encoder.h:540
vpx_bit_depth_t g_bit_depth
Bit-depth of the codec.
Definition: vpx_encoder.h:321
unsigned int rc_buf_optimal_sz
Decoder Buffer Optimal Size.
Definition: vpx_encoder.h:549
unsigned int rc_2pass_vbr_maxsection_pct
Two-pass mode per-GOP maximum bitrate.
Definition: vpx_encoder.h:577
unsigned int rc_target_bitrate
Target data rate.
Definition: vpx_encoder.h:460
unsigned int ts_target_bitrate[5]
Target bitrate for each temporal layer.
Definition: vpx_encoder.h:651
unsigned int g_input_bit_depth
Bit-depth of the input frames.
Definition: vpx_encoder.h:329
unsigned int rc_undershoot_pct
Rate control adaptation undershoot control.
Definition: vpx_encoder.h:501
unsigned int ts_rate_decimator[5]
Frame rate decimation factor for each temporal layer.
Definition: vpx_encoder.h:658
unsigned int kf_max_dist
Keyframe maximum interval.
Definition: vpx_encoder.h:614
unsigned int g_threads
Maximum number of threads to use.
Definition: vpx_encoder.h:285
Callback function pointer / user data pair storage.
Definition: vpx_encoder.h:209
void * user_priv
Definition: vpx_encoder.h:211
vpx_codec_enc_output_cx_pkt_cb_fn_t output_cx_pkt
Definition: vpx_encoder.h:210
Generic fixed size buffer structure.
Definition: vpx_encoder.h:96
size_t sz
Definition: vpx_encoder.h:98
void * buf
Definition: vpx_encoder.h:97
Image Descriptor.
Definition: vpx_image.h:72
Rational Number.
Definition: vpx_encoder.h:218
int den
Definition: vpx_encoder.h:220
int num
Definition: vpx_encoder.h:219
vp9 svc extra configure parameters
Definition: vpx_encoder.h:701
int min_quantizers[12]
Definition: vpx_encoder.h:703
int scaling_factor_num[12]
Definition: vpx_encoder.h:704
int speed_per_layer[12]
Definition: vpx_encoder.h:706
int max_quantizers[12]
Definition: vpx_encoder.h:702
int scaling_factor_den[12]
Definition: vpx_encoder.h:705
int temporal_layering_mode
Definition: vpx_encoder.h:707
Describes the codec algorithm interface to applications.