double ff_eval2(const char *s, double *const_value, const char **const_name, double (**func1)(void *, double), const char **func1_name, double (**func2)(void *, double, double), char **func2_name, void *opaque, const char **error){ AVEvalExpr * e = ff_parse(s, const_name, func1, func1_name, func2, func2_name, error); double d; if (!e) return 0;//NAN; d = ff_parse_eval(e, const_value, opaque); ff_eval_free(e); return d; }
static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ mp_image_t *dmpi; int x,y, plane; if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ // no DR, so get a new image! hope we'll get DR buffer: vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, mpi->w,mpi->h); } dmpi= vf->dmpi; vf->priv->mpi= mpi; vf_clone_mpi_attributes(dmpi, mpi); for(plane=0; plane<3; plane++){ int w= mpi->w >> (plane ? mpi->chroma_x_shift : 0); int h= mpi->h >> (plane ? mpi->chroma_y_shift : 0); uint8_t *dst = dmpi->planes[plane]; int dst_stride= dmpi->stride[plane]; double const_values[]={ M_PI, M_E, 0, 0, w, h, vf->priv->framenum, w/(double)mpi->w, h/(double)mpi->h, 0 }; if (!vf->priv->e[plane]) continue; for(y=0; y<h; y++){ const_values[3]=y; for(x=0; x<w; x++){ const_values[2]=x; dst[x+y* dst_stride]= ff_parse_eval(vf->priv->e[plane], const_values, vf); } } } vf->priv->framenum++; return vf_next_put_image(vf,dmpi, pts); }
/** * modifies the bitrate curve from pass1 for one frame */ static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num){ RateControlContext *rcc= &s->rc_context; AVCodecContext *a= s->avctx; double q, bits; const int pict_type= rce->new_pict_type; const double mb_num= s->mb_num; int i; double const_values[]={ M_PI, M_E, rce->i_tex_bits*rce->qscale, rce->p_tex_bits*rce->qscale, (rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale, rce->mv_bits/mb_num, rce->pict_type == FF_B_TYPE ? (rce->f_code + rce->b_code)*0.5 : rce->f_code, rce->i_count/mb_num, rce->mc_mb_var_sum/mb_num, rce->mb_var_sum/mb_num, rce->pict_type == FF_I_TYPE, rce->pict_type == FF_P_TYPE, rce->pict_type == FF_B_TYPE, rcc->qscale_sum[pict_type] / (double)rcc->frame_count[pict_type], a->qcompress, /* rcc->last_qscale_for[FF_I_TYPE], rcc->last_qscale_for[FF_P_TYPE], rcc->last_qscale_for[FF_B_TYPE], rcc->next_non_b_qscale,*/ rcc->i_cplx_sum[FF_I_TYPE] / (double)rcc->frame_count[FF_I_TYPE], rcc->i_cplx_sum[FF_P_TYPE] / (double)rcc->frame_count[FF_P_TYPE], rcc->p_cplx_sum[FF_P_TYPE] / (double)rcc->frame_count[FF_P_TYPE], rcc->p_cplx_sum[FF_B_TYPE] / (double)rcc->frame_count[FF_B_TYPE], (rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / (double)rcc->frame_count[pict_type], 0 }; bits= ff_parse_eval(rcc->rc_eq_eval, const_values, rce); #ifdef __GNUC__ if (isnan(bits)) { av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->avctx->rc_eq); return -1; } #endif rcc->pass1_rc_eq_output_sum+= bits; bits*=rate_factor; if(bits<0.0) bits=0.0; bits+= 1.0; //avoid 1/0 issues /* user override */ for(i=0; i<s->avctx->rc_override_count; i++){ RcOverride *rco= s->avctx->rc_override; if(rco[i].start_frame > frame_num) continue; if(rco[i].end_frame < frame_num) continue; if(rco[i].qscale) bits= qp2bits(rce, rco[i].qscale); //FIXME move at end to really force it? else bits*= rco[i].quality_factor; } q= bits2qp(rce, bits); /* I/B difference */ if (pict_type==FF_I_TYPE && s->avctx->i_quant_factor<0.0) q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset; else if(pict_type==FF_B_TYPE && s->avctx->b_quant_factor<0.0) q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset; if(q<1) q=1; return q; }