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 
11 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #ifndef VPX_ENCODER_H
32 #define VPX_ENCODER_H
33 #include "vpx_codec.h"
34 
38 #define VPX_TS_MAX_PERIODICITY 16
39 
41 #define VPX_TS_MAX_LAYERS 5
42 
44 #define MAX_PERIODICITY VPX_TS_MAX_PERIODICITY
45 
47 #define MAX_LAYERS VPX_TS_MAX_LAYERS
48 
57 #define VPX_ENCODER_ABI_VERSION (3 + VPX_CODEC_ABI_VERSION)
69 #define VPX_CODEC_CAP_PSNR 0x10000
76 #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
77 
78 
86 #define VPX_CODEC_USE_PSNR 0x10000
87 #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000
95  typedef struct vpx_fixed_buf {
96  void *buf;
97  size_t sz;
106  typedef int64_t vpx_codec_pts_t;
108 
116  typedef uint32_t vpx_codec_frame_flags_t;
117 #define VPX_FRAME_IS_KEY 0x1
118 #define VPX_FRAME_IS_DROPPABLE 0x2
121 #define VPX_FRAME_IS_INVISIBLE 0x4
123 #define VPX_FRAME_IS_FRAGMENT 0x8
132  typedef uint32_t vpx_codec_er_flags_t;
133 #define VPX_ERROR_RESILIENT_DEFAULT 0x1
135 #define VPX_ERROR_RESILIENT_PARTITIONS 0x2
150  enum vpx_codec_cx_pkt_kind {
154  VPX_CODEC_CUSTOM_PKT = 256
155  };
156 
157 
163  typedef struct vpx_codec_cx_pkt {
165  union {
166  struct {
167  void *buf;
168  size_t sz;
171  unsigned long duration;
174  int partition_id;
181  } frame;
183  struct vpx_psnr_pkt {
184  unsigned int samples[4];
185  uint64_t sse[4];
186  double psnr[4];
187  } psnr;
188  struct vpx_fixed_buf raw;
190  /* This packet size is fixed to allow codecs to extend this
191  * interface without having to manage storage for raw packets,
192  * i.e., if it's smaller than 128 bytes, you can store in the
193  * packet list directly.
194  */
195  char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)];
196  } data;
204  typedef struct vpx_rational {
205  int num;
206  int den;
207  } vpx_rational_t;
211  enum vpx_enc_pass {
215  };
216 
219  enum vpx_rc_mode {
220  VPX_VBR,
221  VPX_CBR,
222  VPX_CQ
223  };
234  enum vpx_kf_mode {
236  VPX_KF_AUTO,
237  VPX_KF_DISABLED = 0
238  };
239 
240 
248  typedef long vpx_enc_frame_flags_t;
249 #define VPX_EFLAG_FORCE_KF (1<<0)
258  typedef struct vpx_codec_enc_cfg {
259  /*
260  * generic settings (g)
261  */
270  unsigned int g_usage;
272 
279  unsigned int g_threads;
280 
281 
290  unsigned int g_profile;
301  unsigned int g_w;
302 
311  unsigned int g_h;
312 
313 
326  struct vpx_rational g_timebase;
327 
328 
335  vpx_codec_er_flags_t g_error_resilient;
336 
337 
343  enum vpx_enc_pass g_pass;
344 
345 
358  unsigned int g_lag_in_frames;
359 
360 
361  /*
362  * rate control settings (rc)
363  */
364 
381  unsigned int rc_dropframe_thresh;
382 
383 
391  unsigned int rc_resize_allowed;
392 
393 
400  unsigned int rc_resize_up_thresh;
401 
402 
409  unsigned int rc_resize_down_thresh;
410 
411 
420  enum vpx_rc_mode rc_end_usage;
421 
428  struct vpx_fixed_buf rc_twopass_stats_in;
429 
430 
435  unsigned int rc_target_bitrate;
436 
437 
438  /*
439  * quantizer settings
440  */
442 
451  unsigned int rc_min_quantizer;
452 
453 
462  unsigned int rc_max_quantizer;
463 
465  /*
466  * bitrate tolerance
467  */
468 
469 
480  unsigned int rc_undershoot_pct;
481 
482 
493  unsigned int rc_overshoot_pct;
494 
495 
496  /*
497  * decoder buffer model parameters
498  */
499 
500 
510  unsigned int rc_buf_sz;
511 
512 
520  unsigned int rc_buf_initial_sz;
521 
522 
530  unsigned int rc_buf_optimal_sz;
531 
532 
533  /*
534  * 2 pass rate control parameters
535  */
536 
537 
546  unsigned int rc_2pass_vbr_bias_pct;
554  unsigned int rc_2pass_vbr_minsection_pct;
555 
556 
562  unsigned int rc_2pass_vbr_maxsection_pct;
563 
564 
565  /*
566  * keyframing settings (kf)
567  */
568 
575  enum vpx_kf_mode kf_mode;
576 
577 
585  unsigned int kf_min_dist;
586 
587 
595  unsigned int kf_max_dist;
596 
597  /*
598  * Temporal scalability settings (ts)
599  */
600 
605  unsigned int ts_number_layers;
606 
611  unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS];
612 
618  unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS];
619 
627  unsigned int ts_periodicity;
628 
636  unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY];
667  vpx_codec_iface_t *iface,
668  vpx_codec_enc_cfg_t *cfg,
669  vpx_codec_flags_t flags,
670  int ver);
671 
672 
677 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
678  vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
679 
680 
706  vpx_codec_iface_t *iface,
707  vpx_codec_enc_cfg_t *cfg,
708  int num_enc,
709  vpx_codec_flags_t flags,
710  vpx_rational_t *dsf,
711  int ver);
712 
713 
718 #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
719  vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
720  VPX_ENCODER_ABI_VERSION)
721 
722 
743  vpx_codec_enc_cfg_t *cfg,
744  unsigned int usage);
745 
746 
762  const vpx_codec_enc_cfg_t *cfg);
763 
764 
777 
778 
779 #define VPX_DL_REALTIME (1)
781 #define VPX_DL_GOOD_QUALITY (1000000)
783 #define VPX_DL_BEST_QUALITY (0)
821  vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx,
822  const vpx_image_t *img,
823  vpx_codec_pts_t pts,
824  unsigned long duration,
825  vpx_enc_frame_flags_t flags,
826  unsigned long deadline);
827 
872  const vpx_fixed_buf_t *buf,
873  unsigned int pad_before,
874  unsigned int pad_after);
875 
876 
901  vpx_codec_iter_t *iter);
902 
903 
917 
918 
921 #endif
922 #ifdef __cplusplus
923 }
924 #endif
Rational Number.
Definition: vpx_encoder.h:217
struct vpx_fixed_buf twopass_stats
Definition: vpx_encoder.h:195
struct vpx_codec_iface vpx_codec_iface_t
Codec interface structure.
Definition: vpx_codec.h:174
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.
Image Descriptor.
Definition: vpx_image.h:97
vpx_codec_pts_t pts
Definition: vpx_encoder.h:182
vpx_kf_mode
Keyframe placement mode.
Definition: vpx_encoder.h:247
#define VPX_TS_MAX_LAYERS
Definition: vpx_encoder.h:41
Definition: vpx_encoder.h:234
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:201
int den
Definition: vpx_encoder.h:219
Definition: vpx_encoder.h:165
int partition_id
Definition: vpx_encoder.h:187
vpx_enc_pass
Multi-pass Encoding Pass.
Definition: vpx_encoder.h:224
Encoder configuration structure.
Definition: vpx_encoder.h:271
Definition: vpx_encoder.h:167
Definition: vpx_encoder.h:166
Definition: vpx_encoder.h:249
Encoder output packet.
Definition: vpx_encoder.h:176
void * buf
Definition: vpx_encoder.h:97
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:96
uint32_t vpx_codec_frame_flags_t
Compressed Frame Flags.
Definition: vpx_encoder.h:117
Definition: vpx_encoder.h:226
Definition: vpx_encoder.h:227
struct vpx_codec_cx_pkt::@1::@2 frame
uint64_t sse[4]
Definition: vpx_encoder.h:198
size_t sz
Definition: vpx_encoder.h:181
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:177
long vpx_enc_frame_flags_t
Encoded Frame Flags.
Definition: vpx_encoder.h:261
int num
Definition: vpx_encoder.h:218
char pad[128-sizeof(enum vpx_codec_cx_pkt_kind)]
Definition: vpx_encoder.h:208
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:163
Definition: vpx_encoder.h:233
double psnr[4]
Definition: vpx_encoder.h:199
Definition: vpx_encoder.h:248
unsigned int samples[4]
Definition: vpx_encoder.h:197
vpx_rc_mode
Rate control mode.
Definition: vpx_encoder.h:232
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:184
uint32_t vpx_codec_er_flags_t
Error Resilient flags.
Definition: vpx_encoder.h:137
vpx_codec_err_t
Algorithm return codes.
Definition: vpx_codec.h:88
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:250
int64_t vpx_codec_pts_t
Time Stamp Type.
Definition: vpx_encoder.h:107
#define VPX_TS_MAX_PERIODICITY
Definition: vpx_encoder.h:38
vpx_fixed_buf_t * vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx)
Get global stream headers.
Definition: vpx_encoder.h:235
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.
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:189
Definition: vpx_encoder.h:164
vpx_codec_frame_flags_t flags
Definition: vpx_encoder.h:186
void * buf
Definition: vpx_encoder.h:180
Definition: vpx_encoder.h:225
Codec context structure.
Definition: vpx_codec.h:200