comparison mpegvideo.c @ 1598:932d306bf1dc libavcodec

av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
author michael
date Mon, 03 Nov 2003 13:26:22 +0000
parents 4c9165372ab3
children 079239998a38
comparison
equal deleted inserted replaced
1597:4c9165372ab3 1598:932d306bf1dc
272 assert(!pic->data[0]); 272 assert(!pic->data[0]);
273 273
274 r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic); 274 r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic);
275 275
276 if(r<0 || !pic->age || !pic->type || !pic->data[0]){ 276 if(r<0 || !pic->age || !pic->type || !pic->data[0]){
277 fprintf(stderr, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]); 277 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]);
278 return -1; 278 return -1;
279 } 279 }
280 280
281 if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){ 281 if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){
282 fprintf(stderr, "get_buffer() failed (stride changed)\n"); 282 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n");
283 return -1; 283 return -1;
284 } 284 }
285 285
286 if(pic->linesize[1] != pic->linesize[2]){ 286 if(pic->linesize[1] != pic->linesize[2]){
287 fprintf(stderr, "get_buffer() failed (uv stride missmatch)\n"); 287 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride missmatch)\n");
288 return -1; 288 return -1;
289 } 289 }
290 290
291 s->linesize = pic->linesize[0]; 291 s->linesize = pic->linesize[0];
292 s->uvlinesize= pic->linesize[1]; 292 s->uvlinesize= pic->linesize[1];
623 s->bit_rate = avctx->bit_rate; 623 s->bit_rate = avctx->bit_rate;
624 s->bit_rate_tolerance = avctx->bit_rate_tolerance; 624 s->bit_rate_tolerance = avctx->bit_rate_tolerance;
625 s->width = avctx->width; 625 s->width = avctx->width;
626 s->height = avctx->height; 626 s->height = avctx->height;
627 if(avctx->gop_size > 600){ 627 if(avctx->gop_size > 600){
628 fprintf(stderr, "Warning keyframe interval too large! reducing it ...\n"); 628 av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n");
629 avctx->gop_size=600; 629 avctx->gop_size=600;
630 } 630 }
631 s->gop_size = avctx->gop_size; 631 s->gop_size = avctx->gop_size;
632 s->rtp_mode = avctx->rtp_mode; 632 s->rtp_mode = avctx->rtp_mode;
633 s->rtp_payload_size = avctx->rtp_payload_size; 633 s->rtp_payload_size = avctx->rtp_payload_size;
668 && !s->fixed_qscale; 668 && !s->fixed_qscale;
669 669
670 s->progressive_sequence= !(avctx->flags & CODEC_FLAG_INTERLACED_DCT); 670 s->progressive_sequence= !(avctx->flags & CODEC_FLAG_INTERLACED_DCT);
671 671
672 if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4){ 672 if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4){
673 fprintf(stderr, "4MV not supporetd by codec\n"); 673 av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n");
674 return -1; 674 return -1;
675 } 675 }
676 676
677 if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){ 677 if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){
678 fprintf(stderr, "qpel not supporetd by codec\n"); 678 av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n");
679 return -1; 679 return -1;
680 } 680 }
681 681
682 if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){ 682 if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){
683 fprintf(stderr, "data partitioning not supporetd by codec\n"); 683 av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n");
684 return -1; 684 return -1;
685 } 685 }
686 686
687 if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){ 687 if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){
688 fprintf(stderr, "b frames not supporetd by codec\n"); 688 av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n");
689 return -1; 689 return -1;
690 } 690 }
691 691
692 if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too 692 if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too
693 fprintf(stderr, "mpeg2 style quantization not supporetd by codec\n"); 693 av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supporetd by codec\n");
694 return -1; 694 return -1;
695 } 695 }
696 696
697 if((s->flags & CODEC_FLAG_CBP_RD) && !(s->flags & CODEC_FLAG_TRELLIS_QUANT)){ 697 if((s->flags & CODEC_FLAG_CBP_RD) && !(s->flags & CODEC_FLAG_TRELLIS_QUANT)){
698 fprintf(stderr, "CBP RD needs trellis quant\n"); 698 av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
699 return -1; 699 return -1;
700 } 700 }
701 701
702 if(s->codec_id==CODEC_ID_MJPEG){ 702 if(s->codec_id==CODEC_ID_MJPEG){
703 s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x 703 s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x
751 s->low_delay=1; 751 s->low_delay=1;
752 break; 752 break;
753 #ifdef CONFIG_RISKY 753 #ifdef CONFIG_RISKY
754 case CODEC_ID_H263: 754 case CODEC_ID_H263:
755 if (h263_get_picture_format(s->width, s->height) == 7) { 755 if (h263_get_picture_format(s->width, s->height) == 7) {
756 printf("Input picture size isn't suitable for h263 codec! try h263+\n"); 756 av_log(avctx, AV_LOG_INFO, "Input picture size isn't suitable for h263 codec! try h263+\n");
757 return -1; 757 return -1;
758 } 758 }
759 s->out_format = FMT_H263; 759 s->out_format = FMT_H263;
760 avctx->delay=0; 760 avctx->delay=0;
761 s->low_delay=1; 761 s->low_delay=1;
1076 /* release forgotten pictures */ 1076 /* release forgotten pictures */
1077 /* if(mpeg124/h263) */ 1077 /* if(mpeg124/h263) */
1078 if(!s->encoding){ 1078 if(!s->encoding){
1079 for(i=0; i<MAX_PICTURE_COUNT; i++){ 1079 for(i=0; i<MAX_PICTURE_COUNT; i++){
1080 if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){ 1080 if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){
1081 fprintf(stderr, "releasing zombie picture\n"); 1081 av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n");
1082 avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]); 1082 avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);
1083 } 1083 }
1084 } 1084 }
1085 } 1085 }
1086 } 1086 }
1126 1126
1127 if(s->last_picture_ptr) copy_picture(&s->last_picture, s->last_picture_ptr); 1127 if(s->last_picture_ptr) copy_picture(&s->last_picture, s->last_picture_ptr);
1128 if(s->next_picture_ptr) copy_picture(&s->next_picture, s->next_picture_ptr); 1128 if(s->next_picture_ptr) copy_picture(&s->next_picture, s->next_picture_ptr);
1129 1129
1130 if(s->pict_type != I_TYPE && (s->last_picture_ptr==NULL || s->last_picture_ptr->data[0]==NULL)){ 1130 if(s->pict_type != I_TYPE && (s->last_picture_ptr==NULL || s->last_picture_ptr->data[0]==NULL)){
1131 fprintf(stderr, "warning: first frame is no keyframe\n"); 1131 av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n");
1132 assert(s->pict_type != B_TYPE); //these should have been dropped if we dont have a reference 1132 assert(s->pict_type != B_TYPE); //these should have been dropped if we dont have a reference
1133 goto alloc; 1133 goto alloc;
1134 } 1134 }
1135 1135
1136 assert(s->pict_type == I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0])); 1136 assert(s->pict_type == I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0]));
1313 for(y=0; y<s->mb_height; y++){ 1313 for(y=0; y<s->mb_height; y++){
1314 for(x=0; x<s->mb_width; x++){ 1314 for(x=0; x<s->mb_width; x++){
1315 if(s->avctx->debug&FF_DEBUG_SKIP){ 1315 if(s->avctx->debug&FF_DEBUG_SKIP){
1316 int count= s->mbskip_table[x + y*s->mb_stride]; 1316 int count= s->mbskip_table[x + y*s->mb_stride];
1317 if(count>9) count=9; 1317 if(count>9) count=9;
1318 printf("%1d", count); 1318 av_log(s->avctx, AV_LOG_DEBUG, "%1d", count);
1319 } 1319 }
1320 if(s->avctx->debug&FF_DEBUG_QP){ 1320 if(s->avctx->debug&FF_DEBUG_QP){
1321 printf("%2d", pict->qscale_table[x + y*s->mb_stride]); 1321 av_log(s->avctx, AV_LOG_DEBUG, "%2d", pict->qscale_table[x + y*s->mb_stride]);
1322 } 1322 }
1323 if(s->avctx->debug&FF_DEBUG_MB_TYPE){ 1323 if(s->avctx->debug&FF_DEBUG_MB_TYPE){
1324 int mb_type= pict->mb_type[x + y*s->mb_stride]; 1324 int mb_type= pict->mb_type[x + y*s->mb_stride];
1325 1325
1326 //Type & MV direction 1326 //Type & MV direction
1327 if(IS_PCM(mb_type)) 1327 if(IS_PCM(mb_type))
1328 printf("P"); 1328 av_log(s->avctx, AV_LOG_DEBUG, "P");
1329 else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type)) 1329 else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type))
1330 printf("A"); 1330 av_log(s->avctx, AV_LOG_DEBUG, "A");
1331 else if(IS_INTRA4x4(mb_type)) 1331 else if(IS_INTRA4x4(mb_type))
1332 printf("i"); 1332 av_log(s->avctx, AV_LOG_DEBUG, "i");
1333 else if(IS_INTRA16x16(mb_type)) 1333 else if(IS_INTRA16x16(mb_type))
1334 printf("I"); 1334 av_log(s->avctx, AV_LOG_DEBUG, "I");
1335 else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type)) 1335 else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type))
1336 printf("d"); 1336 av_log(s->avctx, AV_LOG_DEBUG, "d");
1337 else if(IS_DIRECT(mb_type)) 1337 else if(IS_DIRECT(mb_type))
1338 printf("D"); 1338 av_log(s->avctx, AV_LOG_DEBUG, "D");
1339 else if(IS_GMC(mb_type) && IS_SKIP(mb_type)) 1339 else if(IS_GMC(mb_type) && IS_SKIP(mb_type))
1340 printf("g"); 1340 av_log(s->avctx, AV_LOG_DEBUG, "g");
1341 else if(IS_GMC(mb_type)) 1341 else if(IS_GMC(mb_type))
1342 printf("G"); 1342 av_log(s->avctx, AV_LOG_DEBUG, "G");
1343 else if(IS_SKIP(mb_type)) 1343 else if(IS_SKIP(mb_type))
1344 printf("S"); 1344 av_log(s->avctx, AV_LOG_DEBUG, "S");
1345 else if(!USES_LIST(mb_type, 1)) 1345 else if(!USES_LIST(mb_type, 1))
1346 printf(">"); 1346 av_log(s->avctx, AV_LOG_DEBUG, ">");
1347 else if(!USES_LIST(mb_type, 0)) 1347 else if(!USES_LIST(mb_type, 0))
1348 printf("<"); 1348 av_log(s->avctx, AV_LOG_DEBUG, "<");
1349 else{ 1349 else{
1350 assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1)); 1350 assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
1351 printf("X"); 1351 av_log(s->avctx, AV_LOG_DEBUG, "X");
1352 } 1352 }
1353 1353
1354 //segmentation 1354 //segmentation
1355 if(IS_8X8(mb_type)) 1355 if(IS_8X8(mb_type))
1356 printf("+"); 1356 av_log(s->avctx, AV_LOG_DEBUG, "+");
1357 else if(IS_16X8(mb_type)) 1357 else if(IS_16X8(mb_type))
1358 printf("-"); 1358 av_log(s->avctx, AV_LOG_DEBUG, "-");
1359 else if(IS_8X16(mb_type)) 1359 else if(IS_8X16(mb_type))
1360 printf("¦"); 1360 av_log(s->avctx, AV_LOG_DEBUG, "¦");
1361 else if(IS_INTRA(mb_type) || IS_16X16(mb_type)) 1361 else if(IS_INTRA(mb_type) || IS_16X16(mb_type))
1362 printf(" "); 1362 av_log(s->avctx, AV_LOG_DEBUG, " ");
1363 else 1363 else
1364 printf("?"); 1364 av_log(s->avctx, AV_LOG_DEBUG, "?");
1365 1365
1366 1366
1367 if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264) 1367 if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264)
1368 printf("="); 1368 av_log(s->avctx, AV_LOG_DEBUG, "=");
1369 else 1369 else
1370 printf(" "); 1370 av_log(s->avctx, AV_LOG_DEBUG, " ");
1371 } 1371 }
1372 // printf(" "); 1372 // av_log(s->avctx, AV_LOG_DEBUG, " ");
1373 } 1373 }
1374 printf("\n"); 1374 av_log(s->avctx, AV_LOG_DEBUG, "\n");
1375 } 1375 }
1376 } 1376 }
1377 1377
1378 if((s->avctx->debug&FF_DEBUG_VIS_MV) && s->motion_val){ 1378 if((s->avctx->debug&FF_DEBUG_VIS_MV) && s->motion_val){
1379 const int shift= 1 + s->quarter_sample; 1379 const int shift= 1 + s->quarter_sample;
1455 if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0; 1455 if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0;
1456 if(pic_arg->linesize[0] != s->linesize) direct=0; 1456 if(pic_arg->linesize[0] != s->linesize) direct=0;
1457 if(pic_arg->linesize[1] != s->uvlinesize) direct=0; 1457 if(pic_arg->linesize[1] != s->uvlinesize) direct=0;
1458 if(pic_arg->linesize[2] != s->uvlinesize) direct=0; 1458 if(pic_arg->linesize[2] != s->uvlinesize) direct=0;
1459 1459
1460 // printf("%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize); 1460 // av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize);
1461 1461
1462 if(direct){ 1462 if(direct){
1463 i= ff_find_unused_picture(s, 1); 1463 i= ff_find_unused_picture(s, 1);
1464 1464
1465 pic= (AVFrame*)&s->picture[i]; 1465 pic= (AVFrame*)&s->picture[i];
1562 for(b_frames=0; b_frames<s->max_b_frames+1; b_frames++){ 1562 for(b_frames=0; b_frames<s->max_b_frames+1; b_frames++){
1563 if(s->input_picture[b_frames]->pict_type!=B_TYPE) break; 1563 if(s->input_picture[b_frames]->pict_type!=B_TYPE) break;
1564 } 1564 }
1565 1565
1566 if(b_frames > s->max_b_frames){ 1566 if(b_frames > s->max_b_frames){
1567 fprintf(stderr, "warning, too many bframes in a row\n"); 1567 av_log(s->avctx, AV_LOG_ERROR, "warning, too many bframes in a row\n");
1568 b_frames = s->max_b_frames; 1568 b_frames = s->max_b_frames;
1569 } 1569 }
1570 }else if(s->b_frame_strategy==0){ 1570 }else if(s->b_frame_strategy==0){
1571 b_frames= s->max_b_frames; 1571 b_frames= s->max_b_frames;
1572 while(b_frames && !s->input_picture[b_frames]) b_frames--; 1572 while(b_frames && !s->input_picture[b_frames]) b_frames--;
1587 /* reset scores */ 1587 /* reset scores */
1588 for(i=0; i<b_frames+1; i++){ 1588 for(i=0; i<b_frames+1; i++){
1589 s->input_picture[i]->b_frame_score=0; 1589 s->input_picture[i]->b_frame_score=0;
1590 } 1590 }
1591 }else{ 1591 }else{
1592 fprintf(stderr, "illegal b frame strategy\n"); 1592 av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n");
1593 b_frames=0; 1593 b_frames=0;
1594 } 1594 }
1595 1595
1596 emms_c(); 1596 emms_c();
1597 //static int b_count=0; 1597 //static int b_count=0;
1598 //b_count+= b_frames; 1598 //b_count+= b_frames;
1599 //printf("b_frames: %d\n", b_count); 1599 //av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count);
1600 1600
1601 s->reordered_input_picture[0]= s->input_picture[b_frames]; 1601 s->reordered_input_picture[0]= s->input_picture[b_frames];
1602 if( s->picture_in_gop_number + b_frames >= s->gop_size 1602 if( s->picture_in_gop_number + b_frames >= s->gop_size
1603 || s->reordered_input_picture[0]->pict_type== I_TYPE) 1603 || s->reordered_input_picture[0]->pict_type== I_TYPE)
1604 s->reordered_input_picture[0]->pict_type= I_TYPE; 1604 s->reordered_input_picture[0]->pict_type= I_TYPE;
1666 MpegEncContext *s = avctx->priv_data; 1666 MpegEncContext *s = avctx->priv_data;
1667 AVFrame *pic_arg = data; 1667 AVFrame *pic_arg = data;
1668 int i; 1668 int i;
1669 1669
1670 if(avctx->pix_fmt != PIX_FMT_YUV420P){ 1670 if(avctx->pix_fmt != PIX_FMT_YUV420P){
1671 fprintf(stderr, "this codec supports only YUV420P\n"); 1671 av_log(avctx, AV_LOG_ERROR, "this codec supports only YUV420P\n");
1672 return -1; 1672 return -1;
1673 } 1673 }
1674 1674
1675 init_put_bits(&s->pb, buf, buf_size); 1675 init_put_bits(&s->pb, buf, buf_size);
1676 1676
4000 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; 4000 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1];
4001 // printf(" %d %d ", motion_x, motion_y); 4001 // printf(" %d %d ", motion_x, motion_y);
4002 break; 4002 break;
4003 default: 4003 default:
4004 motion_x=motion_y=0; //gcc warning fix 4004 motion_x=motion_y=0; //gcc warning fix
4005 printf("illegal MB type\n"); 4005 av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\n");
4006 } 4006 }
4007 4007
4008 encode_mb(s, motion_x, motion_y); 4008 encode_mb(s, motion_x, motion_y);
4009 4009
4010 // RAL: Update last macrobloc type 4010 // RAL: Update last macrobloc type