Mercurial > libavcodec.hg
comparison xvid_rc.c @ 3204:5fc631919a98 libavcodec
various fixes for xvid_rc
author | michael |
---|---|
date | Sun, 19 Mar 2006 11:49:37 +0000 |
parents | 89348aaf566e |
children | 18af2f7788c6 |
comparison
equal
deleted
inserted
replaced
3203:a78cc2e4b90e | 3204:5fc631919a98 |
---|---|
42 if(fd < 0){ | 42 if(fd < 0){ |
43 strcpy(tmp_name, "./xvidrc.XXXXXX"); | 43 strcpy(tmp_name, "./xvidrc.XXXXXX"); |
44 fd = mkstemp(tmp_name); | 44 fd = mkstemp(tmp_name); |
45 } | 45 } |
46 | 46 |
47 for(i=0; i<s->rc_context.num_entries - s->max_b_frames; i++){ | 47 for(i=0; i<s->rc_context.num_entries; i++){ |
48 static const char *frame_types = " ipbs"; | 48 static const char *frame_types = " ipbs"; |
49 char tmp[256]; | 49 char tmp[256]; |
50 RateControlEntry *rce; | 50 RateControlEntry *rce; |
51 | 51 |
52 rce= &s->rc_context.entry[i]; | 52 rce= &s->rc_context.entry[i]; |
53 | 53 |
54 snprintf(tmp, sizeof(tmp), "%c %d %d %d %d %d %d\n", | 54 snprintf(tmp, sizeof(tmp), "%c %d %d %d %d %d %d\n", |
55 frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count, | 55 frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count, |
56 rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->mv_bits + rce->misc_bits+7)/8, (rce->header_bits+7)/8); | 56 rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8); |
57 | 57 |
58 //av_log(NULL, AV_LOG_ERROR, "%s\n", tmp); | |
58 write(fd, tmp, strlen(tmp)); | 59 write(fd, tmp, strlen(tmp)); |
59 } | 60 } |
60 | 61 |
61 close(fd); | 62 close(fd); |
62 | 63 |
72 xvid_plg_create.version= XVID_MAKE_VERSION(1,1,0); | 73 xvid_plg_create.version= XVID_MAKE_VERSION(1,1,0); |
73 xvid_plg_create.fbase= s->avctx->time_base.den; | 74 xvid_plg_create.fbase= s->avctx->time_base.den; |
74 xvid_plg_create.fincr= s->avctx->time_base.num; | 75 xvid_plg_create.fincr= s->avctx->time_base.num; |
75 xvid_plg_create.param= &xvid_2pass2; | 76 xvid_plg_create.param= &xvid_2pass2; |
76 | 77 |
77 return xvid_plugin_2pass2(NULL, XVID_PLG_CREATE, &xvid_plg_create, &s->rc_context.non_lavc_opaque); | 78 if(xvid_plugin_2pass2(NULL, XVID_PLG_CREATE, &xvid_plg_create, &s->rc_context.non_lavc_opaque)<0){ |
79 av_log(NULL, AV_LOG_ERROR, "xvid_plugin_2pass2 failed\n"); | |
80 return -1; | |
81 } | |
82 return 0; | |
78 } | 83 } |
79 | 84 |
80 float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){ | 85 float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){ |
81 xvid_plg_data_t xvid_plg_data; | 86 xvid_plg_data_t xvid_plg_data; |
82 | 87 |
92 xvid_plg_data.min_quant[1]= s->avctx->qmin; | 97 xvid_plg_data.min_quant[1]= s->avctx->qmin; |
93 xvid_plg_data.min_quant[2]= s->avctx->qmin; //FIXME i/b factor & offset | 98 xvid_plg_data.min_quant[2]= s->avctx->qmin; //FIXME i/b factor & offset |
94 xvid_plg_data.max_quant[0]= s->avctx->qmax; | 99 xvid_plg_data.max_quant[0]= s->avctx->qmax; |
95 xvid_plg_data.max_quant[1]= s->avctx->qmax; | 100 xvid_plg_data.max_quant[1]= s->avctx->qmax; |
96 xvid_plg_data.max_quant[2]= s->avctx->qmax; //FIXME i/b factor & offset | 101 xvid_plg_data.max_quant[2]= s->avctx->qmax; //FIXME i/b factor & offset |
97 xvid_plg_data.bquant_offset = 100 * s->avctx->b_quant_offset; | 102 xvid_plg_data.bquant_offset = 0; // 100 * s->avctx->b_quant_offset; |
98 xvid_plg_data.bquant_ratio = 100 * s->avctx->b_quant_factor; | 103 xvid_plg_data.bquant_ratio = 100; // * s->avctx->b_quant_factor; |
99 | 104 |
100 #if 0 | 105 #if 0 |
101 xvid_plg_data.stats.hlength= X | 106 xvid_plg_data.stats.hlength= X |
102 #endif | 107 #endif |
103 | 108 |
104 if(!s->rc_context.dry_run_qscale){ | 109 if(!s->rc_context.dry_run_qscale){ |
105 if(s->picture_number){ | 110 if(s->picture_number){ |
106 xvid_plg_data.length= | 111 xvid_plg_data.length= |
107 xvid_plg_data.stats.length= (s->frame_bits + 7)/8; | 112 xvid_plg_data.stats.length= (s->frame_bits + 7)/8; |
108 xvid_plg_data.frame_num= s->picture_number - 1; | 113 xvid_plg_data.frame_num= s->rc_context.last_picture_number; |
109 xvid_plg_data.quant= s->qscale; | 114 xvid_plg_data.quant= s->qscale; |
110 | 115 |
111 xvid_plg_data.type= s->last_pict_type; | 116 xvid_plg_data.type= s->last_pict_type; |
112 if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_AFTER, &xvid_plg_data, NULL)){ | 117 if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_AFTER, &xvid_plg_data, NULL)){ |
113 av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_AFTER, ...) FAILED\n"); | 118 av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_AFTER, ...) FAILED\n"); |
114 return -1; | 119 return -1; |
115 } | 120 } |
116 } | 121 } |
122 s->rc_context.last_picture_number= | |
117 xvid_plg_data.frame_num= s->picture_number; | 123 xvid_plg_data.frame_num= s->picture_number; |
118 xvid_plg_data.quant= 0; | 124 xvid_plg_data.quant= 0; |
119 if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_BEFORE, &xvid_plg_data, NULL)){ | 125 if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_BEFORE, &xvid_plg_data, NULL)){ |
120 av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_BEFORE, ...) FAILED\n"); | 126 av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_BEFORE, ...) FAILED\n"); |
121 return -1; | 127 return -1; |
124 } | 130 } |
125 xvid_plg_data.quant= s->rc_context.dry_run_qscale; | 131 xvid_plg_data.quant= s->rc_context.dry_run_qscale; |
126 if(!dry_run) | 132 if(!dry_run) |
127 s->rc_context.dry_run_qscale= 0; | 133 s->rc_context.dry_run_qscale= 0; |
128 | 134 |
129 return xvid_plg_data.quant * FF_QP2LAMBDA; | 135 if(s->pict_type == B_TYPE) //FIXME this is not exactly identical to xvid |
136 return xvid_plg_data.quant * FF_QP2LAMBDA * s->avctx->b_quant_factor + s->avctx->b_quant_offset; | |
137 else | |
138 return xvid_plg_data.quant * FF_QP2LAMBDA; | |
130 } | 139 } |
131 | 140 |
132 void ff_xvid_rate_control_uninit(MpegEncContext *s){ | 141 void ff_xvid_rate_control_uninit(MpegEncContext *s){ |
133 xvid_plg_destroy_t xvid_plg_destroy; | 142 xvid_plg_destroy_t xvid_plg_destroy; |
134 | 143 |