libavcodec/mpegvideo_enc.c:2190: error: Buffer Overrun L2
  Offset: [min(1, `s->qscale`), max(31, `s->qscale`)] Size: 13 by call to `ff_mpeg1_encode_mb`.

libavcodec/mpegvideo_enc.c:1868:1: Parameter `s->qscale`
1866. }
1867. 
1868. static av_always_inline void encode_mb_internal(MpegEncContext *s,
      ^
1869.                                                 int motion_x, int motion_y,
1870.                                                 int mb_block_height,

libavcodec/mpegvideo_enc.c:2190:13: Call
2188.     case AV_CODEC_ID_MPEG2VIDEO:
2189.         if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
2190.             ff_mpeg1_encode_mb(s, s->block, motion_x, motion_y);
                  ^
2191.         break;
2192.     case AV_CODEC_ID_MPEG4:

libavcodec/mpeg12enc.c:938:1: Parameter `s->qscale`
  936. }
  937. 
  938. void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64],
       ^
  939.                         int motion_x, int motion_y)
  940. {

libavcodec/mpeg12enc.c:942:9: Call
  940. {
  941.     if (s->chroma_format == CHROMA_420)
  942.         mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6);
               ^
  943.     else
  944.         mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8);

libavcodec/mpeg12enc.c:660:1: Parameter `s->qscale`
    658. }
    659. 
    660. static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
         ^
    661.                                                       int16_t block[8][64],
    662.                                                       int motion_x, int motion_y,

libavcodec/mpeg12enc.c:710:17: Call
    708.                 /* macroblock_type: macroblock_quant = 1 */
    709.                 put_mb_modes(s, 2, 1, 0, 0);
    710.                 put_qscale(s);
                         ^
    711.             } else {
    712.                 /* macroblock_type: macroblock_quant = 0 */

libavcodec/mpeg12enc.c:342:1: <Offset trace>
340. }
341. 
342. static av_always_inline void put_qscale(MpegEncContext *s)
     ^
