124
133
x4->pic.i_pts = frame->pts;
125
134
x4->pic.i_type = XAVS_TYPE_AUTO;
135
x4->pts_buffer[ctx->frame_number % (ctx->max_b_frames+1)] = frame->pts;
128
138
if (xavs_encoder_encode(x4->enc, &nal, &nnal,
129
139
frame? &x4->pic: NULL, &pic_out) < 0)
132
bufsize = encode_nals(ctx, buf, bufsize, nal, nnal, 0);
142
ret = encode_nals(ctx, pkt, nal, nnal);
137
if (!bufsize && !frame && !(x4->end_of_stream)){
139
buf[bufsize+1] = 0x0;
140
buf[bufsize+2] = 0x01;
141
buf[bufsize+3] = 0xb1;
143
x4->end_of_stream = END_OF_STREAM;
148
if (!frame && !(x4->end_of_stream)) {
149
if ((ret = ff_alloc_packet(pkt, 4)) < 0)
156
pkt->dts = 2*x4->pts_buffer[(x4->out_frame_count-1)%(ctx->max_b_frames+1)] -
157
x4->pts_buffer[(x4->out_frame_count-2)%(ctx->max_b_frames+1)];
158
x4->end_of_stream = END_OF_STREAM;
146
/* FIXME: libxavs now provides DTS */
147
/* but AVFrame doesn't have a field for it. */
148
164
x4->out_pic.pts = pic_out.i_pts;
165
pkt->pts = pic_out.i_pts;
166
if (ctx->has_b_frames) {
167
if (!x4->out_frame_count)
168
pkt->dts = pkt->pts - (x4->pts_buffer[1] - x4->pts_buffer[0]);
170
pkt->dts = x4->pts_buffer[(x4->out_frame_count-1)%(ctx->max_b_frames+1)];
150
174
switch (pic_out.i_type) {
151
175
case XAVS_TYPE_IDR:
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) {
237
if (avctx->partitions & XAVS_PART_I8X8)
238
x4->params.analyse.inter |= XAVS_ANALYSE_I8x8;
239
if (avctx->partitions & XAVS_PART_P8X8)
240
x4->params.analyse.inter |= XAVS_ANALYSE_PSUB16x16;
241
if (avctx->partitions & XAVS_PART_B8X8)
242
x4->params.analyse.inter |= XAVS_ANALYSE_BSUB16x16;
244
x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
245
x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
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;
251
245
if (x4->aud >= 0)
252
246
x4->params.b_aud = x4->aud;
253
247
if (x4->mbtree >= 0)
357
if (!(x4->pts_buffer = av_mallocz((avctx->max_b_frames+1) * sizeof(*x4->pts_buffer))))
358
return AVERROR(ENOMEM);
363
360
avctx->coded_frame = &x4->out_pic;
364
361
/* TAG: Do we have GLOBAL HEADER in AVS */
365
362
/* We Have PPS and SPS in AVS */
366
363
if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
365
int nnal, s, i, size;
370
368
s = xavs_encoder_headers(x4->enc, &nal, &nnal);
372
avctx->extradata = av_malloc(s);
373
avctx->extradata_size = encode_nals(avctx, avctx->extradata, s, nal, nnal, 1);
370
avctx->extradata = p = av_malloc(s);
371
for (i = 0; i < nnal; i++) {
372
/* Don't put the SEI in extradata. */
373
if (nal[i].i_type == NAL_SEI) {
374
x4->sei = av_malloc( 5 + nal[i].i_payload * 4 / 3 );
375
if (xavs_nal_encode(x4->sei, &x4->sei_size, 1, nal + i) < 0)
380
size = xavs_nal_encode(p, &s, 1, nal + i);
385
avctx->extradata_size = p - avctx->extradata;
379
391
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
380
392
static const AVOption options[] = {
381
393
{ "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE },
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 },
394
{ "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, INT_MAX, VE },
395
{ "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, {.i64 = INT_MIN}, INT_MIN, INT_MAX, VE },
384
396
{ "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" },
386
{ "none", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" },
387
{ "spatial", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" },
388
{ "temporal", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" },
389
{ "auto", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" },
390
{ "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
391
{ "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
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 },
393
{ "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE},
397
{ "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, INT_MAX, VE, "direct-pred" },
398
{ "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" },
399
{ "spatial", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" },
400
{ "temporal", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" },
401
{ "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = XAVS_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" },
402
{ "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 1, VE},
403
{ "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 1, VE},
404
{ "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE },
405
{ "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 1, VE},