Ticket #8343: 11_fix_h261dec_keyframe.patch
| File 11_fix_h261dec_keyframe.patch, 4.0 KB (added by , 7 years ago) |
|---|
-
libavcodec/h261.h
old new 35 35 * H261Context 36 36 */ 37 37 typedef struct H261Context { 38 38 MpegEncContext s; 39 39 40 int freeze_picture_release; // 1 if freeze picture release bit is set in the picture header 40 41 int current_mba; 41 42 int mba_diff; 42 43 int mtype; 43 44 int current_mv_x; 44 45 int current_mv_y; -
libavcodec/h261dec.c
old new static int h261_decode_picture_header(H2 500 500 s->picture_number = (s->picture_number & ~31) + i; 501 501 502 502 s->avctx->framerate = (AVRational) { 30000, 1001 }; 503 503 504 504 /* PTYPE starts here */ 505 skip_bits1(&s->gb); /* split screen off*/506 skip_bits1(&s->gb); /* camera off*/507 skip_bits1(&s->gb); /* freeze picture release off*/505 skip_bits1(&s->gb); /* split screen indicator */ 506 skip_bits1(&s->gb); /* document camera indicator */ 507 h->freeze_picture_release = get_bits1(&s->gb); /* freeze picture release */ 508 508 509 509 format = get_bits1(&s->gb); 510 510 511 511 // only 2 formats possible 512 512 if (format == 0) { // QCIF … … static int h261_decode_picture_header(H2 530 530 if (skip_1stop_8data_bits(&s->gb) < 0) 531 531 return AVERROR_INVALIDDATA; 532 532 533 533 /* H.261 has no I-frames, but if we pass AV_PICTURE_TYPE_I for the first 534 534 * frame, the codec crashes if it does not contain all I-blocks 535 * (e.g. when a packet is lost). */ 535 * (e.g. when a packet is lost). We will fix the picture type in the 536 * output frame based on h->freeze_picture_release later. */ 536 537 s->pict_type = AV_PICTURE_TYPE_P; 537 538 538 539 h->gob_number = 0; 539 540 return 0; 540 541 } … … static int h261_decode_frame(AVCodecCont 588 589 const uint8_t *buf = avpkt->data; 589 590 int buf_size = avpkt->size; 590 591 H261Context *h = avctx->priv_data; 591 592 MpegEncContext *s = &h->s; 592 593 int ret; 594 enum AVPictureType pict_type; 593 595 AVFrame *pict = data; 594 596 595 597 ff_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size); 596 598 ff_dlog(avctx, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); 597 599 … … retry: 628 630 return ret; 629 631 630 632 goto retry; 631 633 } 632 634 633 // for skipping the frame 634 s->current_picture.f->pict_type = s->pict_type; 635 s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I; 635 // for skipping the frame and keyframe markup 636 pict_type = h->freeze_picture_release ? AV_PICTURE_TYPE_I : s->pict_type; 636 637 637 if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||638 (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||638 if ((avctx->skip_frame >= AVDISCARD_NONREF && pict_type == AV_PICTURE_TYPE_B) || 639 (avctx->skip_frame >= AVDISCARD_NONKEY && pict_type != AV_PICTURE_TYPE_I) || 639 640 avctx->skip_frame >= AVDISCARD_ALL) 640 641 return get_consumed_bytes(s, buf_size); 641 642 643 s->current_picture.f->pict_type = s->pict_type; 644 s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I; 645 642 646 if (ff_mpv_frame_start(s, avctx) < 0) 643 647 return -1; 644 648 645 649 ff_mpeg_er_frame_start(s); 646 650 … … retry: 658 662 av_assert0(s->current_picture.f->pict_type == s->current_picture_ptr->f->pict_type); 659 663 av_assert0(s->current_picture.f->pict_type == s->pict_type); 660 664 661 665 if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0) 662 666 return ret; 667 668 // fix picture type and correctly mark keyframes 669 pict->pict_type = pict_type; 670 pict->key_frame = pict_type == AV_PICTURE_TYPE_I; 671 663 672 ff_print_debug_info(s, s->current_picture_ptr, pict); 664 673 665 674 *got_frame = 1; 666 675 667 676 return get_consumed_bytes(s, buf_size);
