Mercurial > libavcodec.hg
changeset 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 |
files | avcodec.h h263dec.c h264.c mpeg12.c mpegvideo.c mpegvideo.h rv10.c |
diffstat | 7 files changed, 88 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/avcodec.h Mon Dec 29 22:25:08 2003 +0000 +++ b/avcodec.h Tue Dec 30 02:12:12 2003 +0000 @@ -1133,7 +1133,7 @@ #define FF_DEBUG_MB_TYPE 8 #define FF_DEBUG_QP 16 #define FF_DEBUG_MV 32 -#define FF_DEBUG_VIS_MV 0x00000040 +//#define FF_DEBUG_VIS_MV 0x00000040 #define FF_DEBUG_SKIP 0x00000080 #define FF_DEBUG_STARTCODE 0x00000100 #define FF_DEBUG_PTS 0x00000200 @@ -1144,6 +1144,16 @@ #define FF_DEBUG_VIS_MB_TYPE 0x00004000 /** + * debug. + * - encoding: set by user. + * - decoding: set by user. + */ + int debug_mv; +#define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames +#define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames +#define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames + + /** * error. * - encoding: set by lavc if flags&CODEC_FLAG_PSNR * - decoding: unused
--- a/h263dec.c Mon Dec 29 22:25:08 2003 +0000 +++ b/h263dec.c Tue Dec 30 02:12:12 2003 +0000 @@ -703,10 +703,10 @@ assert(s->current_picture.pict_type == s->pict_type); if(s->pict_type==B_TYPE || s->low_delay){ *pict= *(AVFrame*)&s->current_picture; - ff_print_debug_info(s, s->current_picture_ptr); + ff_print_debug_info(s, pict); } else { *pict= *(AVFrame*)&s->last_picture; - ff_print_debug_info(s, s->last_picture_ptr); + ff_print_debug_info(s, pict); } /* Return the Picture timestamp as the frame number */
--- a/h264.c Mon Dec 29 22:25:08 2003 +0000 +++ b/h264.c Tue Dec 30 02:12:12 2003 +0000 @@ -4172,7 +4172,7 @@ } *pict= *(AVFrame*)&s->current_picture; //FIXME - ff_print_debug_info(s, s->current_picture_ptr); + ff_print_debug_info(s, pict); assert(pict->data[0]); //printf("out %d\n", (int)pict->data[0]); #if 0 //?
--- a/mpeg12.c Mon Dec 29 22:25:08 2003 +0000 +++ b/mpeg12.c Tue Dec 30 02:12:12 2003 +0000 @@ -2305,14 +2305,14 @@ if (s->pict_type == B_TYPE || s->low_delay) { *pict= *(AVFrame*)s->current_picture_ptr; - ff_print_debug_info(s, s->current_picture_ptr); + ff_print_debug_info(s, pict); } else { s->picture_number++; /* latency of 1 frame for I and P frames */ /* XXX: use another variable than picture_number */ if (s->last_picture_ptr != NULL) { *pict= *(AVFrame*)s->last_picture_ptr; - ff_print_debug_info(s, s->last_picture_ptr); + ff_print_debug_info(s, pict); } }
--- a/mpegvideo.c Mon Dec 29 22:25:08 2003 +0000 +++ b/mpegvideo.c Tue Dec 30 02:12:12 2003 +0000 @@ -337,7 +337,7 @@ CHECKED_ALLOCZ(pic->ref_index[i] , b8_array_size * sizeof(uint8_t)) } pic->motion_subsample_log2= 2; - }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&(FF_DEBUG_VIS_MV|FF_DEBUG_MV))){ + }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){ for(i=0; i<2; i++){ CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+1) * sizeof(uint16_t)*2) //FIXME pic->motion_val[i]= pic->motion_val_base[i]+1; @@ -564,6 +564,11 @@ } s->parse_context.state= -1; + if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ + s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); + s->visualization_buffer[1] = av_malloc((s->mb_width*8 + EDGE_WIDTH) * s->mb_height*8 + EDGE_WIDTH); + s->visualization_buffer[2] = av_malloc((s->mb_width*8 + EDGE_WIDTH) * s->mb_height*8 + EDGE_WIDTH); + } s->context_initialized = 1; return 0; @@ -641,6 +646,9 @@ s->last_picture_ptr= s->next_picture_ptr= s->current_picture_ptr= NULL; + for(i=0; i<3; i++) + if (s->visualization_buffer[i]) + av_free(s->visualization_buffer[i]); } #ifdef CONFIG_ENCODERS @@ -1361,13 +1369,22 @@ /** * prints debuging info for the given picture. */ -void ff_print_debug_info(MpegEncContext *s, Picture *pict){ +void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){ if(!pict || !pict->mb_type) return; if(s->avctx->debug&(FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)){ int x,y; - + + av_log(s->avctx,AV_LOG_DEBUG,"New frame, type: "); + switch (pict->pict_type) { + case FF_I_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"I\n"); break; + case FF_P_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"P\n"); break; + case FF_B_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"B\n"); break; + case FF_S_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"S\n"); break; + case FF_SI_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SI\n"); break; + case FF_SP_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SP\n"); break; + } for(y=0; y<s->mb_height; y++){ for(x=0; x<s->mb_width; x++){ if(s->avctx->debug&FF_DEBUG_SKIP){ @@ -1380,7 +1397,6 @@ } if(s->avctx->debug&FF_DEBUG_MB_TYPE){ int mb_type= pict->mb_type[x + y*s->mb_stride]; - //Type & MV direction if(IS_PCM(mb_type)) av_log(s->avctx, AV_LOG_DEBUG, "P"); @@ -1433,45 +1449,71 @@ } } - if(s->avctx->debug&(FF_DEBUG_VIS_MV|FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)){ + if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ const int shift= 1 + s->quarter_sample; int mb_y; - uint8_t *ptr= pict->data[0]; + uint8_t *ptr; s->low_delay=0; //needed to see the vectors without trashing the buffers + int i; + + for(i=0; i<3; i++){ + memcpy(s->visualization_buffer[i], pict->data[i], (i==0) ? pict->linesize[i]*s->height:pict->linesize[i]*s->height/2); + pict->data[i]= s->visualization_buffer[i]; + } + pict->type= FF_BUFFER_TYPE_COPY; + ptr= pict->data[0]; for(mb_y=0; mb_y<s->mb_height; mb_y++){ int mb_x; for(mb_x=0; mb_x<s->mb_width; mb_x++){ const int mb_index= mb_x + mb_y*s->mb_stride; - if((s->avctx->debug&FF_DEBUG_VIS_MV) && pict->motion_val){ - if(IS_8X8(pict->mb_type[mb_index])){ - int i; - for(i=0; i<4; i++){ + if((s->avctx->debug_mv) && pict->motion_val){ + int type; + for(type=0; type<3; type++){ + int direction; + switch (type) { + case 0: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_P_FOR)) || (pict->pict_type!=FF_P_TYPE)) + continue; + direction = 0; + break; + case 1: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_FOR)) || (pict->pict_type!=FF_B_TYPE)) + continue; + direction = 0; + break; + case 2: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_BACK)) || (pict->pict_type!=FF_B_TYPE)) + continue; + direction = 1; + break; + } + if(IS_8X8(pict->mb_type[mb_index])){ + int i; + for(i=0; i<4; i++){ int sx= mb_x*16 + 4 + 8*(i&1); int sy= mb_y*16 + 4 + 8*(i>>1); int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2); - int mx= (pict->motion_val[0][xy][0]>>shift) + sx; - int my= (pict->motion_val[0][xy][1]>>shift) + sy; + int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; + int my= (pict->motion_val[direction][xy][1]>>shift) + sy; draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); - } - }else if(IS_16X8(pict->mb_type[mb_index])){ - int i; - for(i=0; i<2; i++){ + } + }else if(IS_16X8(pict->mb_type[mb_index])){ + int i; + for(i=0; i<2; i++){ int sx=mb_x*16 + 8; int sy=mb_y*16 + 4 + 8*i; int xy=1 + mb_x*2 + (mb_y*2 + 1 + i)*(s->mb_width*2 + 2); - int mx=(pict->motion_val[0][xy][0]>>shift) + sx; - int my=(pict->motion_val[0][xy][1]>>shift) + sy; + int mx=(pict->motion_val[direction][xy][0]>>shift) + sx; + int my=(pict->motion_val[direction][xy][1]>>shift) + sy; draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); + } + }else{ + int sx= mb_x*16 + 8; + int sy= mb_y*16 + 8; + int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2); + int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; + int my= (pict->motion_val[direction][xy][1]>>shift) + sy; + draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); } - }else{ - int sx= mb_x*16 + 8; - int sy= mb_y*16 + 8; - int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2); - int mx= (pict->motion_val[0][xy][0]>>shift) + sx; - int my= (pict->motion_val[0][xy][1]>>shift) + sy; - draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); - } + } } if((s->avctx->debug&FF_DEBUG_VIS_QP) && pict->motion_val){ uint64_t c= (pict->qscale_table[mb_index]*128/31) * 0x0101010101010101ULL;
--- a/mpegvideo.h Mon Dec 29 22:25:08 2003 +0000 +++ b/mpegvideo.h Tue Dec 30 02:12:12 2003 +0000 @@ -304,6 +304,7 @@ Picture *last_picture_ptr; ///< pointer to the previous picture. Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred) Picture *current_picture_ptr; ///< pointer to the current picture + uint8_t *visualization_buffer[3]; //< temporary buffer vor MV visualization int last_dc[3]; ///< last DC values for MPEG1 int16_t *dc_val[3]; ///< used for mpeg4 DC prediction, all 3 arrays must be continuous int16_t dc_cache[4*5]; @@ -705,7 +706,7 @@ #define END_NOT_FOUND -100 int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size); void ff_mpeg_flush(AVCodecContext *avctx); -void ff_print_debug_info(MpegEncContext *s, Picture *pict); +void ff_print_debug_info(MpegEncContext *s, AVFrame *pict); void ff_write_quant_matrix(PutBitContext *pb, int16_t *matrix); int ff_find_unused_picture(MpegEncContext *s, int shared); void ff_denoise_dct(MpegEncContext *s, DCTELEM *block);
--- a/rv10.c Mon Dec 29 22:25:08 2003 +0000 +++ b/rv10.c Tue Dec 30 02:12:12 2003 +0000 @@ -662,10 +662,10 @@ if(s->pict_type==B_TYPE || s->low_delay){ *pict= *(AVFrame*)&s->current_picture; - ff_print_debug_info(s, s->current_picture_ptr); + ff_print_debug_info(s, pict); } else { *pict= *(AVFrame*)&s->last_picture; - ff_print_debug_info(s, s->last_picture_ptr); + ff_print_debug_info(s, pict); } *data_size = sizeof(AVFrame);