comparison h263.c @ 1872:c13d3543c73a libavcodec

h263+ custom pcf support
author michael
date Wed, 10 Mar 2004 22:11:49 +0000
parents 92e94c550def
children c26242faa246
comparison
equal deleted inserted replaced
1871:9457292b0b65 1872:c13d3543c73a
195 } 195 }
196 } 196 }
197 197
198 void h263_encode_picture_header(MpegEncContext * s, int picture_number) 198 void h263_encode_picture_header(MpegEncContext * s, int picture_number)
199 { 199 {
200 int format; 200 int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref;
201 int best_clock_code=1;
202 int best_divisor=60;
203 int best_error= INT_MAX;
204
205 if(s->h263_plus){
206 for(i=0; i<2; i++){
207 int div, error;
208 div= (s->avctx->frame_rate_base*1800000LL + 500LL*s->avctx->frame_rate) / ((1000LL+i)*s->avctx->frame_rate);
209 div= clip(1, div, 127);
210 error= ABS(s->avctx->frame_rate_base*1800000LL - (1000LL+i)*s->avctx->frame_rate*div);
211 if(error < best_error){
212 best_error= error;
213 best_divisor= div;
214 best_clock_code= i;
215 }
216 }
217 }
218 s->custom_pcf= best_clock_code!=1 || best_divisor!=60;
219 coded_frame_rate= 1800000;
220 coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
201 221
202 align_put_bits(&s->pb); 222 align_put_bits(&s->pb);
203 223
204 /* Update the pointer to last GOB */ 224 /* Update the pointer to last GOB */
205 s->ptr_lastgob = pbBufPtr(&s->pb); 225 s->ptr_lastgob = pbBufPtr(&s->pb);
206 put_bits(&s->pb, 22, 0x20); /* PSC */ 226 put_bits(&s->pb, 22, 0x20); /* PSC */
207 put_bits(&s->pb, 8, ((s->picture_number * 30000LL * s->avctx->frame_rate_base) / 227 temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->frame_rate_base /
208 (1001LL *s->avctx->frame_rate)) & 0xff); /* TemporalReference */ 228 (coded_frame_rate_base * (int64_t)s->avctx->frame_rate);
229 put_bits(&s->pb, 8, temp_ref & 0xff); /* TemporalReference */
209 230
210 put_bits(&s->pb, 1, 1); /* marker */ 231 put_bits(&s->pb, 1, 1); /* marker */
211 put_bits(&s->pb, 1, 0); /* h263 id */ 232 put_bits(&s->pb, 1, 0); /* h263 id */
212 put_bits(&s->pb, 1, 0); /* split screen off */ 233 put_bits(&s->pb, 1, 0); /* split screen off */
213 put_bits(&s->pb, 1, 0); /* camera off */ 234 put_bits(&s->pb, 1, 0); /* camera off */
226 put_bits(&s->pb, 1, s->obmc); /* advanced prediction mode */ 247 put_bits(&s->pb, 1, s->obmc); /* advanced prediction mode */
227 put_bits(&s->pb, 1, 0); /* not PB frame */ 248 put_bits(&s->pb, 1, 0); /* not PB frame */
228 put_bits(&s->pb, 5, s->qscale); 249 put_bits(&s->pb, 5, s->qscale);
229 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ 250 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
230 } else { 251 } else {
252 int ufep=1;
231 /* H.263v2 */ 253 /* H.263v2 */
232 /* H.263 Plus PTYPE */ 254 /* H.263 Plus PTYPE */
255
233 put_bits(&s->pb, 3, 7); 256 put_bits(&s->pb, 3, 7);
234 put_bits(&s->pb,3,1); /* Update Full Extended PTYPE */ 257 put_bits(&s->pb,3,ufep); /* Update Full Extended PTYPE */
235 if (format == 7) 258 if (format == 7)
236 put_bits(&s->pb,3,6); /* Custom Source Format */ 259 put_bits(&s->pb,3,6); /* Custom Source Format */
237 else 260 else
238 put_bits(&s->pb, 3, format); 261 put_bits(&s->pb, 3, format);
239 262
240 put_bits(&s->pb,1,0); /* Custom PCF: off */ 263 put_bits(&s->pb,1, s->custom_pcf);
241 put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */ 264 put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */
242 put_bits(&s->pb,1,0); /* SAC: off */ 265 put_bits(&s->pb,1,0); /* SAC: off */
243 put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */ 266 put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */
244 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */ 267 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */
245 put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */ 268 put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */
272 put_bits(&s->pb,9,(s->height >> 2)); 295 put_bits(&s->pb,9,(s->height >> 2));
273 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){ 296 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){
274 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num); 297 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num);
275 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den); 298 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den);
276 } 299 }
300 }
301 if(s->custom_pcf){
302 if(ufep){
303 put_bits(&s->pb, 1, best_clock_code);
304 put_bits(&s->pb, 7, best_divisor);
305 }
306 put_bits(&s->pb, 2, (temp_ref>>8)&3);
277 } 307 }
278 308
279 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ 309 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
280 if (s->umvplus) 310 if (s->umvplus)
281 // put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ 311 // put_bits(&s->pb,1,1); /* Limited according tables of Annex D */
4959 /* ufep other than 0 and 1 are reserved */ 4989 /* ufep other than 0 and 1 are reserved */
4960 if (ufep == 1) { 4990 if (ufep == 1) {
4961 /* OPPTYPE */ 4991 /* OPPTYPE */
4962 format = get_bits(&s->gb, 3); 4992 format = get_bits(&s->gb, 3);
4963 dprintf("ufep=1, format: %d\n", format); 4993 dprintf("ufep=1, format: %d\n", format);
4964 if (get_bits1(&s->gb) != 0) { 4994 s->custom_pcf= get_bits1(&s->gb);
4965 av_log(s->avctx, AV_LOG_ERROR, "Custom PCF not supported\n");
4966 }
4967 s->umvplus = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ 4995 s->umvplus = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */
4968 if (get_bits1(&s->gb) != 0) { 4996 if (get_bits1(&s->gb) != 0) {
4969 av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); 4997 av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
4970 } 4998 }
4971 s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ 4999 s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
5038 height = h263_format[format][1]; 5066 height = h263_format[format][1];
5039 s->avctx->sample_aspect_ratio= (AVRational){12,11}; 5067 s->avctx->sample_aspect_ratio= (AVRational){12,11};
5040 } 5068 }
5041 if ((width == 0) || (height == 0)) 5069 if ((width == 0) || (height == 0))
5042 return -1; 5070 return -1;
5043 s->avctx->frame_rate = 30000;
5044 s->avctx->frame_rate_base= 1001;
5045 s->width = width; 5071 s->width = width;
5046 s->height = height; 5072 s->height = height;
5073
5074 if(s->custom_pcf){
5075 int gcd;
5076 s->avctx->frame_rate= 1800000;
5077 s->avctx->frame_rate_base= 1000 + get_bits1(&s->gb);
5078 s->avctx->frame_rate_base*= get_bits(&s->gb, 7);
5079 if(s->avctx->frame_rate_base == 0){
5080 av_log(s, AV_LOG_ERROR, "zero framerate\n");
5081 return -1;
5082 }
5083 gcd= ff_gcd(s->avctx->frame_rate, s->avctx->frame_rate_base);
5084 s->avctx->frame_rate /= gcd;
5085 s->avctx->frame_rate_base /= gcd;
5086 // av_log(s->avctx, AV_LOG_DEBUG, "%d/%d\n", s->avctx->frame_rate, s->avctx->frame_rate_base);
5087 }else{
5088 s->avctx->frame_rate = 30000;
5089 s->avctx->frame_rate_base= 1001;
5090 }
5091 }
5092
5093 if(s->custom_pcf){
5094 skip_bits(&s->gb, 2); //extended Temporal reference
5095 }
5096
5097 if (ufep) {
5047 if (s->umvplus) { 5098 if (s->umvplus) {
5048 if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ 5099 if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
5049 skip_bits1(&s->gb); 5100 skip_bits1(&s->gb);
5050 } 5101 }
5051 if(s->h263_slice_structured){ 5102 if(s->h263_slice_structured){
5088 s->y_dc_scale_table= 5139 s->y_dc_scale_table=
5089 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; 5140 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
5090 } 5141 }
5091 5142
5092 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ 5143 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
5093 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s\n", 5144 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n",
5094 s->qscale, av_get_pict_type_char(s->pict_type), 5145 s->qscale, av_get_pict_type_char(s->pict_type),
5095 s->gb.size_in_bits, 1-s->no_rounding, 5146 s->gb.size_in_bits, 1-s->no_rounding,
5096 s->obmc ? " AP" : "", 5147 s->obmc ? " AP" : "",
5097 s->umvplus ? " UMV" : "", 5148 s->umvplus ? " UMV" : "",
5098 s->h263_long_vectors ? " LONG" : "", 5149 s->h263_long_vectors ? " LONG" : "",
5099 s->h263_plus ? " +" : "", 5150 s->h263_plus ? " +" : "",
5100 s->h263_aic ? " AIC" : "", 5151 s->h263_aic ? " AIC" : "",
5101 s->alt_inter_vlc ? " AIV" : "", 5152 s->alt_inter_vlc ? " AIV" : "",
5102 s->modified_quant ? " MQ" : "", 5153 s->modified_quant ? " MQ" : "",
5103 s->loop_filter ? " LOOP" : "", 5154 s->loop_filter ? " LOOP" : "",
5104 s->h263_slice_structured ? " SS" : "" 5155 s->h263_slice_structured ? " SS" : "",
5156 s->avctx->frame_rate, s->avctx->frame_rate_base
5105 ); 5157 );
5106 } 5158 }
5107 #if 1 5159 #if 1
5108 if (s->pict_type == I_TYPE && s->avctx->codec_tag == ff_get_fourcc("ZYGO")){ 5160 if (s->pict_type == I_TYPE && s->avctx->codec_tag == ff_get_fourcc("ZYGO")){
5109 int i,j; 5161 int i,j;