if (s->me_method < ME_EPZS) s->mv_penalty = default_mv_penalty;
if (s->me_method < ME_EPZS) s->me.mv_penalty = default_mv_penalty;
int MPV_encode_init(AVCodecContext *avctx){    MpegEncContext *s = avctx->priv_data;    int i;    avctx->pix_fmt = PIX_FMT_YUV420P;    s->bit_rate = avctx->bit_rate;    s->bit_rate_tolerance = avctx->bit_rate_tolerance;    s->frame_rate = avctx->frame_rate;    s->width = avctx->width;    s->height = avctx->height;    if(avctx->gop_size > 600){        fprintf(stderr, "Warning keyframe interval too large! reducing it ...\n");        avctx->gop_size=600;    }    s->gop_size = avctx->gop_size;    s->rtp_mode = avctx->rtp_mode;    s->rtp_payload_size = avctx->rtp_payload_size;    if (avctx->rtp_callback)        s->rtp_callback = avctx->rtp_callback;    s->qmin= avctx->qmin;    s->qmax= avctx->qmax;    s->max_qdiff= avctx->max_qdiff;    s->qcompress= avctx->qcompress;    s->qblur= avctx->qblur;    s->avctx = avctx;    s->flags= avctx->flags;    s->max_b_frames= avctx->max_b_frames;    s->b_frame_strategy= avctx->b_frame_strategy;    s->codec_id= avctx->codec->id;    s->luma_elim_threshold  = avctx->luma_elim_threshold;    s->chroma_elim_threshold= avctx->chroma_elim_threshold;    s->strict_std_compliance= avctx->strict_std_compliance;    s->data_partitioning= avctx->flags & CODEC_FLAG_PART;    s->mpeg_quant= avctx->mpeg_quant;    if (s->gop_size <= 1) {        s->intra_only = 1;        s->gop_size = 12;    } else {        s->intra_only = 0;    }    /* ME algorithm */    if (avctx->me_method == 0)        /* For compatibility */        s->me_method = motion_estimation_method;    else        s->me_method = avctx->me_method;    /* Fixed QSCALE */    s->fixed_qscale = (avctx->flags & CODEC_FLAG_QSCALE);        s->adaptive_quant= (   s->avctx->lumi_masking                        || s->avctx->dark_masking                        || s->avctx->temporal_cplx_masking                         || s->avctx->spatial_cplx_masking                        || s->avctx->p_masking)                       && !s->fixed_qscale;        s->progressive_sequence= !(avctx->flags & CODEC_FLAG_INTERLACED_DCT);    switch(avctx->codec->id) {    case CODEC_ID_MPEG1VIDEO:        s->out_format = FMT_MPEG1;        avctx->delay=0; //FIXME not sure, should check the spec        break;    case CODEC_ID_MJPEG:        s->out_format = FMT_MJPEG;        s->intra_only = 1; /* force intra only for jpeg */        s->mjpeg_write_tables = 1; /* write all tables */	s->mjpeg_data_only_frames = 0; /* write all the needed headers */        s->mjpeg_vsample[0] = 2; /* set up default sampling factors */        s->mjpeg_vsample[1] = 1; /* the only currently supported values */        s->mjpeg_vsample[2] = 1;         s->mjpeg_hsample[0] = 2;        s->mjpeg_hsample[1] = 1;         s->mjpeg_hsample[2] = 1;         if (mjpeg_init(s) < 0)            return -1;        avctx->delay=0;        s->low_delay=1;        break;    case CODEC_ID_H263:        if (h263_get_picture_format(s->width, s->height) == 7) {            printf("Input picture size isn't suitable for h263 codec! try h263+\n");            return -1;        }        s->out_format = FMT_H263;        avctx->delay=0;        s->low_delay=1;        break;    case CODEC_ID_H263P:        s->out_format = FMT_H263;        s->h263_plus = 1;        s->unrestricted_mv = 1;        s->h263_aic = 1;                /* These are just to be sure */        s->umvplus = 0;        s->umvplus_dec = 0;        avctx->delay=0;        s->low_delay=1;        break;    case CODEC_ID_RV10:        s->out_format = FMT_H263;        s->h263_rv10 = 1;        avctx->delay=0;        s->low_delay=1;        break;    case CODEC_ID_MPEG4:        s->out_format = FMT_H263;        s->h263_pred = 1;        s->unrestricted_mv = 1;        s->low_delay= s->max_b_frames ? 0 : 1;        avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);        break;    case CODEC_ID_MSMPEG4V1:        s->out_format = FMT_H263;        s->h263_msmpeg4 = 1;        s->h263_pred = 1;        s->unrestricted_mv = 1;        s->msmpeg4_version= 1;        avctx->delay=0;        s->low_delay=1;        break;    case CODEC_ID_MSMPEG4V2:        s->out_format = FMT_H263;        s->h263_msmpeg4 = 1;        s->h263_pred = 1;        s->unrestricted_mv = 1;        s->msmpeg4_version= 2;        avctx->delay=0;        s->low_delay=1;        break;    case CODEC_ID_MSMPEG4V3:        s->out_format = FMT_H263;        s->h263_msmpeg4 = 1;        s->h263_pred = 1;        s->unrestricted_mv = 1;        s->msmpeg4_version= 3;        avctx->delay=0;        s->low_delay=1;        break;    case CODEC_ID_WMV1:        s->out_format = FMT_H263;        s->h263_msmpeg4 = 1;        s->h263_pred = 1;        s->unrestricted_mv = 1;        s->msmpeg4_version= 4;        avctx->delay=0;        s->low_delay=1;        break;    case CODEC_ID_WMV2:        s->out_format = FMT_H263;        s->h263_msmpeg4 = 1;        s->h263_pred = 1;        s->unrestricted_mv = 1;        s->msmpeg4_version= 5;        avctx->delay=0;        s->low_delay=1;        break;    default:        return -1;    }        { /* set up some save defaults, some codecs might override them later */        static int done=0;        if(!done){            int i;            done=1;            default_mv_penalty= av_mallocz( sizeof(UINT16)*(MAX_FCODE+1)*(2*MAX_MV+1) );            memset(default_mv_penalty, 0, sizeof(UINT16)*(MAX_FCODE+1)*(2*MAX_MV+1));            memset(default_fcode_tab , 0, sizeof(UINT8)*(2*MAX_MV+1));            for(i=-16; i<16; i++){                default_fcode_tab[i + MAX_MV]= 1;            }        }    }    s->mv_penalty= default_mv_penalty;    s->fcode_tab= default_fcode_tab;    s->y_dc_scale_table=    s->c_dc_scale_table= ff_mpeg1_dc_scale_table;     /* dont use mv_penalty table for crap MV as it would be confused */    if (s->me_method < ME_EPZS) s->mv_penalty = default_mv_penalty;    s->encoding = 1;    /* init */    if (MPV_common_init(s) < 0)        return -1;    #ifdef CONFIG_ENCODERS    if (s->out_format == FMT_H263)        h263_encode_init(s);    else if (s->out_format == FMT_MPEG1)        ff_mpeg1_encode_init(s);    if(s->msmpeg4_version)        ff_msmpeg4_encode_init(s);#endif    /* init default q matrix */    for(i=0;i<64;i++) {        int j= s->idct_permutation[i];        if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){            s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];            s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i];        }else if(s->out_format == FMT_H263){            s->intra_matrix[j] =            s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];        }else{ /* mpeg1 */            s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];            s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];        }    }    /* precompute matrix */    /* for mjpeg, we do include qscale in the matrix */    if (s->out_format != FMT_MJPEG) {        convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias,                        s->intra_matrix, s->intra_quant_bias, 1, 31);        convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias,                        s->inter_matrix, s->inter_quant_bias, 1, 31);    }    if(ff_rate_control_init(s) < 0)        return -1;    s->picture_number = 0;    s->picture_in_gop_number = 0;    s->fake_picture_number = 0;    /* motion detector init */    s->f_code = 1;    s->b_code = 1;    return 0;}