Mercurial > libavcodec.hg
comparison mpegvideo.c @ 915:75ee49a4a516 libavcodec
fixing 2pass assert failure
better dynamic b frame selection, still not very good though allthough it works fine without 2pass now
author | michaelni |
---|---|
date | Fri, 06 Dec 2002 13:30:13 +0000 |
parents | 4a1e6bb1f41c |
children | 3814e9115672 |
comparison
equal
deleted
inserted
replaced
914:22cec68e6f01 | 915:75ee49a4a516 |
---|---|
778 | 778 |
779 s->mb_skiped = 0; | 779 s->mb_skiped = 0; |
780 | 780 |
781 /* mark&release old frames */ | 781 /* mark&release old frames */ |
782 if (s->pict_type != B_TYPE && s->last_picture.data[0]) { | 782 if (s->pict_type != B_TYPE && s->last_picture.data[0]) { |
783 Picture *pic= NULL; | |
784 for(i=0; i<MAX_PICTURE_COUNT; i++){ | 783 for(i=0; i<MAX_PICTURE_COUNT; i++){ |
785 if(s->picture[i].data[0] == s->last_picture.data[0]){ | 784 if(s->picture[i].data[0] == s->last_picture.data[0]){ |
786 // s->picture[i].reference=0; | 785 // s->picture[i].reference=0; |
787 avctx->release_buffer(avctx, (AVVideoFrame*)&s->picture[i]); | 786 avctx->release_buffer(avctx, (AVVideoFrame*)&s->picture[i]); |
788 break; | 787 break; |
894 /* release non refernce frames */ | 893 /* release non refernce frames */ |
895 for(i=0; i<MAX_PICTURE_COUNT; i++){ | 894 for(i=0; i<MAX_PICTURE_COUNT; i++){ |
896 if(s->picture[i].data[0] && !s->picture[i].reference) | 895 if(s->picture[i].data[0] && !s->picture[i].reference) |
897 s->avctx->release_buffer(s->avctx, (AVVideoFrame*)&s->picture[i]); | 896 s->avctx->release_buffer(s->avctx, (AVVideoFrame*)&s->picture[i]); |
898 } | 897 } |
898 } | |
899 | |
900 static int get_sae(uint8_t *src, int ref, int stride){ | |
901 int x,y; | |
902 int acc=0; | |
903 | |
904 for(y=0; y<16; y++){ | |
905 for(x=0; x<16; x++){ | |
906 acc+= ABS(src[x+y*stride] - ref); | |
907 } | |
908 } | |
909 | |
910 return acc; | |
911 } | |
912 | |
913 static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){ | |
914 int x, y, w, h; | |
915 int acc=0; | |
916 | |
917 w= s->width &~15; | |
918 h= s->height&~15; | |
919 | |
920 for(y=0; y<h; y+=16){ | |
921 for(x=0; x<w; x+=16){ | |
922 int offset= x + y*stride; | |
923 int sad = s->dsp.pix_abs16x16(src + offset, ref + offset, stride); | |
924 int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8; | |
925 int sae = get_sae(src + offset, mean, stride); | |
926 | |
927 acc+= sae + 500 < sad; | |
928 } | |
929 } | |
930 return acc; | |
899 } | 931 } |
900 | 932 |
901 static int load_input_picture(MpegEncContext *s, AVVideoFrame *pic_arg){ | 933 static int load_input_picture(MpegEncContext *s, AVVideoFrame *pic_arg){ |
902 AVVideoFrame *pic; | 934 AVVideoFrame *pic; |
903 int i,r; | 935 int i,r; |
989 s->reordered_input_picture[i-1]= s->reordered_input_picture[i]; | 1021 s->reordered_input_picture[i-1]= s->reordered_input_picture[i]; |
990 s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL; | 1022 s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL; |
991 | 1023 |
992 /* set next picture types & ordering */ | 1024 /* set next picture types & ordering */ |
993 if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){ | 1025 if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){ |
994 if(s->input_picture[0]->pict_type){ | 1026 if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture.data[0]==NULL || s->intra_only){ |
995 /* user selected pict_type */ | 1027 s->reordered_input_picture[0]= s->input_picture[0]; |
996 if(s->input_picture[0]->pict_type == I_TYPE){ | 1028 s->reordered_input_picture[0]->pict_type= I_TYPE; |
997 s->reordered_input_picture[0]= s->input_picture[0]; | 1029 s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; |
998 s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; | 1030 }else{ |
999 }else{ | 1031 int b_frames; |
1000 int b_frames; | 1032 |
1001 | 1033 if(s->flags&CODEC_FLAG_PASS2){ |
1034 for(i=0; i<s->max_b_frames+1; i++){ | |
1035 int pict_num= s->input_picture[0]->display_picture_number + i; | |
1036 int pict_type= s->rc_context.entry[pict_num].new_pict_type; | |
1037 s->input_picture[i]->pict_type= pict_type; | |
1038 | |
1039 if(i + 1 >= s->rc_context.num_entries) break; | |
1040 } | |
1041 } | |
1042 | |
1043 if(s->input_picture[0]->pict_type){ | |
1044 /* user selected pict_type */ | |
1002 for(b_frames=0; b_frames<s->max_b_frames+1; b_frames++){ | 1045 for(b_frames=0; b_frames<s->max_b_frames+1; b_frames++){ |
1003 if(s->input_picture[b_frames]->pict_type!=B_TYPE) break; | 1046 if(s->input_picture[b_frames]->pict_type!=B_TYPE) break; |
1004 } | 1047 } |
1005 | 1048 |
1006 if(b_frames > s->max_b_frames){ | 1049 if(b_frames > s->max_b_frames){ |
1007 fprintf(stderr, "warning, too many bframes in a row\n"); | 1050 fprintf(stderr, "warning, too many bframes in a row\n"); |
1008 b_frames = s->max_b_frames; | 1051 b_frames = s->max_b_frames; |
1009 s->input_picture[b_frames]->pict_type= I_TYPE; | 1052 } |
1010 } | 1053 }else if(s->b_frame_strategy==0){ |
1054 b_frames= s->max_b_frames; | |
1055 }else if(s->b_frame_strategy==1){ | |
1056 for(i=1; i<s->max_b_frames+1; i++){ | |
1057 if(s->input_picture[i]->b_frame_score==0){ | |
1058 s->input_picture[i]->b_frame_score= | |
1059 get_intra_count(s, s->input_picture[i ]->data[0] + 16, | |
1060 s->input_picture[i-1]->data[0] + 16, s->linesize) + 1; | |
1061 } | |
1062 } | |
1063 for(i=0; i<s->max_b_frames; i++){ | |
1064 if(s->input_picture[i]->b_frame_score - 1 > s->mb_num/40) break; | |
1065 } | |
1066 | |
1067 b_frames= FFMAX(0, i-1); | |
1011 | 1068 |
1012 s->reordered_input_picture[0]= s->input_picture[b_frames]; | 1069 /* reset scores */ |
1013 s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; | 1070 for(i=0; i<b_frames+1; i++){ |
1014 for(i=0; i<b_frames; i++){ | 1071 s->input_picture[i]->b_frame_score=0; |
1015 coded_pic_num++; | 1072 } |
1016 s->reordered_input_picture[i+1]= s->input_picture[i]; | 1073 }else{ |
1017 s->reordered_input_picture[i+1]->coded_picture_number= coded_pic_num; | 1074 fprintf(stderr, "illegal b frame strategy\n"); |
1018 } | 1075 b_frames=0; |
1019 } | 1076 } |
1020 }else{ | 1077 |
1021 if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture.data[0]==NULL || s->intra_only){ | 1078 emms_c(); |
1022 s->reordered_input_picture[0]= s->input_picture[0]; | 1079 //static int b_count=0; |
1080 //b_count+= b_frames; | |
1081 //printf("b_frames: %d\n", b_count); | |
1082 | |
1083 s->reordered_input_picture[0]= s->input_picture[b_frames]; | |
1084 if( s->picture_in_gop_number + b_frames >= s->gop_size | |
1085 || s->reordered_input_picture[0]->pict_type== I_TYPE) | |
1023 s->reordered_input_picture[0]->pict_type= I_TYPE; | 1086 s->reordered_input_picture[0]->pict_type= I_TYPE; |
1024 s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; | 1087 else |
1025 }else{ | 1088 s->reordered_input_picture[0]->pict_type= P_TYPE; |
1026 s->reordered_input_picture[0]= s->input_picture[s->max_b_frames]; | 1089 s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; |
1027 if(s->picture_in_gop_number + s->max_b_frames >= s->gop_size) | 1090 for(i=0; i<b_frames; i++){ |
1028 s->reordered_input_picture[0]->pict_type= I_TYPE; | 1091 coded_pic_num++; |
1029 else | 1092 s->reordered_input_picture[i+1]= s->input_picture[i]; |
1030 s->reordered_input_picture[0]->pict_type= P_TYPE; | 1093 s->reordered_input_picture[i+1]->pict_type= B_TYPE; |
1031 s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; | 1094 s->reordered_input_picture[i+1]->coded_picture_number= coded_pic_num; |
1032 for(i=0; i<s->max_b_frames; i++){ | |
1033 coded_pic_num++; | |
1034 s->reordered_input_picture[i+1]= s->input_picture[i]; | |
1035 s->reordered_input_picture[i+1]->pict_type= B_TYPE; | |
1036 s->reordered_input_picture[i+1]->coded_picture_number= coded_pic_num; | |
1037 } | |
1038 } | 1095 } |
1039 } | 1096 } |
1040 } | 1097 } |
1041 | 1098 |
1042 if(s->reordered_input_picture[0]){ | 1099 if(s->reordered_input_picture[0]){ |