comparison parser.c @ 2539:1fefaaee0fdc libavcodec

mpeg-es bitrate parsing
author michael
date Sat, 05 Mar 2005 03:36:32 +0000
parents e25782262d7d
children e7f2b8fadfb0
comparison
equal deleted inserted replaced
2538:34b0996cc10d 2539:1fefaaee0fdc
290 const uint8_t *buf_end; 290 const uint8_t *buf_end;
291 int32_t start_code; 291 int32_t start_code;
292 int frame_rate_index, ext_type, bytes_left; 292 int frame_rate_index, ext_type, bytes_left;
293 int frame_rate_ext_n, frame_rate_ext_d; 293 int frame_rate_ext_n, frame_rate_ext_d;
294 int picture_structure, top_field_first, repeat_first_field, progressive_frame; 294 int picture_structure, top_field_first, repeat_first_field, progressive_frame;
295 int horiz_size_ext, vert_size_ext; 295 int horiz_size_ext, vert_size_ext, bit_rate_ext;
296 296
297 s->repeat_pict = 0; 297 s->repeat_pict = 0;
298 buf_end = buf + buf_size; 298 buf_end = buf + buf_size;
299 while (buf < buf_end) { 299 while (buf < buf_end) {
300 start_code = find_start_code(&buf, buf_end); 300 start_code = find_start_code(&buf, buf_end);
304 if (bytes_left >= 2) { 304 if (bytes_left >= 2) {
305 s->pict_type = (buf[1] >> 3) & 7; 305 s->pict_type = (buf[1] >> 3) & 7;
306 } 306 }
307 break; 307 break;
308 case SEQ_START_CODE: 308 case SEQ_START_CODE:
309 if (bytes_left >= 4) { 309 if (bytes_left >= 7) {
310 pc->width = (buf[0] << 4) | (buf[1] >> 4); 310 pc->width = (buf[0] << 4) | (buf[1] >> 4);
311 pc->height = ((buf[1] & 0x0f) << 8) | buf[2]; 311 pc->height = ((buf[1] & 0x0f) << 8) | buf[2];
312 avcodec_set_dimensions(avctx, pc->width, pc->height); 312 avcodec_set_dimensions(avctx, pc->width, pc->height);
313 frame_rate_index = buf[3] & 0xf; 313 frame_rate_index = buf[3] & 0xf;
314 pc->frame_rate = avctx->frame_rate = frame_rate_tab[frame_rate_index]; 314 pc->frame_rate = avctx->frame_rate = frame_rate_tab[frame_rate_index];
315 avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE; 315 avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE;
316 avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400;
316 avctx->codec_id = CODEC_ID_MPEG1VIDEO; 317 avctx->codec_id = CODEC_ID_MPEG1VIDEO;
317 avctx->sub_id = 1; 318 avctx->sub_id = 1;
318 } 319 }
319 break; 320 break;
320 case EXT_START_CODE: 321 case EXT_START_CODE:
323 switch(ext_type) { 324 switch(ext_type) {
324 case 0x1: /* sequence extension */ 325 case 0x1: /* sequence extension */
325 if (bytes_left >= 6) { 326 if (bytes_left >= 6) {
326 horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7); 327 horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7);
327 vert_size_ext = (buf[2] >> 5) & 3; 328 vert_size_ext = (buf[2] >> 5) & 3;
329 bit_rate_ext = ((buf[2] & 0x1F)<<7) | (buf[3]>>1);
328 frame_rate_ext_n = (buf[5] >> 5) & 3; 330 frame_rate_ext_n = (buf[5] >> 5) & 3;
329 frame_rate_ext_d = (buf[5] & 0x1f); 331 frame_rate_ext_d = (buf[5] & 0x1f);
330 pc->progressive_sequence = buf[1] & (1 << 3); 332 pc->progressive_sequence = buf[1] & (1 << 3);
331 avctx->has_b_frames= buf[5] >> 7; 333 avctx->has_b_frames= buf[5] >> 7;
332 334
333 pc->width |=(horiz_size_ext << 12); 335 pc->width |=(horiz_size_ext << 12);
334 pc->height |=( vert_size_ext << 12); 336 pc->height |=( vert_size_ext << 12);
337 avctx->bit_rate += (bit_rate_ext << 18) * 400;
335 avcodec_set_dimensions(avctx, pc->width, pc->height); 338 avcodec_set_dimensions(avctx, pc->width, pc->height);
336 avctx->frame_rate = pc->frame_rate * (frame_rate_ext_n + 1); 339 avctx->frame_rate = pc->frame_rate * (frame_rate_ext_n + 1);
337 avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d + 1); 340 avctx->frame_rate_base = MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d + 1);
338 avctx->codec_id = CODEC_ID_MPEG2VIDEO; 341 avctx->codec_id = CODEC_ID_MPEG2VIDEO;
339 avctx->sub_id = 2; /* forces MPEG2 */ 342 avctx->sub_id = 2; /* forces MPEG2 */