⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpegvideo.c

📁 mpeg4 video codec mpeg4 video codec
💻 C
📖 第 1 页 / 共 5 页
字号:
        for(i=0; i<s->max_b_frames+1; i++){            int is_p= i % (j+1) == j || i==s->max_b_frames;            input[i+1].pict_type= is_p ? P_TYPE : B_TYPE;            input[i+1].quality= s->last_lambda_for[input[i+1].pict_type];            out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[i+1]);            rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT;        }        /* get the delayed frames */        while(out_size){            out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);            rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT;        }        rd += c->error[0] + c->error[1] + c->error[2];        if(rd < best_rd){            best_rd= rd;            best_b_count= j;        }    }    av_freep(&outbuf);    avcodec_close(c);    av_freep(&c);    img_resample_close(resample);    for(i=0; i<s->max_b_frames+2; i++){        av_freep(&input[i].data[0]);    }    return best_b_count;}#endifstatic void select_input_picture(MpegEncContext *s){    int i;    for(i=1; i<MAX_PICTURE_COUNT; i++)        s->reordered_input_picture[i-1]= s->reordered_input_picture[i];    s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL;    /* set next picture type & ordering */    if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){        if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){            s->reordered_input_picture[0]= s->input_picture[0];            s->reordered_input_picture[0]->pict_type= I_TYPE;            s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++;        }else{            int b_frames;                        if(s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor){                if(s->picture_in_gop_number < s->gop_size && skip_check(s, s->input_picture[0], s->next_picture_ptr)){                //FIXME check that te gop check above is +-1 correct//av_log(NULL, AV_LOG_DEBUG, "skip %p %Ld\n", s->input_picture[0]->data[0], s->input_picture[0]->pts);                                    if(s->input_picture[0]->type == FF_BUFFER_TYPE_SHARED){                        for(i=0; i<4; i++)                            s->input_picture[0]->data[i]= NULL;                        s->input_picture[0]->type= 0;                                }else{                        assert(   s->input_picture[0]->type==FF_BUFFER_TYPE_USER                                || s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL);                                    s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]);                    }                    emms_c();                    ff_vbv_update(s, 0);                    goto no_output_pic;                }            }            if(s->flags&CODEC_FLAG_PASS2){                for(i=0; i<s->max_b_frames+1; i++){                    int pict_num= s->input_picture[0]->display_picture_number + i;                                        if(pict_num >= s->rc_context.num_entries)                         break;                    if(!s->input_picture[i]){                        s->rc_context.entry[pict_num-1].new_pict_type = P_TYPE;                        break;                    }                    s->input_picture[i]->pict_type=                         s->rc_context.entry[pict_num].new_pict_type;                }            }            if(s->avctx->b_frame_strategy==0){                b_frames= s->max_b_frames;                while(b_frames && !s->input_picture[b_frames]) b_frames--;            }else if(s->avctx->b_frame_strategy==1){                for(i=1; i<s->max_b_frames+1; i++){                    if(s->input_picture[i] && s->input_picture[i]->b_frame_score==0){                        s->input_picture[i]->b_frame_score=                             get_intra_count(s, s->input_picture[i  ]->data[0],                                                s->input_picture[i-1]->data[0], s->linesize) + 1;                    }                }                for(i=0; i<s->max_b_frames+1; i++){                    if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/40) break;                }                                                b_frames= FFMAX(0, i-1);                                /* reset scores */                for(i=0; i<b_frames+1; i++){                    s->input_picture[i]->b_frame_score=0;                }            }/*            else if(s->avctx->b_frame_strategy==2){                            b_frames= estimate_best_b_count(s);                        }*/            else{                av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n");                b_frames=0;            }            emms_c();//static int b_count=0;//b_count+= b_frames;//av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count);            for(i= b_frames - 1; i>=0; i--){                int type= s->input_picture[i]->pict_type;                if(type && type != B_TYPE)                    b_frames= i;            }            if(s->input_picture[b_frames]->pict_type == B_TYPE && b_frames == s->max_b_frames){                av_log(s->avctx, AV_LOG_ERROR, "warning, too many bframes in a row\n");            }            if(s->picture_in_gop_number + b_frames >= s->gop_size){              if((s->flags2 & CODEC_FLAG2_STRICT_GOP) && s->gop_size > s->picture_in_gop_number){                    b_frames= s->gop_size - s->picture_in_gop_number - 1;              }else{                if(s->flags & CODEC_FLAG_CLOSED_GOP)                    b_frames=0;                s->input_picture[b_frames]->pict_type= I_TYPE;            }            }                        if(   (s->flags & CODEC_FLAG_CLOSED_GOP)               && b_frames               && s->input_picture[b_frames]->pict_type== I_TYPE)                b_frames--;                                    s->reordered_input_picture[0]= s->input_picture[b_frames];            if(s->reordered_input_picture[0]->pict_type != I_TYPE)                s->reordered_input_picture[0]->pict_type= P_TYPE;            s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++;            for(i=0; i<b_frames; i++){                s->reordered_input_picture[i+1]= s->input_picture[i];                s->reordered_input_picture[i+1]->pict_type= B_TYPE;                s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++;            }        }    }no_output_pic:    if(s->reordered_input_picture[0]){        s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE ? 3 : 0;        copy_picture(&s->new_picture, s->reordered_input_picture[0]);        if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED){            // input is a shared pix, so we can't modifiy it -> alloc a new one & ensure that the shared one is reuseable                    int i= ff_find_unused_picture(s, 0);            Picture *pic= &s->picture[i];            /* mark us unused / free shared pic */            for(i=0; i<4; i++)                s->reordered_input_picture[0]->data[i]= NULL;            s->reordered_input_picture[0]->type= 0;                        pic->reference = s->reordered_input_picture[0]->reference;                        alloc_picture(s, pic, 0);            copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]);            s->current_picture_ptr= pic;        }else{            // input is not a shared pix -> reuse buffer for current_pix            assert(   s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER                    || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL);                        s->current_picture_ptr= s->reordered_input_picture[0];            for(i=0; i<4; i++){                s->new_picture.data[i]+=16;            }        }        copy_picture(&s->current_picture, s->current_picture_ptr);            s->picture_number= s->new_picture.display_picture_number;//printf("dpn:%d\n", s->picture_number);    }else{       memset(&s->new_picture, 0, sizeof(Picture));    }}#endif //CONFIG_ENCODERSstatic inline void gmc1_motion(MpegEncContext *s,                               uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,                               uint8_t **ref_picture){    uint8_t *ptr;    int offset, src_x, src_y, linesize, uvlinesize;    int motion_x, motion_y;    int emu=0;    motion_x= s->sprite_offset[0][0];    motion_y= s->sprite_offset[0][1];    src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1));    src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1));    motion_x<<=(3-s->sprite_warping_accuracy);    motion_y<<=(3-s->sprite_warping_accuracy);    src_x = clip(src_x, -16, s->width);    if (src_x == s->width)        motion_x =0;    src_y = clip(src_y, -16, s->height);    if (src_y == s->height)        motion_y =0;        linesize = s->linesize;    uvlinesize = s->uvlinesize;        ptr = ref_picture[0] + (src_y * linesize) + src_x;    if(s->flags&CODEC_FLAG_EMU_EDGE){        if(   (unsigned)src_x >= s->h_edge_pos - 17           || (unsigned)src_y >= s->v_edge_pos - 17){            ff_emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos);            ptr= s->edge_emu_buffer;        }    }        if((motion_x|motion_y)&7){        s->dsp.gmc1(dest_y  , ptr  , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);        s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);    }else{        int dxy;                dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2);        if (s->no_rounding){	    s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);        }else{            s->dsp.put_pixels_tab       [0][dxy](dest_y, ptr, linesize, 16);        }            }        if(s->flags&CODEC_FLAG_GRAY) return;    motion_x= s->sprite_offset[1][0];    motion_y= s->sprite_offset[1][1];    src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1));    src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1));    motion_x<<=(3-s->sprite_warping_accuracy);    motion_y<<=(3-s->sprite_warping_accuracy);    src_x = clip(src_x, -8, s->width>>1);    if (src_x == s->width>>1)        motion_x =0;    src_y = clip(src_y, -8, s->height>>1);    if (src_y == s->height>>1)        motion_y =0;    offset = (src_y * uvlinesize) + src_x;    ptr = ref_picture[1] + offset;    if(s->flags&CODEC_FLAG_EMU_EDGE){        if(   (unsigned)src_x >= (s->h_edge_pos>>1) - 9           || (unsigned)src_y >= (s->v_edge_pos>>1) - 9){            ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);        ptr= s->edge_emu_buffer;            emu=1;        }    }    s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);        ptr = ref_picture[2] + offset;    if(emu){        ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);        ptr= s->edge_emu_buffer;    }    s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);        return;}static inline void gmc_motion(MpegEncContext *s,                               uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,                               uint8_t **ref_picture){    uint8_t *ptr;    int linesize, uvlinesize;    const int a= s->sprite_warping_accuracy;    int ox, oy;    linesize = s->linesize;    uvlinesize = s->uvlinesize;    ptr = ref_picture[0];        ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16;    oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16;    s->dsp.gmc(dest_y, ptr, linesize, 16,           ox,            oy,            s->sprite_delta[0][0], s->sprite_delta[0][1],           s->sprite_delta[1][0], s->sprite_delta[1][1],            a+1, (1<<(2*a+1)) - s->no_rounding,           s->h_edge_pos, s->v_edge_pos);    s->dsp.gmc(dest_y+8, ptr, linesize, 16,           ox + s->sprite_delta[0][0]*8,            oy + s->sprite_delta[1][0]*8,            s->sprite_delta[0][0], s->sprite_delta[0][1],           s->sprite_delta[1][0], s->sprite_delta[1][1],            a+1, (1<<(2*a+1)) - s->no_rounding,           s->h_edge_pos, s->v_edge_pos);    if(s->flags&CODEC_FLAG_GRAY) return;    ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8;    oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8;    ptr = ref_picture[1];    s->dsp.gmc(dest_cb, ptr, uvlinesize, 8,           ox,            oy,            s->sprite_delta[0][0], s->sprite_delta[0][1],           s->sprite_delta[1][0], s->sprite_delta[1][1],            a+1, (1<<(2*a+1)) - s->no_rounding,           s->h_edge_pos>>1, s->v_edge_pos>>1);        ptr = ref_picture[2];    s->dsp.gmc(dest_cr, ptr, uvlinesize, 8,           ox,            oy,            s->sprite_delta[0][0], s->sprite_delta[0][1],           s->sprite_delta[1][0], s->sprite_delta[1][1],            a+1, (1<<(2*a+1)) - s->no_rounding,           s->h_edge_pos>>1, s->v_edge_pos>>1);}/** * Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples. * @param buf destination buffer * @param src source buffer * @param l

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -