WebM Codec SDK: vpx/vpx_encoder.h Source File

WebM Codec SDK

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

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 VPX_MAX_LAYERS 12 // 3 temporal + 4 spatial layers are allowed.
47
49 #define MAX_LAYERS VPX_MAX_LAYERS // 3 temporal + 4 spatial layers allowed.
50
52 #define VPX_SS_MAX_LAYERS 5
53
55 #define VPX_SS_DEFAULT_LAYERS 1
56
65 #define VPX_ENCODER_ABI_VERSION (5 + VPX_CODEC_ABI_VERSION)
77 #define VPX_CODEC_CAP_PSNR 0x10000
84 #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
85
88 #define VPX_CODEC_CAP_HIGHBITDEPTH 0x40000
89
97 #define VPX_CODEC_USE_PSNR 0x10000
98 #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000
100 #define VPX_CODEC_USE_HIGHBITDEPTH 0x40000
107 typedef struct vpx_fixed_buf {
108 void *buf;
109 size_t sz;
110 } vpx_fixed_buf_t;
118 typedef int64_t vpx_codec_pts_t;
119
120
128 typedef uint32_t vpx_codec_frame_flags_t;
129 #define VPX_FRAME_IS_KEY 0x1
130 #define VPX_FRAME_IS_DROPPABLE 0x2
133 #define VPX_FRAME_IS_INVISIBLE 0x4
135 #define VPX_FRAME_IS_FRAGMENT 0x8
144 typedef uint32_t vpx_codec_er_flags_t;
145 #define VPX_ERROR_RESILIENT_DEFAULT 0x1
147 #define VPX_ERROR_RESILIENT_PARTITIONS 0x2
162 enum vpx_codec_cx_pkt_kind {
163 VPX_CODEC_CX_FRAME_PKT,
164 VPX_CODEC_STATS_PKT,
165 VPX_CODEC_FPMB_STATS_PKT,
166 VPX_CODEC_PSNR_PKT,
167 // Spatial SVC is still experimental and may be removed before the next ABI
168 // bump.
169 #if VPX_ENCODER_ABI_VERSION > (5 + VPX_CODEC_ABI_VERSION)
170 VPX_CODEC_SPATIAL_SVC_LAYER_SIZES,
171 VPX_CODEC_SPATIAL_SVC_LAYER_PSNR,
172 #endif
173 VPX_CODEC_CUSTOM_PKT = 256
174 };
175
176
182 typedef struct vpx_codec_cx_pkt {
183 enum vpx_codec_cx_pkt_kind kind;
184 union {
185 struct {
186 void *buf;
187 size_t sz;
188 vpx_codec_pts_t pts;
190 unsigned long duration;
192 vpx_codec_frame_flags_t flags;
193 int partition_id;
200 } frame;
201 vpx_fixed_buf_t twopass_stats;
202 vpx_fixed_buf_t firstpass_mb_stats;
203 struct vpx_psnr_pkt {
204 unsigned int samples[4];
205 uint64_t sse[4];
206 double psnr[4];
207 } psnr;
208 vpx_fixed_buf_t raw;
209 // Spatial SVC is still experimental and may be removed before the next
210 // ABI bump.
211 #if VPX_ENCODER_ABI_VERSION > (5 + VPX_CODEC_ABI_VERSION)
212 size_t layer_sizes[VPX_SS_MAX_LAYERS];
213 struct vpx_psnr_pkt layer_psnr[VPX_SS_MAX_LAYERS];
214 #endif
215
216 /* This packet size is fixed to allow codecs to extend this
217 * interface without having to manage storage for raw packets,
218 * i.e., if it's smaller than 128 bytes, you can store in the
219 * packet list directly.
220 */
221 char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)];
222 } data;
223 } vpx_codec_cx_pkt_t;
231 // putting the definitions here for now. (agrange: find if there
232 // is a better place for this)
233 typedef void (* vpx_codec_enc_output_cx_pkt_cb_fn_t)(vpx_codec_cx_pkt_t *pkt,
234 void *user_data);
235
237 typedef struct vpx_codec_enc_output_cx_cb_pair {
238 vpx_codec_enc_output_cx_pkt_cb_fn_t output_cx_pkt;
239 void *user_priv;
240 } vpx_codec_priv_output_cx_pkt_cb_pair_t;
241
246 typedef struct vpx_rational {
247 int num;
248 int den;
249 } vpx_rational_t;
253 enum vpx_enc_pass {
254 VPX_RC_ONE_PASS,
255 VPX_RC_FIRST_PASS,
256 VPX_RC_LAST_PASS
257 };
258
259
261 enum vpx_rc_mode {
262 VPX_VBR,
263 VPX_CBR,
264 VPX_CQ,
265 VPX_Q,
266 };
267
268
277 enum vpx_kf_mode {
278 VPX_KF_FIXED,
279 VPX_KF_AUTO,
280 VPX_KF_DISABLED = 0
281 };
282
283
291 typedef long vpx_enc_frame_flags_t;
292 #define VPX_EFLAG_FORCE_KF (1<<0)
301 typedef struct vpx_codec_enc_cfg {
302 /*
303 * generic settings (g)
304 */
305
313 unsigned int g_usage;
314
315
322 unsigned int g_threads;
323
324
333 unsigned int g_profile;
344 unsigned int g_w;
345
346
354 unsigned int g_h;
355
362 vpx_bit_depth_t g_bit_depth;
363
370 unsigned int g_input_bit_depth;
371
384 struct vpx_rational g_timebase;
385
386
393 vpx_codec_er_flags_t g_error_resilient;
394
395
401 enum vpx_enc_pass g_pass;
402
403
416 unsigned int g_lag_in_frames;
417
418
419 /*
420 * rate control settings (rc)
421 */
422
439 unsigned int rc_dropframe_thresh;
440
441
449 unsigned int rc_resize_allowed;
450
456 unsigned int rc_scaled_width;
457
463 unsigned int rc_scaled_height;
464
471 unsigned int rc_resize_up_thresh;
472
473
480 unsigned int rc_resize_down_thresh;
481
482
491 enum vpx_rc_mode rc_end_usage;
492
493
499 vpx_fixed_buf_t rc_twopass_stats_in;
500
506 vpx_fixed_buf_t rc_firstpass_mb_stats_in;
507
512 unsigned int rc_target_bitrate;
513
514
515 /*
516 * quantizer settings
517 */
518
519
528 unsigned int rc_min_quantizer;
529
530
539 unsigned int rc_max_quantizer;
540
541
542 /*
543 * bitrate tolerance
544 */
545
546
557 unsigned int rc_undershoot_pct;
558
559
570 unsigned int rc_overshoot_pct;
571
572
573 /*
574 * decoder buffer model parameters
575 */
576
577
587 unsigned int rc_buf_sz;
588
589
597 unsigned int rc_buf_initial_sz;
598
599
607 unsigned int rc_buf_optimal_sz;
608
609
610 /*
611 * 2 pass rate control parameters
612 */
613
614
623 unsigned int rc_2pass_vbr_bias_pct;
631 unsigned int rc_2pass_vbr_minsection_pct;
632
633
639 unsigned int rc_2pass_vbr_maxsection_pct;
640
641
642 /*
643 * keyframing settings (kf)
644 */
645
652 enum vpx_kf_mode kf_mode;
653
654
662 unsigned int kf_min_dist;
663
664
672 unsigned int kf_max_dist;
673
674 /*
675 * Spatial scalability settings (ss)
676 */
677
682 unsigned int ss_number_layers;
683
689 int ss_enable_auto_alt_ref[VPX_SS_MAX_LAYERS];
690
696 unsigned int ss_target_bitrate[VPX_SS_MAX_LAYERS];
697
702 unsigned int ts_number_layers;
703
709 unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS];
710
716 unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS];
717
725 unsigned int ts_periodicity;
726
734 unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY];
735
742 unsigned int layer_target_bitrate[VPX_MAX_LAYERS];
743
750 int temporal_layering_mode;
751 } vpx_codec_enc_cfg_t;
758 typedef struct vpx_svc_parameters {
759 int max_quantizers[VPX_MAX_LAYERS];
760 int min_quantizers[VPX_MAX_LAYERS];
761 int scaling_factor_num[VPX_MAX_LAYERS];
762 int scaling_factor_den[VPX_MAX_LAYERS];
763 int temporal_layering_mode;
764 } vpx_svc_extra_cfg_t;
765
766
789 vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx,
790 vpx_codec_iface_t *iface,
791 const vpx_codec_enc_cfg_t *cfg,
792 vpx_codec_flags_t flags,
793 int ver);
794
795
800 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
801 vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
802
803
824 vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx,
825 vpx_codec_iface_t *iface,
826 vpx_codec_enc_cfg_t *cfg,
827 int num_enc,
828 vpx_codec_flags_t flags,
829 vpx_rational_t *dsf,
830 int ver);
831
832
837 #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
838 vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
839 VPX_ENCODER_ABI_VERSION)
840
841
861 vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface,
862 vpx_codec_enc_cfg_t *cfg,
863 unsigned int reserved);
864
865
880 vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx,
881 const vpx_codec_enc_cfg_t *cfg);
882
883
895 vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx);
896
897
898 #define VPX_DL_REALTIME (1)
900 #define VPX_DL_GOOD_QUALITY (1000000)
902 #define VPX_DL_BEST_QUALITY (0)
940 vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx,
941 const vpx_image_t *img,
942 vpx_codec_pts_t pts,
943 unsigned long duration,
944 vpx_enc_frame_flags_t flags,
945 unsigned long deadline);
946
990 vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx,
991 const vpx_fixed_buf_t *buf,
992 unsigned int pad_before,
993 unsigned int pad_after);
994
995
1019 const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx,
1020 vpx_codec_iter_t *iter);
1021
1022
1035 const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx);
1036
1037
1039 #ifdef __cplusplus
1040 }
1041 #endif
1042 #endif // VPX_VPX_ENCODER_H_
1043
vpx_rational
Rational Number.
Definition: vpx_encoder.h:259
vpx_codec_cx_pkt::twopass_stats
vpx_fixed_buf_t twopass_stats
Definition: vpx_encoder.h:214
vpx_codec_set_cx_data_buf
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_MAX_LAYERS
#define VPX_MAX_LAYERS
Definition: vpx_encoder.h:46
VPX_Q
Definition: vpx_encoder.h:278
vpx_image
Image Descriptor.
Definition: vpx_image.h:88
vpx_codec_cx_pkt::pts
vpx_codec_pts_t pts
Definition: vpx_encoder.h:201
vpx_kf_mode
vpx_kf_mode
Keyframe placement mode.
Definition: vpx_encoder.h:290
VPX_TS_MAX_LAYERS
#define VPX_TS_MAX_LAYERS
Definition: vpx_encoder.h:40
VPX_CBR
Definition: vpx_encoder.h:276
vpx_codec_enc_cfg_t
struct vpx_codec_enc_cfg vpx_codec_enc_cfg_t
Encoder configuration structure.
vpx_fixed_buf_t
struct vpx_fixed_buf vpx_fixed_buf_t
Generic fixed size buffer structure.
vpx_svc_extra_cfg_t
struct vpx_svc_parameters vpx_svc_extra_cfg_t
vp9 svc extra configure parameters
VPX_CODEC_STATS_PKT
Definition: vpx_encoder.h:177
vpx_codec_cx_pkt::partition_id
int partition_id
Definition: vpx_encoder.h:206
vpx_enc_pass
vpx_enc_pass
Multi-pass Encoding Pass.
Definition: vpx_encoder.h:266
vpx_codec_enc_cfg
Encoder configuration structure.
Definition: vpx_encoder.h:314
VPX_CODEC_CUSTOM_PKT
Definition: vpx_encoder.h:186
VPX_CODEC_PSNR_PKT
Definition: vpx_encoder.h:179
VPX_KF_AUTO
Definition: vpx_encoder.h:292
vpx_codec_cx_pkt
Encoder output packet.
Definition: vpx_encoder.h:195
vpx_codec_enc_config_set
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.
vpx_fixed_buf
Generic fixed size buffer structure.
Definition: vpx_encoder.h:108
vpx_codec_frame_flags_t
uint32_t vpx_codec_frame_flags_t
Compressed Frame Flags.
Definition: vpx_encoder.h:129
VPX_RC_FIRST_PASS
Definition: vpx_encoder.h:268
VPX_RC_LAST_PASS
Definition: vpx_encoder.h:269
vpx_codec_cx_pkt::frame
struct vpx_codec_cx_pkt::@1::@2 frame
VPX_SS_MAX_LAYERS
#define VPX_SS_MAX_LAYERS
Definition: vpx_encoder.h:52
vpx_bit_depth_t
enum vpx_bit_depth vpx_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
vpx_codec_cx_pkt::sse
uint64_t sse[4]
Definition: vpx_encoder.h:218
vpx_codec_cx_pkt::sz
size_t sz
Definition: vpx_encoder.h:200
vpx_codec_cx_pkt::kind
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:196
vpx_codec_cx_pkt::raw
vpx_fixed_buf_t raw
Definition: vpx_encoder.h:221
vpx_codec_enc_output_cx_cb_pair
Callback function pointer / user data pair storage.
Definition: vpx_encoder.h:250
vpx_enc_frame_flags_t
long vpx_enc_frame_flags_t
Encoded Frame Flags.
Definition: vpx_encoder.h:304
vpx_codec_iface_t
const struct vpx_codec_iface vpx_codec_iface_t
Codec interface structure.
Definition: vpx_codec.h:173
vpx_codec_cx_pkt::pad
char pad[128-sizeof(enum vpx_codec_cx_pkt_kind)]
Definition: vpx_encoder.h:234
vpx_codec_flags_t
long vpx_codec_flags_t
Initialization-time Feature Enabling.
Definition: vpx_codec.h:165
vpx_codec_cx_pkt_kind
vpx_codec_cx_pkt_kind
Encoder output packet variants.
Definition: vpx_encoder.h:175
VPX_VBR
Definition: vpx_encoder.h:275
vpx_codec_cx_pkt::psnr
double psnr[4]
Definition: vpx_encoder.h:219
VPX_KF_FIXED
Definition: vpx_encoder.h:291
vpx_codec_cx_pkt::samples
unsigned int samples[4]
Definition: vpx_encoder.h:217
vpx_codec_cx_pkt::firstpass_mb_stats
vpx_fixed_buf_t firstpass_mb_stats
Definition: vpx_encoder.h:215
vpx_rc_mode
vpx_rc_mode
Rate control mode.
Definition: vpx_encoder.h:274
vpx_codec_get_preview_frame
const vpx_image_t * vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx)
Get Preview Frame.
vpx_codec_cx_pkt::duration
unsigned long duration
Definition: vpx_encoder.h:203
vpx_codec_er_flags_t
uint32_t vpx_codec_er_flags_t
Error Resilient flags.
Definition: vpx_encoder.h:149
vpx_codec_err_t
vpx_codec_err_t
Algorithm return codes.
Definition: vpx_codec.h:89
vpx_codec_get_cx_data
const vpx_codec_cx_pkt_t * vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter)
Encoded data iterator.
vpx_codec_cx_pkt::data
union vpx_codec_cx_pkt::@1 data
vpx_codec_enc_output_cx_pkt_cb_fn_t
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:246
vpx_codec_cx_pkt_t
struct vpx_codec_cx_pkt vpx_codec_cx_pkt_t
Encoder output packet.
vpx_rational_t
struct vpx_rational vpx_rational_t
Rational Number.
vpx_codec_enc_cfg::temporal_layering_mode
int temporal_layering_mode
Temporal layering mode indicating which temporal layering scheme to use.
Definition: vpx_encoder.h:763
vpx_codec_priv_output_cx_pkt_cb_pair_t
struct vpx_codec_enc_output_cx_cb_pair vpx_codec_priv_output_cx_pkt_cb_pair_t
Callback function pointer / user data pair storage.
VPX_KF_DISABLED
Definition: vpx_encoder.h:293
VPX_CODEC_FPMB_STATS_PKT
Definition: vpx_encoder.h:178
vpx_codec_pts_t
int64_t vpx_codec_pts_t
Time Stamp Type.
Definition: vpx_encoder.h:119
vpx_codec_enc_config_default
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.
VPX_TS_MAX_PERIODICITY
#define VPX_TS_MAX_PERIODICITY
Definition: vpx_encoder.h:37
vpx_codec_get_global_headers
vpx_fixed_buf_t * vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx)
Get global stream headers.
VPX_CQ
Definition: vpx_encoder.h:277
vpx_codec.h
Describes the codec algorithm interface to applications.
vpx_codec_enc_init_multi_ver
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.
vpx_codec_enc_init_ver
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_iter_t
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:188
VPX_CODEC_CX_FRAME_PKT
Definition: vpx_encoder.h:176
vpx_codec_cx_pkt::flags
vpx_codec_frame_flags_t flags
Definition: vpx_encoder.h:205
vpx_codec_cx_pkt::buf
void * buf
Definition: vpx_encoder.h:199
vpx_svc_parameters
vp9 svc extra configure parameters
Definition: vpx_encoder.h:771
VPX_RC_ONE_PASS
Definition: vpx_encoder.h:267
vpx_codec_ctx
Codec context structure.
Definition: vpx_codec.h:199