Mercurial > libavcodec.hg
comparison mpegvideo.c @ 2381:cfc9e0489859 libavcodec
frame skip support
author | michael |
---|---|
date | Wed, 08 Dec 2004 11:46:16 +0000 |
parents | 3daf36fd1999 |
children | 23e7af611c34 |
comparison
equal
deleted
inserted
replaced
2380:3daf36fd1999 | 2381:cfc9e0489859 |
---|---|
2016 s->input_picture[encoding_delay]= (Picture*)pic; | 2016 s->input_picture[encoding_delay]= (Picture*)pic; |
2017 | 2017 |
2018 return 0; | 2018 return 0; |
2019 } | 2019 } |
2020 | 2020 |
2021 static inline int block_max(DCTELEM *block){ | |
2022 int i, max; | |
2023 | |
2024 max=0; | |
2025 for(i=0; i<64; i++){ | |
2026 int v= ABS(block[i]); | |
2027 if(v>max) max= v; | |
2028 } | |
2029 return max; | |
2030 } | |
2031 | |
2032 static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){ | |
2033 int x, y, plane; | |
2034 int score=0; | |
2035 | |
2036 for(plane=0; plane<3; plane++){ | |
2037 const int stride= p->linesize[plane]; | |
2038 const int bw= plane ? 1 : 2; | |
2039 for(y=0; y<s->mb_height*bw; y++){ | |
2040 for(x=0; x<s->mb_width*bw; x++){ | |
2041 int v; | |
2042 | |
2043 s->dsp.diff_pixels(s->block[0], p->data[plane] + 8*(x + y*stride), ref->data[plane] + 8*(x + y*stride), stride); | |
2044 v= block_max(s->block[0]); | |
2045 | |
2046 if(v>score) | |
2047 score=v; | |
2048 } | |
2049 } | |
2050 } | |
2051 | |
2052 if(score < s->avctx->frame_skip_threshold) | |
2053 return 1; | |
2054 if(score < ((s->avctx->frame_skip_factor * s->lambda)>>8)) | |
2055 return 1; | |
2056 return 0; | |
2057 } | |
2058 | |
2021 static void select_input_picture(MpegEncContext *s){ | 2059 static void select_input_picture(MpegEncContext *s){ |
2022 int i; | 2060 int i; |
2023 | 2061 |
2024 for(i=1; i<MAX_PICTURE_COUNT; i++) | 2062 for(i=1; i<MAX_PICTURE_COUNT; i++) |
2025 s->reordered_input_picture[i-1]= s->reordered_input_picture[i]; | 2063 s->reordered_input_picture[i-1]= s->reordered_input_picture[i]; |
2031 s->reordered_input_picture[0]= s->input_picture[0]; | 2069 s->reordered_input_picture[0]= s->input_picture[0]; |
2032 s->reordered_input_picture[0]->pict_type= I_TYPE; | 2070 s->reordered_input_picture[0]->pict_type= I_TYPE; |
2033 s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; | 2071 s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; |
2034 }else{ | 2072 }else{ |
2035 int b_frames; | 2073 int b_frames; |
2074 | |
2075 if(s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor){ | |
2076 if(skip_check(s, s->input_picture[0], s->next_picture_ptr)){ | |
2077 //av_log(NULL, AV_LOG_DEBUG, "skip %p %Ld\n", s->input_picture[0]->data[0], s->input_picture[0]->pts); | |
2078 | |
2079 if(s->input_picture[0]->type == FF_BUFFER_TYPE_SHARED){ | |
2080 for(i=0; i<4; i++) | |
2081 s->input_picture[0]->data[i]= NULL; | |
2082 s->input_picture[0]->type= 0; | |
2083 }else{ | |
2084 assert( s->input_picture[0]->type==FF_BUFFER_TYPE_USER | |
2085 || s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); | |
2036 | 2086 |
2087 s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]); | |
2088 } | |
2089 | |
2090 goto no_output_pic; | |
2091 } | |
2092 } | |
2093 | |
2037 if(s->flags&CODEC_FLAG_PASS2){ | 2094 if(s->flags&CODEC_FLAG_PASS2){ |
2038 for(i=0; i<s->max_b_frames+1; i++){ | 2095 for(i=0; i<s->max_b_frames+1; i++){ |
2039 int pict_num= s->input_picture[0]->display_picture_number + i; | 2096 int pict_num= s->input_picture[0]->display_picture_number + i; |
2040 | 2097 |
2041 if(pict_num >= s->rc_context.num_entries) | 2098 if(pict_num >= s->rc_context.num_entries) |
2114 s->reordered_input_picture[i+1]->pict_type= B_TYPE; | 2171 s->reordered_input_picture[i+1]->pict_type= B_TYPE; |
2115 s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++; | 2172 s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++; |
2116 } | 2173 } |
2117 } | 2174 } |
2118 } | 2175 } |
2119 | 2176 no_output_pic: |
2120 if(s->reordered_input_picture[0]){ | 2177 if(s->reordered_input_picture[0]){ |
2121 s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE ? 3 : 0; | 2178 s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE ? 3 : 0; |
2122 | 2179 |
2123 copy_picture(&s->new_picture, s->reordered_input_picture[0]); | 2180 copy_picture(&s->new_picture, s->reordered_input_picture[0]); |
2124 | 2181 |