Mercurial > libavcodec.hg
comparison mpegvideo.c @ 1706:3ba5c493db6f libavcodec
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
author | michael |
---|---|
date | Tue, 30 Dec 2003 02:12:12 +0000 |
parents | 954593137d37 |
children | 027545a2fdbe |
comparison
equal
deleted
inserted
replaced
1705:954593137d37 | 1706:3ba5c493db6f |
---|---|
335 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+1) * sizeof(uint16_t)) | 335 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+1) * sizeof(uint16_t)) |
336 pic->motion_val[i]= pic->motion_val_base[i]+1; | 336 pic->motion_val[i]= pic->motion_val_base[i]+1; |
337 CHECKED_ALLOCZ(pic->ref_index[i] , b8_array_size * sizeof(uint8_t)) | 337 CHECKED_ALLOCZ(pic->ref_index[i] , b8_array_size * sizeof(uint8_t)) |
338 } | 338 } |
339 pic->motion_subsample_log2= 2; | 339 pic->motion_subsample_log2= 2; |
340 }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&(FF_DEBUG_VIS_MV|FF_DEBUG_MV))){ | 340 }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){ |
341 for(i=0; i<2; i++){ | 341 for(i=0; i<2; i++){ |
342 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+1) * sizeof(uint16_t)*2) //FIXME | 342 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+1) * sizeof(uint16_t)*2) //FIXME |
343 pic->motion_val[i]= pic->motion_val_base[i]+1; | 343 pic->motion_val[i]= pic->motion_val_base[i]+1; |
344 } | 344 } |
345 pic->motion_subsample_log2= 3; | 345 pic->motion_subsample_log2= 3; |
562 for(i=0;i<12;i++){ | 562 for(i=0;i<12;i++){ |
563 s->pblocks[i] = (short *)(&s->block[i]); | 563 s->pblocks[i] = (short *)(&s->block[i]); |
564 } | 564 } |
565 | 565 |
566 s->parse_context.state= -1; | 566 s->parse_context.state= -1; |
567 if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ | |
568 s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); | |
569 s->visualization_buffer[1] = av_malloc((s->mb_width*8 + EDGE_WIDTH) * s->mb_height*8 + EDGE_WIDTH); | |
570 s->visualization_buffer[2] = av_malloc((s->mb_width*8 + EDGE_WIDTH) * s->mb_height*8 + EDGE_WIDTH); | |
571 } | |
567 | 572 |
568 s->context_initialized = 1; | 573 s->context_initialized = 1; |
569 return 0; | 574 return 0; |
570 fail: | 575 fail: |
571 MPV_common_end(s); | 576 MPV_common_end(s); |
639 avcodec_default_free_buffers(s->avctx); | 644 avcodec_default_free_buffers(s->avctx); |
640 s->context_initialized = 0; | 645 s->context_initialized = 0; |
641 s->last_picture_ptr= | 646 s->last_picture_ptr= |
642 s->next_picture_ptr= | 647 s->next_picture_ptr= |
643 s->current_picture_ptr= NULL; | 648 s->current_picture_ptr= NULL; |
649 for(i=0; i<3; i++) | |
650 if (s->visualization_buffer[i]) | |
651 av_free(s->visualization_buffer[i]); | |
644 } | 652 } |
645 | 653 |
646 #ifdef CONFIG_ENCODERS | 654 #ifdef CONFIG_ENCODERS |
647 | 655 |
648 /* init video encoder */ | 656 /* init video encoder */ |
1359 } | 1367 } |
1360 | 1368 |
1361 /** | 1369 /** |
1362 * prints debuging info for the given picture. | 1370 * prints debuging info for the given picture. |
1363 */ | 1371 */ |
1364 void ff_print_debug_info(MpegEncContext *s, Picture *pict){ | 1372 void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){ |
1365 | 1373 |
1366 if(!pict || !pict->mb_type) return; | 1374 if(!pict || !pict->mb_type) return; |
1367 | 1375 |
1368 if(s->avctx->debug&(FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)){ | 1376 if(s->avctx->debug&(FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)){ |
1369 int x,y; | 1377 int x,y; |
1370 | 1378 |
1379 av_log(s->avctx,AV_LOG_DEBUG,"New frame, type: "); | |
1380 switch (pict->pict_type) { | |
1381 case FF_I_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"I\n"); break; | |
1382 case FF_P_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"P\n"); break; | |
1383 case FF_B_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"B\n"); break; | |
1384 case FF_S_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"S\n"); break; | |
1385 case FF_SI_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SI\n"); break; | |
1386 case FF_SP_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SP\n"); break; | |
1387 } | |
1371 for(y=0; y<s->mb_height; y++){ | 1388 for(y=0; y<s->mb_height; y++){ |
1372 for(x=0; x<s->mb_width; x++){ | 1389 for(x=0; x<s->mb_width; x++){ |
1373 if(s->avctx->debug&FF_DEBUG_SKIP){ | 1390 if(s->avctx->debug&FF_DEBUG_SKIP){ |
1374 int count= s->mbskip_table[x + y*s->mb_stride]; | 1391 int count= s->mbskip_table[x + y*s->mb_stride]; |
1375 if(count>9) count=9; | 1392 if(count>9) count=9; |
1378 if(s->avctx->debug&FF_DEBUG_QP){ | 1395 if(s->avctx->debug&FF_DEBUG_QP){ |
1379 av_log(s->avctx, AV_LOG_DEBUG, "%2d", pict->qscale_table[x + y*s->mb_stride]); | 1396 av_log(s->avctx, AV_LOG_DEBUG, "%2d", pict->qscale_table[x + y*s->mb_stride]); |
1380 } | 1397 } |
1381 if(s->avctx->debug&FF_DEBUG_MB_TYPE){ | 1398 if(s->avctx->debug&FF_DEBUG_MB_TYPE){ |
1382 int mb_type= pict->mb_type[x + y*s->mb_stride]; | 1399 int mb_type= pict->mb_type[x + y*s->mb_stride]; |
1383 | |
1384 //Type & MV direction | 1400 //Type & MV direction |
1385 if(IS_PCM(mb_type)) | 1401 if(IS_PCM(mb_type)) |
1386 av_log(s->avctx, AV_LOG_DEBUG, "P"); | 1402 av_log(s->avctx, AV_LOG_DEBUG, "P"); |
1387 else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type)) | 1403 else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type)) |
1388 av_log(s->avctx, AV_LOG_DEBUG, "A"); | 1404 av_log(s->avctx, AV_LOG_DEBUG, "A"); |
1431 } | 1447 } |
1432 av_log(s->avctx, AV_LOG_DEBUG, "\n"); | 1448 av_log(s->avctx, AV_LOG_DEBUG, "\n"); |
1433 } | 1449 } |
1434 } | 1450 } |
1435 | 1451 |
1436 if(s->avctx->debug&(FF_DEBUG_VIS_MV|FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)){ | 1452 if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ |
1437 const int shift= 1 + s->quarter_sample; | 1453 const int shift= 1 + s->quarter_sample; |
1438 int mb_y; | 1454 int mb_y; |
1439 uint8_t *ptr= pict->data[0]; | 1455 uint8_t *ptr; |
1440 s->low_delay=0; //needed to see the vectors without trashing the buffers | 1456 s->low_delay=0; //needed to see the vectors without trashing the buffers |
1457 int i; | |
1458 | |
1459 for(i=0; i<3; i++){ | |
1460 memcpy(s->visualization_buffer[i], pict->data[i], (i==0) ? pict->linesize[i]*s->height:pict->linesize[i]*s->height/2); | |
1461 pict->data[i]= s->visualization_buffer[i]; | |
1462 } | |
1463 pict->type= FF_BUFFER_TYPE_COPY; | |
1464 ptr= pict->data[0]; | |
1441 | 1465 |
1442 for(mb_y=0; mb_y<s->mb_height; mb_y++){ | 1466 for(mb_y=0; mb_y<s->mb_height; mb_y++){ |
1443 int mb_x; | 1467 int mb_x; |
1444 for(mb_x=0; mb_x<s->mb_width; mb_x++){ | 1468 for(mb_x=0; mb_x<s->mb_width; mb_x++){ |
1445 const int mb_index= mb_x + mb_y*s->mb_stride; | 1469 const int mb_index= mb_x + mb_y*s->mb_stride; |
1446 if((s->avctx->debug&FF_DEBUG_VIS_MV) && pict->motion_val){ | 1470 if((s->avctx->debug_mv) && pict->motion_val){ |
1447 if(IS_8X8(pict->mb_type[mb_index])){ | 1471 int type; |
1448 int i; | 1472 for(type=0; type<3; type++){ |
1449 for(i=0; i<4; i++){ | 1473 int direction; |
1474 switch (type) { | |
1475 case 0: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_P_FOR)) || (pict->pict_type!=FF_P_TYPE)) | |
1476 continue; | |
1477 direction = 0; | |
1478 break; | |
1479 case 1: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_FOR)) || (pict->pict_type!=FF_B_TYPE)) | |
1480 continue; | |
1481 direction = 0; | |
1482 break; | |
1483 case 2: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_BACK)) || (pict->pict_type!=FF_B_TYPE)) | |
1484 continue; | |
1485 direction = 1; | |
1486 break; | |
1487 } | |
1488 if(IS_8X8(pict->mb_type[mb_index])){ | |
1489 int i; | |
1490 for(i=0; i<4; i++){ | |
1450 int sx= mb_x*16 + 4 + 8*(i&1); | 1491 int sx= mb_x*16 + 4 + 8*(i&1); |
1451 int sy= mb_y*16 + 4 + 8*(i>>1); | 1492 int sy= mb_y*16 + 4 + 8*(i>>1); |
1452 int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2); | 1493 int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2); |
1453 int mx= (pict->motion_val[0][xy][0]>>shift) + sx; | 1494 int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; |
1454 int my= (pict->motion_val[0][xy][1]>>shift) + sy; | 1495 int my= (pict->motion_val[direction][xy][1]>>shift) + sy; |
1455 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); | 1496 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); |
1456 } | 1497 } |
1457 }else if(IS_16X8(pict->mb_type[mb_index])){ | 1498 }else if(IS_16X8(pict->mb_type[mb_index])){ |
1458 int i; | 1499 int i; |
1459 for(i=0; i<2; i++){ | 1500 for(i=0; i<2; i++){ |
1460 int sx=mb_x*16 + 8; | 1501 int sx=mb_x*16 + 8; |
1461 int sy=mb_y*16 + 4 + 8*i; | 1502 int sy=mb_y*16 + 4 + 8*i; |
1462 int xy=1 + mb_x*2 + (mb_y*2 + 1 + i)*(s->mb_width*2 + 2); | 1503 int xy=1 + mb_x*2 + (mb_y*2 + 1 + i)*(s->mb_width*2 + 2); |
1463 int mx=(pict->motion_val[0][xy][0]>>shift) + sx; | 1504 int mx=(pict->motion_val[direction][xy][0]>>shift) + sx; |
1464 int my=(pict->motion_val[0][xy][1]>>shift) + sy; | 1505 int my=(pict->motion_val[direction][xy][1]>>shift) + sy; |
1465 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); | 1506 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); |
1507 } | |
1508 }else{ | |
1509 int sx= mb_x*16 + 8; | |
1510 int sy= mb_y*16 + 8; | |
1511 int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2); | |
1512 int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; | |
1513 int my= (pict->motion_val[direction][xy][1]>>shift) + sy; | |
1514 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); | |
1466 } | 1515 } |
1467 }else{ | 1516 } |
1468 int sx= mb_x*16 + 8; | |
1469 int sy= mb_y*16 + 8; | |
1470 int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2); | |
1471 int mx= (pict->motion_val[0][xy][0]>>shift) + sx; | |
1472 int my= (pict->motion_val[0][xy][1]>>shift) + sy; | |
1473 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); | |
1474 } | |
1475 } | 1517 } |
1476 if((s->avctx->debug&FF_DEBUG_VIS_QP) && pict->motion_val){ | 1518 if((s->avctx->debug&FF_DEBUG_VIS_QP) && pict->motion_val){ |
1477 uint64_t c= (pict->qscale_table[mb_index]*128/31) * 0x0101010101010101ULL; | 1519 uint64_t c= (pict->qscale_table[mb_index]*128/31) * 0x0101010101010101ULL; |
1478 int y; | 1520 int y; |
1479 for(y=0; y<8; y++){ | 1521 for(y=0; y<8; y++){ |