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
29extern "C" {
30#endif
31
32#include "./vpx_codec.h"
33#include "./vpx_ext_ratectrl.h"
34
38#define VPX_TS_MAX_PERIODICITY 16
39
41#define VPX_TS_MAX_LAYERS 5
42
44#define VPX_MAX_LAYERS 12 // 3 temporal + 4 spatial layers are allowed.
45
47#define VPX_SS_MAX_LAYERS 5
48
50#define VPX_SS_DEFAULT_LAYERS 1
51
60#define VPX_ENCODER_ABI_VERSION \
61 (15 + VPX_CODEC_ABI_VERSION + \
62 VPX_EXT_RATECTRL_ABI_VERSION)
73#define VPX_CODEC_CAP_PSNR 0x10000
80#define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
81
89#define VPX_CODEC_USE_PSNR 0x10000
91#define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000
92#define VPX_CODEC_USE_HIGHBITDEPTH 0x40000
98typedef struct vpx_fixed_buf {
99 void *buf;
100 size_t sz;
108typedef int64_t vpx_codec_pts_t;
109
117typedef uint32_t vpx_codec_frame_flags_t;
118#define VPX_FRAME_IS_KEY 0x1u
121#define VPX_FRAME_IS_DROPPABLE 0x2u
123#define VPX_FRAME_IS_INVISIBLE 0x4u
125#define VPX_FRAME_IS_FRAGMENT 0x8u
126
133typedef uint32_t vpx_codec_er_flags_t;
135#define VPX_ERROR_RESILIENT_DEFAULT 0x1u
141#define VPX_ERROR_RESILIENT_PARTITIONS 0x2u
142
156
162typedef struct vpx_codec_cx_pkt {
164 union {
165 struct {
166 void *buf;
167 size_t sz;
171 unsigned long duration;
179 unsigned int width[VPX_SS_MAX_LAYERS];
180 unsigned int height[VPX_SS_MAX_LAYERS];
187 struct vpx_psnr_pkt {
188 unsigned int samples[4];
189 uint64_t sse[4];
190 double psnr[4];
194 /* This packet size is fixed to allow codecs to extend this
195 * interface without having to manage storage for raw packets,
196 * i.e., if it's smaller than 128 bytes, you can store in the
197 * packet list directly.
198 */
199 char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)];
209 void *user_data);
210
214 void *user_priv;
216
221typedef struct vpx_rational {
222 int num;
223 int den;
227typedef enum vpx_enc_pass {
232
239};
240
252 VPX_KF_DISABLED = 0
254
263#define VPX_EFLAG_FORCE_KF (1 << 0)
271typedef struct vpx_codec_enc_cfg {
272 /*
273 * generic settings (g)
274 */
275
280 unsigned int g_usage;
281
288 unsigned int g_threads;
289
298 unsigned int g_profile;
307 unsigned int g_w;
308
316 unsigned int g_h;
317
325
332 unsigned int g_input_bit_depth;
333
347
355
362
375 unsigned int g_lag_in_frames;
376
377 /*
378 * rate control settings (rc)
379 */
380
395
403 unsigned int rc_resize_allowed;
404
410 unsigned int rc_scaled_width;
411
417 unsigned int rc_scaled_height;
418
426
434
444
451
458
463 unsigned int rc_target_bitrate;
464
465 /*
466 * quantizer settings
467 */
468
476 unsigned int rc_min_quantizer;
477
485 unsigned int rc_max_quantizer;
486
487 /*
488 * bitrate tolerance
489 */
490
504 unsigned int rc_undershoot_pct;
505
519 unsigned int rc_overshoot_pct;
520
521 /*
522 * decoder buffer model parameters
523 */
524
534 unsigned int rc_buf_sz;
535
543 unsigned int rc_buf_initial_sz;
544
552 unsigned int rc_buf_optimal_sz;
553
554 /*
555 * 2 pass rate control parameters
556 */
557
567
574
581
588
589 /*
590 * keyframing settings (kf)
591 */
592
600
608 unsigned int kf_min_dist;
609
617 unsigned int kf_max_dist;
618
619 /*
620 * Spatial scalability settings (ss)
621 */
622
627 unsigned int ss_number_layers;
628
635
642
647 unsigned int ts_number_layers;
648
655
662
670 unsigned int ts_periodicity;
671
680
688
697
703
712
721
730
739
748
757
767
776
785
794
803
812
822
832
849typedef struct vpx_svc_parameters {
858
882 vpx_codec_iface_t *iface,
883 const vpx_codec_enc_cfg_t *cfg,
884 vpx_codec_flags_t flags, int ver);
885
890#define vpx_codec_enc_init(ctx, iface, cfg, flags) \
891 vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
892
915 int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver);
916
921#define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
922 vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
923 VPX_ENCODER_ABI_VERSION)
924
946 unsigned int usage);
947
963 const vpx_codec_enc_cfg_t *cfg);
964
977
979#define VPX_DL_REALTIME (1)
981#define VPX_DL_GOOD_QUALITY (1000000)
983#define VPX_DL_BEST_QUALITY (0)
1021 vpx_codec_pts_t pts, unsigned long duration,
1023 unsigned long deadline);
1024
1069 const vpx_fixed_buf_t *buf,
1070 unsigned int pad_before,
1071 unsigned int pad_after);
1072
1097 vpx_codec_iter_t *iter);
1098
1112
1114#ifdef __cplusplus
1115}
1116#endif
1117#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.
#define VPX_TS_MAX_LAYERS
Definition: vpx_encoder.h:41
vpx_codec_cx_pkt_kind
Encoder output packet variants.
Definition: vpx_encoder.h:149
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:208
vpx_enc_pass
Multi-pass Encoding Pass.
Definition: vpx_encoder.h:227
const vpx_image_t * vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx)
Get Preview Frame.
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.
const vpx_codec_cx_pkt_t * vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter)
Encoded data iterator.
#define VPX_TS_MAX_PERIODICITY
Definition: vpx_encoder.h:38
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:44
uint32_t vpx_codec_er_flags_t
Error Resilient flags.
Definition: vpx_encoder.h:133
int64_t vpx_codec_pts_t
Time Stamp Type.
Definition: vpx_encoder.h:108
#define VPX_SS_MAX_LAYERS
Definition: vpx_encoder.h:47
long vpx_enc_frame_flags_t
Encoded Frame Flags.
Definition: vpx_encoder.h:262
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:249
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:117
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_t * vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx)
Get global stream headers.
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:234
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:153
@ VPX_CODEC_CX_FRAME_PKT
Definition: vpx_encoder.h:150
@ VPX_CODEC_STATS_PKT
Definition: vpx_encoder.h:151
@ VPX_CODEC_CUSTOM_PKT
Definition: vpx_encoder.h:154
@ VPX_CODEC_FPMB_STATS_PKT
Definition: vpx_encoder.h:152
@ VPX_RC_LAST_PASS
Definition: vpx_encoder.h:230
@ VPX_RC_ONE_PASS
Definition: vpx_encoder.h:228
@ VPX_RC_FIRST_PASS
Definition: vpx_encoder.h:229
@ VPX_KF_DISABLED
Definition: vpx_encoder.h:252
@ VPX_KF_FIXED
Definition: vpx_encoder.h:250
@ VPX_KF_AUTO
Definition: vpx_encoder.h:251
@ VPX_Q
Definition: vpx_encoder.h:238
@ VPX_CQ
Definition: vpx_encoder.h:237
@ VPX_CBR
Definition: vpx_encoder.h:236
@ VPX_VBR
Definition: vpx_encoder.h:235
Codec context structure.
Definition: vpx_codec.h:200
Encoder output packet.
Definition: vpx_encoder.h:162
char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)]
Definition: vpx_encoder.h:199
vpx_codec_frame_flags_t flags
Definition: vpx_encoder.h:172
vpx_fixed_buf_t twopass_stats
Definition: vpx_encoder.h:185
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:163
double psnr[4]
Definition: vpx_encoder.h:190
unsigned int width[5]
Width and height of frames in this packet. VP8 will only use the first one.
Definition: vpx_encoder.h:179
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:183
vpx_fixed_buf_t firstpass_mb_stats
Definition: vpx_encoder.h:186
size_t sz
Definition: vpx_encoder.h:167
void * buf
Definition: vpx_encoder.h:166
vpx_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition: vpx_encoder.h:169
vpx_fixed_buf_t raw
Definition: vpx_encoder.h:192
unsigned int height[5]
Definition: vpx_encoder.h:180
int partition_id
the partition id defines the decoding order of the partitions. Only applicable when "output partition...
Definition: vpx_encoder.h:176
unsigned long duration
duration to show frame (in timebase units)
Definition: vpx_encoder.h:171
union vpx_codec_cx_pkt::@1 data
Encoder configuration structure.
Definition: vpx_encoder.h:271
vpx_rational_t rd_mult_arf_qp_fac
Rate-distortion multiplier for alt-ref frames. The multiplier is a crucial parameter in the calculati...
Definition: vpx_encoder.h:831
unsigned int rc_resize_allowed
Enable/disable spatial resampling, if supported by the codec.
Definition: vpx_encoder.h:403
int temporal_layering_mode
Temporal layering mode indicating which temporal layering scheme to use.
Definition: vpx_encoder.h:696
unsigned int kf_min_dist
Keyframe minimum interval.
Definition: vpx_encoder.h:608
vpx_rational_t sr_default_decay_limit
Second reference default decay limit.
Definition: vpx_encoder.h:729
unsigned int rc_min_quantizer
Minimum (Best Quality) Quantizer.
Definition: vpx_encoder.h:476
unsigned int ts_number_layers
Number of temporal coding layers.
Definition: vpx_encoder.h:647
vpx_rational_t kf_max_total_boost_factor
Keyframe maximum total boost adjustment factor.
Definition: vpx_encoder.h:784
vpx_fixed_buf_t rc_twopass_stats_in
Two-pass stats buffer.
Definition: vpx_encoder.h:450
unsigned int rc_resize_down_thresh
Spatial resampling down watermark.
Definition: vpx_encoder.h:433
unsigned int ss_number_layers
Number of spatial coding layers.
Definition: vpx_encoder.h:627
unsigned int rc_2pass_vbr_bias_pct
Two-pass mode CBR/VBR bias.
Definition: vpx_encoder.h:566
unsigned int rc_2pass_vbr_minsection_pct
Two-pass mode per-GOP minimum bitrate.
Definition: vpx_encoder.h:573
int ss_enable_auto_alt_ref[5]
Enable auto alt reference flags for each spatial layer.
Definition: vpx_encoder.h:634
unsigned int rc_scaled_width
Internal coded frame width.
Definition: vpx_encoder.h:410
vpx_rational_t rd_mult_key_qp_fac
Rate-distortion multiplier for key frames. The multiplier is a crucial parameter in the calculation o...
Definition: vpx_encoder.h:841
unsigned int g_profile
Bitstream profile to use.
Definition: vpx_encoder.h:298
unsigned int layer_target_bitrate[12]
Target bitrate for each spatial/temporal layer.
Definition: vpx_encoder.h:687
unsigned int g_h
Height of the frame.
Definition: vpx_encoder.h:316
enum vpx_kf_mode kf_mode
Keyframe placement mode.
Definition: vpx_encoder.h:599
unsigned int ts_layer_id[16]
Template defining the membership of frames to temporal layers.
Definition: vpx_encoder.h:679
vpx_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition: vpx_encoder.h:354
unsigned int ts_periodicity
Length of the sequence defining frame temporal layer membership.
Definition: vpx_encoder.h:670
unsigned int rc_overshoot_pct
Rate control adaptation overshoot control.
Definition: vpx_encoder.h:519
vpx_fixed_buf_t rc_firstpass_mb_stats_in
first pass mb stats buffer.
Definition: vpx_encoder.h:457
unsigned int rc_scaled_height
Internal coded frame height.
Definition: vpx_encoder.h:417
unsigned int g_usage
Deprecated: Algorithm specific "usage" value.
Definition: vpx_encoder.h:280
unsigned int g_w
Width of the frame.
Definition: vpx_encoder.h:307
unsigned int ss_target_bitrate[5]
Target bitrate for each spatial layer.
Definition: vpx_encoder.h:641
unsigned int rc_buf_sz
Decoder Buffer Size.
Definition: vpx_encoder.h:534
unsigned int rc_dropframe_thresh
Temporal resampling configuration, if supported by the codec.
Definition: vpx_encoder.h:394
struct vpx_rational g_timebase
Stream timebase units.
Definition: vpx_encoder.h:346
enum vpx_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: vpx_encoder.h:361
vpx_rational_t kf_frame_max_boost_first_factor
Keyframe maximum boost adjustment factor, for the first keyframe in a chunk.
Definition: vpx_encoder.h:766
unsigned int rc_resize_up_thresh
Spatial resampling up watermark.
Definition: vpx_encoder.h:425
unsigned int rc_max_quantizer
Maximum (Worst Quality) Quantizer.
Definition: vpx_encoder.h:485
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:587
vpx_rational_t zm_factor
Zero motion power factor.
Definition: vpx_encoder.h:811
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition: vpx_encoder.h:375
enum vpx_rc_mode rc_end_usage
Rate control algorithm to use.
Definition: vpx_encoder.h:443
vpx_rational_t active_wq_factor
Active worst quality factor.
Definition: vpx_encoder.h:711
vpx_rational_t gf_max_total_boost_factor
Golden frame maximum total boost adjustment factor.
Definition: vpx_encoder.h:793
unsigned int rc_buf_initial_sz
Decoder Buffer Initial Size.
Definition: vpx_encoder.h:543
vpx_bit_depth_t g_bit_depth
Bit-depth of the codec.
Definition: vpx_encoder.h:324
vpx_rational_t gf_frame_max_boost_factor
Golden frame maximum boost adjustment factor.
Definition: vpx_encoder.h:802
unsigned int rc_buf_optimal_sz
Decoder Buffer Optimal Size.
Definition: vpx_encoder.h:552
int use_vizier_rc_params
A flag indicating whether to use external rate control parameters. By default is 0....
Definition: vpx_encoder.h:702
unsigned int rc_2pass_vbr_maxsection_pct
Two-pass mode per-GOP maximum bitrate.
Definition: vpx_encoder.h:580
unsigned int rc_target_bitrate
Target data rate.
Definition: vpx_encoder.h:463
unsigned int ts_target_bitrate[5]
Target bitrate for each temporal layer.
Definition: vpx_encoder.h:654
vpx_rational_t err_per_mb_factor
Error per macroblock adjustment factor.
Definition: vpx_encoder.h:720
unsigned int g_input_bit_depth
Bit-depth of the input frames.
Definition: vpx_encoder.h:332
vpx_rational_t kf_frame_min_boost_factor
Keyframe minimum boost adjustment factor.
Definition: vpx_encoder.h:756
vpx_rational_t sr_diff_factor
Second reference difference factor.
Definition: vpx_encoder.h:738
vpx_rational_t kf_err_per_mb_factor
Keyframe error per macroblock adjustment factor.
Definition: vpx_encoder.h:747
unsigned int rc_undershoot_pct
Rate control adaptation undershoot control.
Definition: vpx_encoder.h:504
unsigned int ts_rate_decimator[5]
Frame rate decimation factor for each temporal layer.
Definition: vpx_encoder.h:661
unsigned int kf_max_dist
Keyframe maximum interval.
Definition: vpx_encoder.h:617
vpx_rational_t rd_mult_inter_qp_fac
Rate-distortion multiplier for inter frames. The multiplier is a crucial parameter in the calculation...
Definition: vpx_encoder.h:821
vpx_rational_t kf_frame_max_boost_subs_factor
Keyframe maximum boost adjustment factor, for subsequent keyframes.
Definition: vpx_encoder.h:775
unsigned int g_threads
Maximum number of threads to use.
Definition: vpx_encoder.h:288
Callback function pointer / user data pair storage.
Definition: vpx_encoder.h:212
void * user_priv
Definition: vpx_encoder.h:214
vpx_codec_enc_output_cx_pkt_cb_fn_t output_cx_pkt
Definition: vpx_encoder.h:213
Generic fixed size buffer structure.
Definition: vpx_encoder.h:98
size_t sz
Definition: vpx_encoder.h:100
void * buf
Definition: vpx_encoder.h:99
Image Descriptor.
Definition: vpx_image.h:72
Rational Number.
Definition: vpx_encoder.h:221
int den
Definition: vpx_encoder.h:223
int num
Definition: vpx_encoder.h:222
vp9 svc extra configure parameters
Definition: vpx_encoder.h:849
int min_quantizers[12]
Definition: vpx_encoder.h:851
int scaling_factor_num[12]
Definition: vpx_encoder.h:852
int speed_per_layer[12]
Definition: vpx_encoder.h:854
int max_quantizers[12]
Definition: vpx_encoder.h:850
int scaling_factor_den[12]
Definition: vpx_encoder.h:853
int loopfilter_ctrl[12]
Definition: vpx_encoder.h:856
int temporal_layering_mode
Definition: vpx_encoder.h:855
Describes the codec algorithm interface to applications.