33 #define END_OF_STREAM 0x001
35 #define XAVS_PART_I8X8 0x002
36 #define XAVS_PART_P8X8 0x010
37 #define XAVS_PART_B8X8 0x100
60 static const int level_map[] = {
67 if (level < 0 || level > XAVS_LOG_DEBUG)
70 av_vlog(p, level_map[level], fmt, args);
74 int size, xavs_nal_t *nals,
75 int nnal,
int skip_sei)
88 for (i = 0; i < nnal; i++) {
90 if (skip_sei && nals[i].i_type ==
NAL_SEI) {
92 if (xavs_nal_encode(x4->
sei, &x4->
sei_size, 1, nals + i) < 0)
97 s = xavs_nal_encode(p, &size, 1, nals + i);
107 int bufsize,
void *
data)
113 xavs_picture_t pic_out;
115 x4->
pic.img.i_csp = XAVS_CSP_I420;
116 x4->
pic.img.i_plane = 3;
119 for (i = 0; i < 3; i++) {
120 x4->
pic.img.plane[i] = frame->
data[i];
124 x4->
pic.i_pts = frame->
pts;
125 x4->
pic.i_type = XAVS_TYPE_AUTO;
128 if (xavs_encoder_encode(x4->
enc, &nal, &nnal,
129 frame? &x4->
pic:
NULL, &pic_out) < 0)
132 bufsize =
encode_nals(ctx, buf, bufsize, nal, nnal, 0);
139 buf[bufsize+1] = 0x0;
140 buf[bufsize+2] = 0x01;
141 buf[bufsize+3] = 0xb1;
150 switch (pic_out.i_type) {
181 xavs_encoder_close(x4->
enc);
191 xavs_param_default(&x4->
params);
194 x4->
params.p_log_private = avctx;
198 x4->
params.rc.i_rc_method = XAVS_RC_ABR;
204 x4->
params.rc.b_stat_read = 1;
206 #if FF_API_X264_GLOBAL_OPTS
208 x4->
params.rc.i_rc_method = XAVS_RC_CRF;
209 x4->
params.rc.f_rf_constant = avctx->crf;
210 }
else if (avctx->cqp > -1) {
211 x4->
params.rc.i_rc_method = XAVS_RC_CQP;
212 x4->
params.rc.i_qp_constant = avctx->cqp;
217 x4->
params.rc.i_rc_method = XAVS_RC_CRF;
219 }
else if (x4->
cqp >= 0) {
220 x4->
params.rc.i_rc_method = XAVS_RC_CQP;
225 #if FF_API_X264_GLOBAL_OPTS
226 if (avctx->bframebias)
227 x4->
params.i_bframe_bias = avctx->bframebias;
228 if (avctx->deblockalpha)
229 x4->
params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
230 if (avctx->deblockbeta)
231 x4->
params.i_deblocking_filter_beta = avctx->deblockbeta;
232 if (avctx->complexityblur >= 0)
233 x4->
params.rc.f_complexity_blur = avctx->complexityblur;
234 if (avctx->directpred >= 0)
235 x4->
params.analyse.i_direct_mv_pred = avctx->directpred;
236 if (avctx->partitions) {
238 x4->
params.analyse.inter |= XAVS_ANALYSE_I8x8;
240 x4->
params.analyse.inter |= XAVS_ANALYSE_PSUB16x16;
242 x4->
params.analyse.inter |= XAVS_ANALYSE_BSUB16x16;
244 x4->
params.rc.b_mb_tree = !!(avctx->
flags2 & CODEC_FLAG2_MBTREE);
246 x4->
params.analyse.b_mixed_references = avctx->
flags2 & CODEC_FLAG2_MIXED_REFS;
247 x4->
params.analyse.b_fast_pskip = avctx->
flags2 & CODEC_FLAG2_FASTPSKIP;
248 x4->
params.analyse.b_weighted_bipred = avctx->
flags2 & CODEC_FLAG2_WPRED;
261 if (x4->
b_bias != INT_MIN)
300 x4->
params.analyse.inter = XAVS_ANALYSE_I8x8 |XAVS_ANALYSE_PSUB16x16| XAVS_ANALYSE_BSUB16x16;
304 x4->
params.analyse.i_me_method = XAVS_ME_DIA;
307 x4->
params.analyse.i_me_method = XAVS_ME_HEX;
310 x4->
params.analyse.i_me_method = XAVS_ME_UMH;
313 x4->
params.analyse.i_me_method = XAVS_ME_ESA;
316 x4->
params.analyse.i_me_method = XAVS_ME_TESA;
319 x4->
params.analyse.i_me_method = XAVS_ME_HEX;
327 x4->
params.analyse.b_transform_8x8 = 1;
332 if (avctx->
level > 0)
335 x4->
params.rc.f_rate_tolerance =
340 x4->
params.rc.f_vbv_buffer_init =
343 x4->
params.rc.f_vbv_buffer_init = 0.9;
352 x4->
params.i_log_level = XAVS_LOG_DEBUG;
357 x4->
params.b_repeat_headers = 0;
359 x4->
enc = xavs_encoder_open(&x4->
params);
370 s = xavs_encoder_headers(x4->
enc, &nal, &nnal);
378 #define OFFSET(x) offsetof(XavsContext, x)
379 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
382 {
"qp",
"Constant quantization parameter rate control method",
OFFSET(cqp),
AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX,
VE },
383 {
"b-bias",
"Influences how often B-frames are used",
OFFSET(b_bias),
AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX,
VE },
384 {
"cplxblur",
"Reduce fluctuations in QP (before curve compression)",
OFFSET(cplxblur),
AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX,
VE},
385 {
"direct-pred",
"Direct MV prediction mode",
OFFSET(direct_pred),
AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX,
VE,
"direct-pred" },
392 {
"mixed-refs",
"One reference per partition, as opposed to one reference per macroblock",
OFFSET(mixed_refs),
AV_OPT_TYPE_INT, {-1}, -1, 1,
VE },
420 .priv_class = &
class,
#define CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
#define CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
float qblur
amount of qscale smoothing over time (0.0-1.0)
AVFrame * coded_frame
the picture in the bitstream
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
#define AV_LOG_WARNING
Something somehow does not look correct.
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
static void XAVS_log(void *p, int level, const char *fmt, va_list args)
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
static const AVOption options[]
int scenechange_threshold
scene change detection threshold 0 is default, larger means fewer detected scene changes.
struct XavsContext XavsContext
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static av_cold int XAVS_close(AVCodecContext *avctx)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int bit_rate_tolerance
number of bits the bitstream is allowed to diverge from the reference.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
int64_t pts
presentation timestamp in time_base units (time when frame should be shown to user) If AV_NOPTS_VALUE...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int me_cmp
motion estimation comparison function
enhanced predictive zonal search
static int init(AVCodecParserContext *s)
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
int chromaoffset
chroma qp offset from luma
int has_b_frames
Size of the frame reordering buffer in the decoder.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
#define CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
int qmax
maximum quantizer
static av_cold int XAVS_init(AVCodecContext *avctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int rc_max_rate
maximum bitrate
const char * name
Name of the codec implementation.
float i_quant_factor
qscale factor between P and I-frames If > 0 then the last p frame quantizer will be used (q= lastp_q*...
int rc_buffer_size
decoder bitstream buffer size
int refs
number of reference frames
static const AVCodecDefault xavs_defaults[]
int bit_rate
the average bitrate
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
int width
picture width / height.
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
int max_qdiff
maximum quantizer difference between frames
static int XAVS_frame(AVCodecContext *ctx, uint8_t *buf, int bufsize, void *data)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
int qmin
minimum quantizer
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Describe the class of an AVClass context structure.
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
transformed exhaustive search algorithm
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int noise_reduction
noise reduction strength
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
common internal api header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
uneven multi-hexagon search
int trellis
trellis RD quantization
AVCodec ff_libxavs_encoder
int key_frame
1 -> keyframe, 0-> not
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size, xavs_nal_t *nals, int nnal, int skip_sei)
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int me_method
Motion estimation algorithm used for video coding.
int me_subpel_quality
subpel ME quality
int keyint_min
minimum GOP size