343. {
344.     if (s->q_scale_type) {

libavcodec/mpeg12enc.c:342:1: Parameter `s->qscale`
      340. }
      341. 
      342. static av_always_inline void put_qscale(MpegEncContext *s)
           ^
      343. {
      344.     if (s->q_scale_type) {

libavcodec/mpeg12enc.c:44:1: <Length trace>
42. 
43. 
44. static const uint8_t inv_non_linear_qscale[] = {
    ^
45.     0, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
46. };

libavcodec/mpeg12enc.c:44:1: Array declaration
      42. 
      43. 
      44. static const uint8_t inv_non_linear_qscale[] = {
          ^
      45.     0, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
      46. };

libavcodec/mpeg12enc.c:346:29: Array access: Offset: [min(1, s->qscale), max(31, s->qscale)] Size: 13 by call to `ff_mpeg1_encode_mb` 
      344.     if (s->q_scale_type) {
      345.         assert(s->qscale >= 1 && s->qscale <= 12);
      346.         put_bits(&s->pb, 5, inv_non_linear_qscale[s->qscale]);
                                       ^
      347.     } else {
      348.         put_bits(&s->pb, 5, s->qscale);

static av_always_inline void put_qscale(MpegEncContext *s)
{
    if (s->q_scale_type) {
        assert(s->qscale >= 1 && s->qscale <= 12);
        put_bits(&s->pb, 5, inv_non_linear_qscale[s->qscale]);
    } else {
        put_bits(&s->pb, 5, s->qscale);
    }
}
['static av_always_inline void encode_mb_internal(MpegEncContext *s,\n                                                int motion_x, int motion_y,\n                                                int mb_block_height,\n                                                int mb_block_count)\n{\n    int16_t weight[8][64];\n    int16_t orig[8][64];\n    const int mb_x = s->mb_x;\n    const int mb_y = s->mb_y;\n    int i;\n    int skip_dct[8];\n    int dct_offset = s->linesize * 8;\n    uint8_t *ptr_y, *ptr_cb, *ptr_cr;\n    ptrdiff_t wrap_y, wrap_c;\n    for (i = 0; i < mb_block_count; i++)\n        skip_dct[i] = s->skipdct;\n    if (s->adaptive_quant) {\n        const int last_qp = s->qscale;\n        const int mb_xy = mb_x + mb_y * s->mb_stride;\n        s->lambda = s->lambda_table[mb_xy];\n        update_qscale(s);\n        if (!(s->mpv_flags & FF_MPV_FLAG_QP_RD)) {\n            s->qscale = s->current_picture_ptr->qscale_table[mb_xy];\n            s->dquant = s->qscale - last_qp;\n            if (s->out_format == FMT_H263) {\n                s->dquant = av_clip(s->dquant, -2, 2);\n                if (s->codec_id == AV_CODEC_ID_MPEG4) {\n                    if (!s->mb_intra) {\n                        if (s->pict_type == AV_PICTURE_TYPE_B) {\n                            if (s->dquant & 1 || s->mv_dir & MV_DIRECT)\n                                s->dquant = 0;\n                        }\n                        if (s->mv_type == MV_TYPE_8X8)\n                            s->dquant = 0;\n                    }\n                }\n            }\n        }\n        ff_set_qscale(s, last_qp + s->dquant);\n    } else if (s->mpv_flags & FF_MPV_FLAG_QP_RD)\n        ff_set_qscale(s, s->qscale + s->dquant);\n    wrap_y = s->linesize;\n    wrap_c = s->uvlinesize;\n    ptr_y  = s->new_picture.f->data[0] +\n             (mb_y * 16 * wrap_y)              + mb_x * 16;\n    ptr_cb = s->new_picture.f->data[1] +\n             (mb_y * mb_block_height * wrap_c) + mb_x * 8;\n    ptr_cr = s->new_picture.f->data[2] +\n             (mb_y * mb_block_height * wrap_c) + mb_x * 8;\n    if (mb_x * 16 + 16 > s->width || mb_y * 16 + 16 > s->height) {\n        uint8_t *ebuf = s->edge_emu_buffer + 32;\n        s->vdsp.emulated_edge_mc(ebuf, ptr_y,\n                                 wrap_y, wrap_y,\n                                 16, 16, mb_x * 16, mb_y * 16,\n                                 s->width, s->height);\n        ptr_y = ebuf;\n        s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb,\n                                 wrap_c, wrap_c,\n                                 8, mb_block_height, mb_x * 8, mb_y * 8,\n                                 s->width >> 1, s->height >> 1);\n        ptr_cb = ebuf + 18 * wrap_y;\n        s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y + 8, ptr_cr,\n                                 wrap_c, wrap_c,\n                                 8, mb_block_height, mb_x * 8, mb_y * 8,\n                                 s->width >> 1, s->height >> 1);\n        ptr_cr = ebuf + 18 * wrap_y + 8;\n    }\n    if (s->mb_intra) {\n        if (s->flags & CODEC_FLAG_INTERLACED_DCT) {\n            int progressive_score, interlaced_score;\n            s->interlaced_dct = 0;\n            progressive_score = s->mecc.ildct_cmp[4](s, ptr_y, NULL, wrap_y, 8) +\n                                s->mecc.ildct_cmp[4](s, ptr_y + wrap_y * 8,\n                                                     NULL, wrap_y, 8) - 400;\n            if (progressive_score > 0) {\n                interlaced_score = s->mecc.ildct_cmp[4](s, ptr_y,\n                                                        NULL, wrap_y * 2, 8) +\n                                   s->mecc.ildct_cmp[4](s, ptr_y + wrap_y,\n                                                        NULL, wrap_y * 2, 8);\n                if (progressive_score > interlaced_score) {\n                    s->interlaced_dct = 1;\n                    dct_offset = wrap_y;\n                    wrap_y <<= 1;\n                    if (s->chroma_format == CHROMA_422)\n                        wrap_c <<= 1;\n                }\n            }\n        }\n        s->pdsp.get_pixels(s->block[0], ptr_y,                  wrap_y);\n        s->pdsp.get_pixels(s->block[1], ptr_y + 8,              wrap_y);\n        s->pdsp.get_pixels(s->block[2], ptr_y + dct_offset,     wrap_y);\n        s->pdsp.get_pixels(s->block[3], ptr_y + dct_offset + 8, wrap_y);\n        if (s->flags & CODEC_FLAG_GRAY) {\n            skip_dct[4] = 1;\n            skip_dct[5] = 1;\n        } else {\n            s->pdsp.get_pixels(s->block[4], ptr_cb, wrap_c);\n            s->pdsp.get_pixels(s->block[5], ptr_cr, wrap_c);\n            if (!s->chroma_y_shift) {\n                s->pdsp.get_pixels(s->block[6],\n                                   ptr_cb + (dct_offset >> 1), wrap_c);\n                s->pdsp.get_pixels(s->block[7],\n                                   ptr_cr + (dct_offset >> 1), wrap_c);\n            }\n        }\n    } else {\n        op_pixels_func (*op_pix)[4];\n        qpel_mc_func (*op_qpix)[16];\n        uint8_t *dest_y, *dest_cb, *dest_cr;\n        dest_y  = s->dest[0];\n        dest_cb = s->dest[1];\n        dest_cr = s->dest[2];\n        if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {\n            op_pix  = s->hdsp.put_pixels_tab;\n            op_qpix = s->qdsp.put_qpel_pixels_tab;\n        } else {\n            op_pix  = s->hdsp.put_no_rnd_pixels_tab;\n            op_qpix = s->qdsp.put_no_rnd_qpel_pixels_tab;\n        }\n        if (s->mv_dir & MV_DIR_FORWARD) {\n            ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 0,\n                          s->last_picture.f->data,\n                          op_pix, op_qpix);\n            op_pix  = s->hdsp.avg_pixels_tab;\n            op_qpix = s->qdsp.avg_qpel_pixels_tab;\n        }\n        if (s->mv_dir & MV_DIR_BACKWARD) {\n            ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 1,\n                          s->next_picture.f->data,\n                          op_pix, op_qpix);\n        }\n        if (s->flags & CODEC_FLAG_INTERLACED_DCT) {\n            int progressive_score, interlaced_score;\n            s->interlaced_dct = 0;\n            progressive_score = s->mecc.ildct_cmp[0](s, dest_y, ptr_y, wrap_y, 8) +\n                                s->mecc.ildct_cmp[0](s, dest_y + wrap_y * 8,\n                                                     ptr_y + wrap_y * 8,\n                                                     wrap_y, 8) - 400;\n            if (s->avctx->ildct_cmp == FF_CMP_VSSE)\n                progressive_score -= 400;\n            if (progressive_score > 0) {\n                interlaced_score = s->mecc.ildct_cmp[0](s, dest_y, ptr_y,\n                                                        wrap_y * 2, 8) +\n                                   s->mecc.ildct_cmp[0](s, dest_y + wrap_y,\n                                                        ptr_y + wrap_y,\n                                                        wrap_y * 2, 8);\n                if (progressive_score > interlaced_score) {\n                    s->interlaced_dct = 1;\n                    dct_offset = wrap_y;\n                    wrap_y <<= 1;\n                    if (s->chroma_format == CHROMA_422)\n                        wrap_c <<= 1;\n                }\n            }\n        }\n        s->pdsp.diff_pixels(s->block[0], ptr_y, dest_y, wrap_y);\n        s->pdsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y);\n        s->pdsp.diff_pixels(s->block[2], ptr_y + dct_offset,\n                            dest_y + dct_offset, wrap_y);\n        s->pdsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8,\n                            dest_y + dct_offset + 8, wrap_y);\n        if (s->flags & CODEC_FLAG_GRAY) {\n            skip_dct[4] = 1;\n            skip_dct[5] = 1;\n        } else {\n            s->pdsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c);\n            s->pdsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c);\n            if (!s->chroma_y_shift) {\n                s->pdsp.diff_pixels(s->block[6], ptr_cb + (dct_offset >> 1),\n                                    dest_cb + (dct_offset >> 1), wrap_c);\n                s->pdsp.diff_pixels(s->block[7], ptr_cr + (dct_offset >> 1),\n                                    dest_cr + (dct_offset >> 1), wrap_c);\n            }\n        }\n        if (s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] <\n                2 * s->qscale * s->qscale) {\n            if (s->mecc.sad[1](NULL, ptr_y, dest_y, wrap_y, 8) < 20 * s->qscale)\n                skip_dct[0] = 1;\n            if (s->mecc.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20 * s->qscale)\n                skip_dct[1] = 1;\n            if (s->mecc.sad[1](NULL, ptr_y + dct_offset, dest_y + dct_offset,\n                               wrap_y, 8) < 20 * s->qscale)\n                skip_dct[2] = 1;\n            if (s->mecc.sad[1](NULL, ptr_y + dct_offset + 8, dest_y + dct_offset + 8,\n                               wrap_y, 8) < 20 * s->qscale)\n                skip_dct[3] = 1;\n            if (s->mecc.sad[1](NULL, ptr_cb, dest_cb, wrap_c, 8) < 20 * s->qscale)\n                skip_dct[4] = 1;\n            if (s->mecc.sad[1](NULL, ptr_cr, dest_cr, wrap_c, 8) < 20 * s->qscale)\n                skip_dct[5] = 1;\n            if (!s->chroma_y_shift) {\n                if (s->mecc.sad[1](NULL, ptr_cb + (dct_offset >> 1),\n                                   dest_cb + (dct_offset >> 1),\n                                   wrap_c, 8) < 20 * s->qscale)\n                    skip_dct[6] = 1;\n                if (s->mecc.sad[1](NULL, ptr_cr + (dct_offset >> 1),\n                                   dest_cr + (dct_offset >> 1),\n                                   wrap_c, 8) < 20 * s->qscale)\n                    skip_dct[7] = 1;\n            }\n        }\n    }\n    if (s->quantizer_noise_shaping) {\n        if (!skip_dct[0])\n            get_visual_weight(weight[0], ptr_y                 , wrap_y);\n        if (!skip_dct[1])\n            get_visual_weight(weight[1], ptr_y              + 8, wrap_y);\n        if (!skip_dct[2])\n            get_visual_weight(weight[2], ptr_y + dct_offset    , wrap_y);\n        if (!skip_dct[3])\n            get_visual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y);\n        if (!skip_dct[4])\n            get_visual_weight(weight[4], ptr_cb                , wrap_c);\n        if (!skip_dct[5])\n            get_visual_weight(weight[5], ptr_cr                , wrap_c);\n        if (!s->chroma_y_shift) {\n            if (!skip_dct[6])\n                get_visual_weight(weight[6], ptr_cb + (dct_offset >> 1),\n                                  wrap_c);\n            if (!skip_dct[7])\n                get_visual_weight(weight[7], ptr_cr + (dct_offset >> 1),\n                                  wrap_c);\n        }\n        memcpy(orig[0], s->block[0], sizeof(int16_t) * 64 * mb_block_count);\n    }\n    assert(s->out_format != FMT_MJPEG || s->qscale == 8);\n    {\n        for (i = 0; i < mb_block_count; i++) {\n            if (!skip_dct[i]) {\n                int overflow;\n                s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow);\n                if (overflow)\n                    clip_coeffs(s, s->block[i], s->block_last_index[i]);\n            } else\n                s->block_last_index[i] = -1;\n        }\n        if (s->quantizer_noise_shaping) {\n            for (i = 0; i < mb_block_count; i++) {\n                if (!skip_dct[i]) {\n                    s->block_last_index[i] =\n                        dct_quantize_refine(s, s->block[i], weight[i],\n                                            orig[i], i, s->qscale);\n                }\n            }\n        }\n        if (s->luma_elim_threshold && !s->mb_intra)\n            for (i = 0; i < 4; i++)\n                dct_single_coeff_elimination(s, i, s->luma_elim_threshold);\n        if (s->chroma_elim_threshold && !s->mb_intra)\n            for (i = 4; i < mb_block_count; i++)\n                dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);\n        if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {\n            for (i = 0; i < mb_block_count; i++) {\n                if (s->block_last_index[i] == -1)\n                    s->coded_score[i] = INT_MAX / 256;\n            }\n        }\n    }\n    if ((s->flags & CODEC_FLAG_GRAY) && s->mb_intra) {\n        s->block_last_index[4] =\n        s->block_last_index[5] = 0;\n        s->block[4][0] =\n        s->block[5][0] = (1024 + s->c_dc_scale / 2) / s->c_dc_scale;\n    }\n    if (s->alternate_scan && s->dct_quantize != ff_dct_quantize_c) {\n        for (i = 0; i < mb_block_count; i++) {\n            int j;\n            if (s->block_last_index[i] > 0) {\n                for (j = 63; j > 0; j--) {\n                    if (s->block[i][s->intra_scantable.permutated[j]])\n                        break;\n                }\n                s->block_last_index[i] = j;\n            }\n        }\n    }\n    switch(s->codec_id){\n    case AV_CODEC_ID_MPEG1VIDEO:\n    case AV_CODEC_ID_MPEG2VIDEO:\n        if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)\n            ff_mpeg1_encode_mb(s, s->block, motion_x, motion_y);\n        break;\n    case AV_CODEC_ID_MPEG4:\n        if (CONFIG_MPEG4_ENCODER)\n            ff_mpeg4_encode_mb(s, s->block, motion_x, motion_y);\n        break;\n    case AV_CODEC_ID_MSMPEG4V2:\n    case AV_CODEC_ID_MSMPEG4V3:\n    case AV_CODEC_ID_WMV1:\n        if (CONFIG_MSMPEG4_ENCODER)\n            ff_msmpeg4_encode_mb(s, s->block, motion_x, motion_y);\n        break;\n    case AV_CODEC_ID_WMV2:\n        if (CONFIG_WMV2_ENCODER)\n            ff_wmv2_encode_mb(s, s->block, motion_x, motion_y);\n        break;\n    case AV_CODEC_ID_H261:\n        if (CONFIG_H261_ENCODER)\n            ff_h261_encode_mb(s, s->block, motion_x, motion_y);\n        break;\n    case AV_CODEC_ID_H263:\n    case AV_CODEC_ID_H263P:\n    case AV_CODEC_ID_FLV1:\n    case AV_CODEC_ID_RV10:\n    case AV_CODEC_ID_RV20:\n        if (CONFIG_H263_ENCODER)\n            ff_h263_encode_mb(s, s->block, motion_x, motion_y);\n        break;\n    case AV_CODEC_ID_MJPEG:\n        if (CONFIG_MJPEG_ENCODER)\n            ff_mjpeg_encode_mb(s, s->block);\n        break;\n    default:\n        assert(0);\n    }\n}', 'void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64],\n                        int motion_x, int motion_y)\n{\n    if (s->chroma_format == CHROMA_420)\n        mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6);\n    else\n        mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8);\n}', 'static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,\n                                                      int16_t block[8][64],\n                                                      int motion_x, int motion_y,\n                                                      int mb_block_count)\n{\n    int i, cbp;\n    const int mb_x     = s->mb_x;\n    const int mb_y     = s->mb_y;\n    const int first_mb = mb_x == s->resync_mb_x && mb_y == s->resync_mb_y;\n    cbp = 0;\n    for (i = 0; i < mb_block_count; i++)\n        if (s->block_last_index[i] >= 0)\n            cbp |= 1 << (mb_block_count - 1 - i);\n    if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 &&\n        (mb_x != s->mb_width - 1 ||\n         (mb_y != s->mb_height - 1 && s->codec_id == AV_CODEC_ID_MPEG1VIDEO)) &&\n        ((s->pict_type == AV_PICTURE_TYPE_P && (motion_x | motion_y) == 0) ||\n         (s->pict_type == AV_PICTURE_TYPE_B && s->mv_dir == s->last_mv_dir &&\n          (((s->mv_dir & MV_DIR_FORWARD)\n            ? ((s->mv[0][0][0] - s->last_mv[0][0][0]) |\n               (s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) |\n           ((s->mv_dir & MV_DIR_BACKWARD)\n            ? ((s->mv[1][0][0] - s->last_mv[1][0][0]) |\n               (s->mv[1][0][1] - s->last_mv[1][0][1])) : 0)) == 0))) {\n        s->mb_skip_run++;\n        s->qscale -= s->dquant;\n        s->skip_count++;\n        s->misc_bits++;\n        s->last_bits++;\n        if (s->pict_type == AV_PICTURE_TYPE_P) {\n            s->last_mv[0][0][0] =\n            s->last_mv[0][0][1] =\n            s->last_mv[0][1][0] =\n            s->last_mv[0][1][1] = 0;\n        }\n    } else {\n        if (first_mb) {\n            assert(s->mb_skip_run == 0);\n            encode_mb_skip_run(s, s->mb_x);\n        } else {\n            encode_mb_skip_run(s, s->mb_skip_run);\n        }\n        if (s->pict_type == AV_PICTURE_TYPE_I) {\n            if (s->dquant && cbp) {\n                put_mb_modes(s, 2, 1, 0, 0);\n                put_qscale(s);\n            } else {\n                put_mb_modes(s, 1, 1, 0, 0);\n                s->qscale -= s->dquant;\n            }\n            s->misc_bits += get_bits_diff(s);\n            s->i_count++;\n        } else if (s->mb_intra) {\n            if (s->dquant && cbp) {\n                put_mb_modes(s, 6, 0x01, 0, 0);\n                put_qscale(s);\n            } else {\n                put_mb_modes(s, 5, 0x03, 0, 0);\n                s->qscale -= s->dquant;\n            }\n            s->misc_bits += get_bits_diff(s);\n            s->i_count++;\n            memset(s->last_mv, 0, sizeof(s->last_mv));\n        } else if (s->pict_type == AV_PICTURE_TYPE_P) {\n            if (s->mv_type == MV_TYPE_16X16) {\n                if (cbp != 0) {\n                    if ((motion_x | motion_y) == 0) {\n                        if (s->dquant) {\n                            put_mb_modes(s, 5, 1, 0, 0);\n                            put_qscale(s);\n                        } else {\n                            put_mb_modes(s, 2, 1, 0, 0);\n                        }\n                        s->misc_bits += get_bits_diff(s);\n                    } else {\n                        if (s->dquant) {\n                            put_mb_modes(s, 5, 2, 1, 0);\n                            put_qscale(s);\n                        } else {\n                            put_mb_modes(s, 1, 1, 1, 0);\n                        }\n                        s->misc_bits += get_bits_diff(s);\n                        mpeg1_encode_motion(s,\n                                            motion_x - s->last_mv[0][0][0],\n                                            s->f_code);\n                        mpeg1_encode_motion(s,\n                                            motion_y - s->last_mv[0][0][1],\n                                            s->f_code);\n                        s->mv_bits += get_bits_diff(s);\n                    }\n                } else {\n                    put_bits(&s->pb, 3, 1);\n                    if (!s->frame_pred_frame_dct)\n                        put_bits(&s->pb, 2, 2);\n                    s->misc_bits += get_bits_diff(s);\n                    mpeg1_encode_motion(s,\n                                        motion_x - s->last_mv[0][0][0],\n                                        s->f_code);\n                    mpeg1_encode_motion(s,\n                                        motion_y - s->last_mv[0][0][1],\n                                        s->f_code);\n                    s->qscale  -= s->dquant;\n                    s->mv_bits += get_bits_diff(s);\n                }\n                s->last_mv[0][1][0] = s->last_mv[0][0][0] = motion_x;\n                s->last_mv[0][1][1] = s->last_mv[0][0][1] = motion_y;\n            } else {\n                assert(!s->frame_pred_frame_dct && s->mv_type == MV_TYPE_FIELD);\n                if (cbp) {\n                    if (s->dquant) {\n                        put_mb_modes(s, 5, 2, 1, 1);\n                        put_qscale(s);\n                    } else {\n                        put_mb_modes(s, 1, 1, 1, 1);\n                    }\n                } else {\n                    put_bits(&s->pb, 3, 1);\n                    put_bits(&s->pb, 2, 1);\n                    s->qscale -= s->dquant;\n                }\n                s->misc_bits += get_bits_diff(s);\n                for (i = 0; i < 2; i++) {\n                    put_bits(&s->pb, 1, s->field_select[0][i]);\n                    mpeg1_encode_motion(s,\n                                        s->mv[0][i][0] - s->last_mv[0][i][0],\n                                        s->f_code);\n                    mpeg1_encode_motion(s,\n                                        s->mv[0][i][1] - (s->last_mv[0][i][1] >> 1),\n                                        s->f_code);\n                    s->last_mv[0][i][0] = s->mv[0][i][0];\n                    s->last_mv[0][i][1] = 2 * s->mv[0][i][1];\n                }\n                s->mv_bits += get_bits_diff(s);\n            }\n            if (cbp) {\n                if (s->chroma_y_shift) {\n                    put_bits(&s->pb,\n                             ff_mpeg12_mbPatTable[cbp][1],\n                             ff_mpeg12_mbPatTable[cbp][0]);\n                } else {\n                    put_bits(&s->pb,\n                             ff_mpeg12_mbPatTable[cbp >> 2][1],\n                             ff_mpeg12_mbPatTable[cbp >> 2][0]);\n                    put_sbits(&s->pb, 2, cbp);\n                }\n            }\n            s->f_count++;\n        } else {\n            if (s->mv_type == MV_TYPE_16X16) {\n                if (cbp) {\n                    if (s->dquant) {\n                        if (s->mv_dir == MV_DIR_FORWARD)\n                            put_mb_modes(s, 6, 3, 1, 0);\n                        else\n                            put_mb_modes(s, 8 - s->mv_dir, 2, 1, 0);\n                        put_qscale(s);\n                    } else {\n                        put_mb_modes(s, 5 - s->mv_dir, 3, 1, 0);\n                    }\n                } else {\n                    put_bits(&s->pb, 5 - s->mv_dir, 2);\n                    if (!s->frame_pred_frame_dct)\n                        put_bits(&s->pb, 2, 2);\n                    s->qscale -= s->dquant;\n                }\n                s->misc_bits += get_bits_diff(s);\n                if (s->mv_dir & MV_DIR_FORWARD) {\n                    mpeg1_encode_motion(s,\n                                        s->mv[0][0][0] - s->last_mv[0][0][0],\n                                        s->f_code);\n                    mpeg1_encode_motion(s,\n                                        s->mv[0][0][1] - s->last_mv[0][0][1],\n                                        s->f_code);\n                    s->last_mv[0][0][0] =\n                    s->last_mv[0][1][0] = s->mv[0][0][0];\n                    s->last_mv[0][0][1] =\n                    s->last_mv[0][1][1] = s->mv[0][0][1];\n                    s->f_count++;\n                }\n                if (s->mv_dir & MV_DIR_BACKWARD) {\n                    mpeg1_encode_motion(s,\n                                        s->mv[1][0][0] - s->last_mv[1][0][0],\n                                        s->b_code);\n                    mpeg1_encode_motion(s,\n                                        s->mv[1][0][1] - s->last_mv[1][0][1],\n                                        s->b_code);\n                    s->last_mv[1][0][0] =\n                    s->last_mv[1][1][0] = s->mv[1][0][0];\n                    s->last_mv[1][0][1] =\n                    s->last_mv[1][1][1] = s->mv[1][0][1];\n                    s->b_count++;\n                }\n            } else {\n                assert(s->mv_type == MV_TYPE_FIELD);\n                assert(!s->frame_pred_frame_dct);\n                if (cbp) {\n                    if (s->dquant) {\n                        if (s->mv_dir == MV_DIR_FORWARD)\n                            put_mb_modes(s, 6, 3, 1, 1);\n                        else\n                            put_mb_modes(s, 8 - s->mv_dir, 2, 1, 1);\n                        put_qscale(s);\n                    } else {\n                        put_mb_modes(s, 5 - s->mv_dir, 3, 1, 1);\n                    }\n                } else {\n                    put_bits(&s->pb, 5 - s->mv_dir, 2);\n                    put_bits(&s->pb, 2, 1);\n                    s->qscale -= s->dquant;\n                }\n                s->misc_bits += get_bits_diff(s);\n                if (s->mv_dir & MV_DIR_FORWARD) {\n                    for (i = 0; i < 2; i++) {\n                        put_bits(&s->pb, 1, s->field_select[0][i]);\n                        mpeg1_encode_motion(s,\n                                            s->mv[0][i][0] - s->last_mv[0][i][0],\n                                            s->f_code);\n                        mpeg1_encode_motion(s,\n                                            s->mv[0][i][1] - (s->last_mv[0][i][1] >> 1),\n                                            s->f_code);\n                        s->last_mv[0][i][0] = s->mv[0][i][0];\n                        s->last_mv[0][i][1] = s->mv[0][i][1] * 2;\n                    }\n                    s->f_count++;\n                }\n                if (s->mv_dir & MV_DIR_BACKWARD) {\n                    for (i = 0; i < 2; i++) {\n                        put_bits(&s->pb, 1, s->field_select[1][i]);\n                        mpeg1_encode_motion(s,\n                                            s->mv[1][i][0] - s->last_mv[1][i][0],\n                                            s->b_code);\n                        mpeg1_encode_motion(s,\n                                            s->mv[1][i][1] - (s->last_mv[1][i][1] >> 1),\n                                            s->b_code);\n                        s->last_mv[1][i][0] = s->mv[1][i][0];\n                        s->last_mv[1][i][1] = s->mv[1][i][1] * 2;\n                    }\n                    s->b_count++;\n                }\n            }\n            s->mv_bits += get_bits_diff(s);\n            if (cbp) {\n                if (s->chroma_y_shift) {\n                    put_bits(&s->pb,\n                             ff_mpeg12_mbPatTable[cbp][1],\n                             ff_mpeg12_mbPatTable[cbp][0]);\n                } else {\n                    put_bits(&s->pb,\n                             ff_mpeg12_mbPatTable[cbp >> 2][1],\n                             ff_mpeg12_mbPatTable[cbp >> 2][0]);\n                    put_sbits(&s->pb, 2, cbp);\n                }\n            }\n        }\n        for (i = 0; i < mb_block_count; i++)\n            if (cbp & (1 << (mb_block_count - 1 - i)))\n                mpeg1_encode_block(s, block[i], i);\n        s->mb_skip_run = 0;\n        if (s->mb_intra)\n            s->i_tex_bits += get_bits_diff(s);\n        else\n            s->p_tex_bits += get_bits_diff(s);\n    }\n}', 'static av_always_inline void put_qscale(MpegEncContext *s)\n{\n    if (s->q_scale_type) {\n        assert(s->qscale >= 1 && s->qscale <= 12);\n        put_bits(&s->pb, 5, inv_non_linear_qscale[s->qscale]);\n    } else {\n        put_bits(&s->pb, 5, s->qscale);\n    }\n}']