Showing the changes to libavcodec (2 of 2 files). Show all
Unified · Split
| @@ -39,6 +39,7 @@ · 38 unmodified lines | ||
| 39 | 39 | #include "put_golomb.h" |
| 40 | 40 | #include "rangecoder.h" |
| 41 | 41 | #include "ffv1.h" |
| 42 | +#include "ffv1enc.h" | |
| 42 | 43 | |
| 43 | 44 | static const int8_t quant5_10bit[256] = { |
| 44 | 45 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, |
| @@ -512,16 +513,42 @@ static int sort_stt(FFV1Context *s, uint8_t stt[256]) · 467 unmodified lines | ||
| 512 | 513 | return print; |
| 513 | 514 | } |
| 514 | 515 | |
| 515 | −static av_cold int encode_init(AVCodecContext *avctx) | |
| 516 | + | |
| 517 | +static int encode_determine_slices(AVCodecContext *avctx) | |
| 516 | 518 | { |
| 517 | 519 | FFV1Context *s = avctx->priv_data; |
| 518 | − const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); | |
| 519 | − int i, j, k, m, ret; | |
| 520 | − | |
| 521 | − if ((ret = ff_ffv1_common_init(avctx)) < 0) | |
| 522 | − return ret; | |
| 520 | + int plane_count = 1 + 2*s->chroma_planes + s->transparency; | |
| 521 | + int max_h_slices = AV_CEIL_RSHIFT(avctx->width , s->chroma_h_shift); | |
| 522 | + int max_v_slices = AV_CEIL_RSHIFT(avctx->height, s->chroma_v_shift); | |
| 523 | + s->num_v_slices = (avctx->width > 352 || avctx->height > 288 || !avctx->slices) ? 2 : 1; | |
| 524 | + s->num_v_slices = FFMIN(s->num_v_slices, max_v_slices); | |
| 525 | + for (; s->num_v_slices < 32; s->num_v_slices++) { | |
| 526 | + for (s->num_h_slices = s->num_v_slices; s->num_h_slices < 2*s->num_v_slices; s->num_h_slices++) { | |
| 527 | + int maxw = (avctx->width + s->num_h_slices - 1) / s->num_h_slices; | |
| 528 | + int maxh = (avctx->height + s->num_v_slices - 1) / s->num_v_slices; | |
| 529 | + if (s->num_h_slices > max_h_slices || s->num_v_slices > max_v_slices) | |
| 530 | + continue; | |
| 531 | + if (maxw * maxh * (int64_t)(s->bits_per_raw_sample+1) * plane_count > 8<<24) | |
| 532 | + continue; | |
| 533 | + if (s->version < 4) | |
| 534 | + if ( ff_need_new_slices(avctx->width , s->num_h_slices, s->chroma_h_shift) | |
| 535 | + ||ff_need_new_slices(avctx->height, s->num_v_slices, s->chroma_v_shift)) | |
| 536 | + continue; | |
| 537 | + if (avctx->slices == s->num_h_slices * s->num_v_slices && avctx->slices <= MAX_SLICES || !avctx->slices) | |
| 538 | + return 0; | |
| 539 | + } | |
| 540 | + } | |
| 541 | + av_log(avctx, AV_LOG_ERROR, | |
| 542 | + "Unsupported number %d of slices requested, please specify a " | |
| 543 | + "supported number with -slices (ex:4,6,9,12,16, ...)\n", | |
| 544 | + avctx->slices); | |
| 545 | + return AVERROR(ENOSYS); | |
| 546 | +} | |
| 523 | 547 | |
| 524 | − s->version = 0; | |
| 548 | +av_cold int ff_ffv1_encode_init(AVCodecContext *avctx) | |
| 549 | +{ | |
| 550 | + FFV1Context *s = avctx->priv_data; | |
| 551 | + int i, j, k, m, ret; | |
| 525 | 552 | |
| 526 | 553 | if ((avctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) || |
| 527 | 554 | avctx->slices > 1) |
| @@ -568,153 +595,6 @@ static av_cold int encode_init(AVCodecContext *avctx) · 40 unmodified lines | ||
| 568 | 595 | return AVERROR_INVALIDDATA; |
| 569 | 596 | } |
| 570 | 597 | |
| 571 | − if (s->ac == 1) // Compatbility with common command line usage | |
| 572 | − s->ac = AC_RANGE_CUSTOM_TAB; | |
| 573 | − else if (s->ac == AC_RANGE_DEFAULT_TAB_FORCE) | |
| 574 | − s->ac = AC_RANGE_DEFAULT_TAB; | |
| 575 | − | |
| 576 | − s->plane_count = 3; | |
| 577 | − switch(avctx->pix_fmt) { | |
| 578 | − case AV_PIX_FMT_GRAY9: | |
| 579 | − case AV_PIX_FMT_YUV444P9: | |
| 580 | − case AV_PIX_FMT_YUV422P9: | |
| 581 | − case AV_PIX_FMT_YUV420P9: | |
| 582 | − case AV_PIX_FMT_YUVA444P9: | |
| 583 | − case AV_PIX_FMT_YUVA422P9: | |
| 584 | − case AV_PIX_FMT_YUVA420P9: | |
| 585 | − if (!avctx->bits_per_raw_sample) | |
| 586 | − s->bits_per_raw_sample = 9; | |
| 587 | − case AV_PIX_FMT_GRAY10: | |
| 588 | − case AV_PIX_FMT_YUV444P10: | |
| 589 | − case AV_PIX_FMT_YUV440P10: | |
| 590 | − case AV_PIX_FMT_YUV420P10: | |
| 591 | − case AV_PIX_FMT_YUV422P10: | |
| 592 | − case AV_PIX_FMT_YUVA444P10: | |
| 593 | − case AV_PIX_FMT_YUVA422P10: | |
| 594 | − case AV_PIX_FMT_YUVA420P10: | |
| 595 | − if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 596 | − s->bits_per_raw_sample = 10; | |
| 597 | − case AV_PIX_FMT_GRAY12: | |
| 598 | − case AV_PIX_FMT_YUV444P12: | |
| 599 | − case AV_PIX_FMT_YUV440P12: | |
| 600 | − case AV_PIX_FMT_YUV420P12: | |
| 601 | − case AV_PIX_FMT_YUV422P12: | |
| 602 | − case AV_PIX_FMT_YUVA444P12: | |
| 603 | − case AV_PIX_FMT_YUVA422P12: | |
| 604 | − if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 605 | − s->bits_per_raw_sample = 12; | |
| 606 | − case AV_PIX_FMT_GRAY14: | |
| 607 | − case AV_PIX_FMT_YUV444P14: | |
| 608 | − case AV_PIX_FMT_YUV420P14: | |
| 609 | − case AV_PIX_FMT_YUV422P14: | |
| 610 | − if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 611 | − s->bits_per_raw_sample = 14; | |
| 612 | − s->packed_at_lsb = 1; | |
| 613 | − case AV_PIX_FMT_GRAY16: | |
| 614 | − case AV_PIX_FMT_YUV444P16: | |
| 615 | − case AV_PIX_FMT_YUV422P16: | |
| 616 | − case AV_PIX_FMT_YUV420P16: | |
| 617 | − case AV_PIX_FMT_YUVA444P16: | |
| 618 | − case AV_PIX_FMT_YUVA422P16: | |
| 619 | − case AV_PIX_FMT_YUVA420P16: | |
| 620 | − if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) { | |
| 621 | − s->bits_per_raw_sample = 16; | |
| 622 | − } else if (!s->bits_per_raw_sample) { | |
| 623 | − s->bits_per_raw_sample = avctx->bits_per_raw_sample; | |
| 624 | − } | |
| 625 | − if (s->bits_per_raw_sample <= 8) { | |
| 626 | − av_log(avctx, AV_LOG_ERROR, "bits_per_raw_sample invalid\n"); | |
| 627 | − return AVERROR_INVALIDDATA; | |
| 628 | − } | |
| 629 | − s->version = FFMAX(s->version, 1); | |
| 630 | − case AV_PIX_FMT_GRAY8: | |
| 631 | − case AV_PIX_FMT_YA8: | |
| 632 | − case AV_PIX_FMT_YUV444P: | |
| 633 | − case AV_PIX_FMT_YUV440P: | |
| 634 | − case AV_PIX_FMT_YUV422P: | |
| 635 | − case AV_PIX_FMT_YUV420P: | |
| 636 | − case AV_PIX_FMT_YUV411P: | |
| 637 | − case AV_PIX_FMT_YUV410P: | |
| 638 | − case AV_PIX_FMT_YUVA444P: | |
| 639 | − case AV_PIX_FMT_YUVA422P: | |
| 640 | − case AV_PIX_FMT_YUVA420P: | |
| 641 | − s->chroma_planes = desc->nb_components < 3 ? 0 : 1; | |
| 642 | − s->colorspace = 0; | |
| 643 | − s->transparency = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA); | |
| 644 | − if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 645 | − s->bits_per_raw_sample = 8; | |
| 646 | − else if (!s->bits_per_raw_sample) | |
| 647 | − s->bits_per_raw_sample = 8; | |
| 648 | − break; | |
| 649 | − case AV_PIX_FMT_RGB32: | |
| 650 | − s->colorspace = 1; | |
| 651 | − s->transparency = 1; | |
| 652 | − s->chroma_planes = 1; | |
| 653 | − s->bits_per_raw_sample = 8; | |
| 654 | − break; | |
| 655 | − case AV_PIX_FMT_RGBA64: | |
| 656 | − s->colorspace = 1; | |
| 657 | − s->transparency = 1; | |
| 658 | − s->chroma_planes = 1; | |
| 659 | − s->bits_per_raw_sample = 16; | |
| 660 | − s->use32bit = 1; | |
| 661 | − s->version = FFMAX(s->version, 1); | |
| 662 | − break; | |
| 663 | − case AV_PIX_FMT_RGB48: | |
| 664 | − s->colorspace = 1; | |
| 665 | − s->chroma_planes = 1; | |
| 666 | − s->bits_per_raw_sample = 16; | |
| 667 | − s->use32bit = 1; | |
| 668 | − s->version = FFMAX(s->version, 1); | |
| 669 | − break; | |
| 670 | − case AV_PIX_FMT_0RGB32: | |
| 671 | − s->colorspace = 1; | |
| 672 | − s->chroma_planes = 1; | |
| 673 | − s->bits_per_raw_sample = 8; | |
| 674 | − break; | |
| 675 | − case AV_PIX_FMT_GBRP9: | |
| 676 | − if (!avctx->bits_per_raw_sample) | |
| 677 | − s->bits_per_raw_sample = 9; | |
| 678 | − case AV_PIX_FMT_GBRP10: | |
| 679 | − case AV_PIX_FMT_GBRAP10: | |
| 680 | − if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 681 | − s->bits_per_raw_sample = 10; | |
| 682 | − case AV_PIX_FMT_GBRP12: | |
| 683 | − case AV_PIX_FMT_GBRAP12: | |
| 684 | − if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 685 | − s->bits_per_raw_sample = 12; | |
| 686 | − case AV_PIX_FMT_GBRP14: | |
| 687 | − case AV_PIX_FMT_GBRAP14: | |
| 688 | − if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 689 | − s->bits_per_raw_sample = 14; | |
| 690 | − case AV_PIX_FMT_GBRP16: | |
| 691 | − case AV_PIX_FMT_GBRAP16: | |
| 692 | − if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 693 | − s->bits_per_raw_sample = 16; | |
| 694 | − else if (!s->bits_per_raw_sample) | |
| 695 | − s->bits_per_raw_sample = avctx->bits_per_raw_sample; | |
| 696 | − s->transparency = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA); | |
| 697 | − s->colorspace = 1; | |
| 698 | − s->chroma_planes = 1; | |
| 699 | − if (s->bits_per_raw_sample >= 16) { | |
| 700 | − s->use32bit = 1; | |
| 701 | − } | |
| 702 | − s->version = FFMAX(s->version, 1); | |
| 703 | − break; | |
| 704 | − default: | |
| 705 | − av_log(avctx, AV_LOG_ERROR, "format not supported\n"); | |
| 706 | − return AVERROR(ENOSYS); | |
| 707 | − } | |
| 708 | − av_assert0(s->bits_per_raw_sample >= 8); | |
| 709 | − | |
| 710 | − if (s->bits_per_raw_sample > (s->version > 3 ? 16 : 8)) { | |
| 711 | − if (s->ac == AC_GOLOMB_RICE) { | |
| 712 | − av_log(avctx, AV_LOG_INFO, | |
| 713 | − "high bits_per_raw_sample, forcing range coder\n"); | |
| 714 | − s->ac = AC_RANGE_CUSTOM_TAB; | |
| 715 | − } | |
| 716 | − } | |
| 717 | − | |
| 718 | 598 | if (s->ac == AC_RANGE_CUSTOM_TAB) { |
| 719 | 599 | for (i = 1; i < 256; i++) |
| 720 | 600 | s->state_transition[i] = ver2_state[i]; |
| @@ -725,7 +605,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 4 unmodified lines | ||
| 725 | 605 | s->state_transition[i] = c.one_state[i]; |
| 726 | 606 | } |
| 727 | 607 | |
| 728 | − for (i = 0; i < MAX_QUANT_TABLE_SIZE; i++) { | |
| 608 | + for (i = 0; i < 256; i++) { | |
| 729 | 609 | s->quant_table_count = 2; |
| 730 | 610 | if ((s->qtable == -1 && s->bits_per_raw_sample <= 8) || s->qtable == 1) { |
| 731 | 611 | s->quant_tables[0][0][i]= quant11[i]; |
| @@ -760,10 +640,6 @@ static av_cold int encode_init(AVCodecContext *avctx) · 28 unmodified lines | ||
| 760 | 640 | if (!s->chroma_planes && s->version > 3) |
| 761 | 641 | s->plane_count--; |
| 762 | 642 | |
| 763 | − ret = av_pix_fmt_get_chroma_sub_sample (avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); | |
| 764 | − if (ret) | |
| 765 | − return ret; | |
| 766 | − | |
| 767 | 643 | s->picture_number = 0; |
| 768 | 644 | |
| 769 | 645 | if (avctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) { |
| @@ -856,36 +732,14 @@ static av_cold int encode_init(AVCodecContext *avctx) · 86 unmodified lines | ||
| 856 | 732 | av_freep(&best_state); |
| 857 | 733 | } |
| 858 | 734 | |
| 859 | − if (s->version > 1) { | |
| 860 | − int plane_count = 1 + 2*s->chroma_planes + s->transparency; | |
| 861 | − int max_h_slices = AV_CEIL_RSHIFT(avctx->width , s->chroma_h_shift); | |
| 862 | − int max_v_slices = AV_CEIL_RSHIFT(avctx->height, s->chroma_v_shift); | |
| 863 | − s->num_v_slices = (avctx->width > 352 || avctx->height > 288 || !avctx->slices) ? 2 : 1; | |
| 864 | − | |
| 865 | − s->num_v_slices = FFMIN(s->num_v_slices, max_v_slices); | |
| 735 | + if (s->version <= 1) { | |
| 736 | + /* Disable slices when the version doesn't support them */ | |
| 737 | + s->num_h_slices = 1; | |
| 738 | + s->num_v_slices = 1; | |
| 739 | + } else { | |
| 740 | + if ((ret = encode_determine_slices(avctx)) < 0) | |
| 741 | + return ret; | |
| 866 | 742 | |
| 867 | − for (; s->num_v_slices < 32; s->num_v_slices++) { | |
| 868 | − for (s->num_h_slices = s->num_v_slices; s->num_h_slices < 2*s->num_v_slices; s->num_h_slices++) { | |
| 869 | − int maxw = (avctx->width + s->num_h_slices - 1) / s->num_h_slices; | |
| 870 | − int maxh = (avctx->height + s->num_v_slices - 1) / s->num_v_slices; | |
| 871 | − if (s->num_h_slices > max_h_slices || s->num_v_slices > max_v_slices) | |
| 872 | − continue; | |
| 873 | − if (maxw * maxh * (int64_t)(s->bits_per_raw_sample+1) * plane_count > 8<<24) | |
| 874 | − continue; | |
| 875 | − if (s->version < 4) | |
| 876 | − if ( ff_need_new_slices(avctx->width , s->num_h_slices, s->chroma_h_shift) | |
| 877 | − ||ff_need_new_slices(avctx->height, s->num_v_slices, s->chroma_v_shift)) | |
| 878 | − continue; | |
| 879 | − if (avctx->slices == s->num_h_slices * s->num_v_slices && avctx->slices <= MAX_SLICES || !avctx->slices) | |
| 880 | − goto slices_ok; | |
| 881 | − } | |
| 882 | − } | |
| 883 | − av_log(avctx, AV_LOG_ERROR, | |
| 884 | − "Unsupported number %d of slices requested, please specify a " | |
| 885 | − "supported number with -slices (ex:4,6,9,12,16, ...)\n", | |
| 886 | − avctx->slices); | |
| 887 | − return AVERROR(ENOSYS); | |
| 888 | −slices_ok: | |
| 889 | 743 | if ((ret = write_extradata(s)) < 0) |
| 890 | 744 | return ret; |
| 891 | 745 | } |
| @@ -908,13 +762,178 @@ slices_ok: · 16 unmodified lines | ||
| 908 | 762 | if ((ret = ff_ffv1_init_slices_state(s)) < 0) |
| 909 | 763 | return ret; |
| 910 | 764 | |
| 765 | + return 0; | |
| 766 | +} | |
| 767 | + | |
| 768 | +static int encode_init_internal(AVCodecContext *avctx) | |
| 769 | +{ | |
| 770 | + int ret; | |
| 771 | + FFV1Context *s = avctx->priv_data; | |
| 772 | + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); | |
| 773 | + | |
| 774 | + if ((ret = ff_ffv1_common_init(avctx)) < 0) | |
| 775 | + return ret; | |
| 776 | + | |
| 777 | + if (s->ac == 1) // Compatbility with common command line usage | |
| 778 | + s->ac = AC_RANGE_CUSTOM_TAB; | |
| 779 | + else if (s->ac == AC_RANGE_DEFAULT_TAB_FORCE) | |
| 780 | + s->ac = AC_RANGE_DEFAULT_TAB; | |
| 781 | + | |
| 782 | + s->plane_count = 3; | |
| 783 | + switch(avctx->pix_fmt) { | |
| 784 | + case AV_PIX_FMT_GRAY9: | |
| 785 | + case AV_PIX_FMT_YUV444P9: | |
| 786 | + case AV_PIX_FMT_YUV422P9: | |
| 787 | + case AV_PIX_FMT_YUV420P9: | |
| 788 | + case AV_PIX_FMT_YUVA444P9: | |
| 789 | + case AV_PIX_FMT_YUVA422P9: | |
| 790 | + case AV_PIX_FMT_YUVA420P9: | |
| 791 | + if (!avctx->bits_per_raw_sample) | |
| 792 | + s->bits_per_raw_sample = 9; | |
| 793 | + case AV_PIX_FMT_GRAY10: | |
| 794 | + case AV_PIX_FMT_YUV444P10: | |
| 795 | + case AV_PIX_FMT_YUV440P10: | |
| 796 | + case AV_PIX_FMT_YUV420P10: | |
| 797 | + case AV_PIX_FMT_YUV422P10: | |
| 798 | + case AV_PIX_FMT_YUVA444P10: | |
| 799 | + case AV_PIX_FMT_YUVA422P10: | |
| 800 | + case AV_PIX_FMT_YUVA420P10: | |
| 801 | + if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 802 | + s->bits_per_raw_sample = 10; | |
| 803 | + case AV_PIX_FMT_GRAY12: | |
| 804 | + case AV_PIX_FMT_YUV444P12: | |
| 805 | + case AV_PIX_FMT_YUV440P12: | |
| 806 | + case AV_PIX_FMT_YUV420P12: | |
| 807 | + case AV_PIX_FMT_YUV422P12: | |
| 808 | + case AV_PIX_FMT_YUVA444P12: | |
| 809 | + case AV_PIX_FMT_YUVA422P12: | |
| 810 | + if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 811 | + s->bits_per_raw_sample = 12; | |
| 812 | + case AV_PIX_FMT_GRAY14: | |
| 813 | + case AV_PIX_FMT_YUV444P14: | |
| 814 | + case AV_PIX_FMT_YUV420P14: | |
| 815 | + case AV_PIX_FMT_YUV422P14: | |
| 816 | + if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 817 | + s->bits_per_raw_sample = 14; | |
| 818 | + s->packed_at_lsb = 1; | |
| 819 | + case AV_PIX_FMT_GRAY16: | |
| 820 | + case AV_PIX_FMT_YUV444P16: | |
| 821 | + case AV_PIX_FMT_YUV422P16: | |
| 822 | + case AV_PIX_FMT_YUV420P16: | |
| 823 | + case AV_PIX_FMT_YUVA444P16: | |
| 824 | + case AV_PIX_FMT_YUVA422P16: | |
| 825 | + case AV_PIX_FMT_YUVA420P16: | |
| 826 | + if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) { | |
| 827 | + s->bits_per_raw_sample = 16; | |
| 828 | + } else if (!s->bits_per_raw_sample) { | |
| 829 | + s->bits_per_raw_sample = avctx->bits_per_raw_sample; | |
| 830 | + } | |
| 831 | + if (s->bits_per_raw_sample <= 8) { | |
| 832 | + av_log(avctx, AV_LOG_ERROR, "bits_per_raw_sample invalid\n"); | |
| 833 | + return AVERROR_INVALIDDATA; | |
| 834 | + } | |
| 835 | + s->version = FFMAX(s->version, 1); | |
| 836 | + case AV_PIX_FMT_GRAY8: | |
| 837 | + case AV_PIX_FMT_YA8: | |
| 838 | + case AV_PIX_FMT_YUV444P: | |
| 839 | + case AV_PIX_FMT_YUV440P: | |
| 840 | + case AV_PIX_FMT_YUV422P: | |
| 841 | + case AV_PIX_FMT_YUV420P: | |
| 842 | + case AV_PIX_FMT_YUV411P: | |
| 843 | + case AV_PIX_FMT_YUV410P: | |
| 844 | + case AV_PIX_FMT_YUVA444P: | |
| 845 | + case AV_PIX_FMT_YUVA422P: | |
| 846 | + case AV_PIX_FMT_YUVA420P: | |
| 847 | + s->chroma_planes = desc->nb_components < 3 ? 0 : 1; | |
| 848 | + s->colorspace = 0; | |
| 849 | + s->transparency = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA); | |
| 850 | + if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 851 | + s->bits_per_raw_sample = 8; | |
| 852 | + else if (!s->bits_per_raw_sample) | |
| 853 | + s->bits_per_raw_sample = 8; | |
| 854 | + break; | |
| 855 | + case AV_PIX_FMT_RGB32: | |
| 856 | + s->colorspace = 1; | |
| 857 | + s->transparency = 1; | |
| 858 | + s->chroma_planes = 1; | |
| 859 | + s->bits_per_raw_sample = 8; | |
| 860 | + break; | |
| 861 | + case AV_PIX_FMT_RGBA64: | |
| 862 | + s->colorspace = 1; | |
| 863 | + s->transparency = 1; | |
| 864 | + s->chroma_planes = 1; | |
| 865 | + s->bits_per_raw_sample = 16; | |
| 866 | + s->use32bit = 1; | |
| 867 | + s->version = FFMAX(s->version, 1); | |
| 868 | + break; | |
| 869 | + case AV_PIX_FMT_RGB48: | |
| 870 | + s->colorspace = 1; | |
| 871 | + s->chroma_planes = 1; | |
| 872 | + s->bits_per_raw_sample = 16; | |
| 873 | + s->use32bit = 1; | |
| 874 | + s->version = FFMAX(s->version, 1); | |
| 875 | + break; | |
| 876 | + case AV_PIX_FMT_0RGB32: | |
| 877 | + s->colorspace = 1; | |
| 878 | + s->chroma_planes = 1; | |
| 879 | + s->bits_per_raw_sample = 8; | |
| 880 | + break; | |
| 881 | + case AV_PIX_FMT_GBRP9: | |
| 882 | + if (!avctx->bits_per_raw_sample) | |
| 883 | + s->bits_per_raw_sample = 9; | |
| 884 | + case AV_PIX_FMT_GBRP10: | |
| 885 | + case AV_PIX_FMT_GBRAP10: | |
| 886 | + if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 887 | + s->bits_per_raw_sample = 10; | |
| 888 | + case AV_PIX_FMT_GBRP12: | |
| 889 | + case AV_PIX_FMT_GBRAP12: | |
| 890 | + if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 891 | + s->bits_per_raw_sample = 12; | |
| 892 | + case AV_PIX_FMT_GBRP14: | |
| 893 | + case AV_PIX_FMT_GBRAP14: | |
| 894 | + if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 895 | + s->bits_per_raw_sample = 14; | |
| 896 | + case AV_PIX_FMT_GBRP16: | |
| 897 | + case AV_PIX_FMT_GBRAP16: | |
| 898 | + if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample) | |
| 899 | + s->bits_per_raw_sample = 16; | |
| 900 | + else if (!s->bits_per_raw_sample) | |
| 901 | + s->bits_per_raw_sample = avctx->bits_per_raw_sample; | |
| 902 | + s->transparency = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA); | |
| 903 | + s->colorspace = 1; | |
| 904 | + s->chroma_planes = 1; | |
| 905 | + if (s->bits_per_raw_sample >= 16) { | |
| 906 | + s->use32bit = 1; | |
| 907 | + } | |
| 908 | + s->version = FFMAX(s->version, 1); | |
| 909 | + break; | |
| 910 | + default: | |
| 911 | + av_log(avctx, AV_LOG_ERROR, "format not supported\n"); | |
| 912 | + return AVERROR(ENOSYS); | |
| 913 | + } | |
| 914 | + av_assert0(s->bits_per_raw_sample >= 8); | |
| 915 | + | |
| 916 | + if (s->bits_per_raw_sample > (s->version > 3 ? 16 : 8)) { | |
| 917 | + if (s->ac == AC_GOLOMB_RICE) { | |
| 918 | + av_log(avctx, AV_LOG_INFO, | |
| 919 | + "high bits_per_raw_sample, forcing range coder\n"); | |
| 920 | + s->ac = AC_RANGE_CUSTOM_TAB; | |
| 921 | + } | |
| 922 | + } | |
| 923 | + | |
| 924 | + s->version = 0; | |
| 925 | + | |
| 926 | + ret = ff_ffv1_encode_init(avctx); | |
| 927 | + if (ret < 0) | |
| 928 | + return ret; | |
| 929 | + | |
| 911 | 930 | #define STATS_OUT_SIZE 1024 * 1024 * 6 |
| 912 | 931 | if (avctx->flags & AV_CODEC_FLAG_PASS1) { |
| 913 | 932 | avctx->stats_out = av_mallocz(STATS_OUT_SIZE); |
| 914 | 933 | if (!avctx->stats_out) |
| 915 | 934 | return AVERROR(ENOMEM); |
| 916 | − for (i = 0; i < s->quant_table_count; i++) | |
| 917 | − for (j = 0; j < s->max_slice_count; j++) { | |
| 935 | + for (int i = 0; i < s->quant_table_count; i++) | |
| 936 | + for (int j = 0; j < s->max_slice_count; j++) { | |
| 918 | 937 | FFV1SliceContext *sc = &s->slices[j]; |
| 919 | 938 | av_assert0(!sc->rc_stat2[i]); |
| 920 | 939 | sc->rc_stat2[i] = av_mallocz(s->context_count[i] * |
| @@ -1321,7 +1340,7 @@ const FFCodec ff_ffv1_encoder = { · 400 unmodified lines | ||
| 1321 | 1340 | AV_CODEC_CAP_SLICE_THREADS | |
| 1322 | 1341 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, |
| 1323 | 1342 | .priv_data_size = sizeof(FFV1Context), |
| 1324 | − .init = encode_init, | |
| 1343 | + .init = encode_init_internal, | |
| 1325 | 1344 | FF_CODEC_ENCODE_CB(encode_frame), |
| 1326 | 1345 | .close = ff_ffv1_close, |
| 1327 | 1346 | .p.pix_fmts = (const enum AVPixelFormat[]) { |
| @@ -0,0 +1,30 @@ | ||
| 1 | +/* | |
| 2 | + * FFV1 encoder | |
| 3 | + * | |
| 4 | + * Copyright (c) 2003-2013 Michael Niedermayer <michaelni@gmx.at> | |
| 5 | + * | |
| 6 | + * This file is part of FFmpeg. | |
| 7 | + * | |
| 8 | + * FFmpeg is free software; you can redistribute it and/or | |
| 9 | + * modify it under the terms of the GNU Lesser General Public | |
| 10 | + * License as published by the Free Software Foundation; either | |
| 11 | + * version 2.1 of the License, or (at your option) any later version. | |
| 12 | + * | |
| 13 | + * FFmpeg is distributed in the hope that it will be useful, | |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 16 | + * Lesser General Public License for more details. | |
| 17 | + * | |
| 18 | + * You should have received a copy of the GNU Lesser General Public | |
| 19 | + * License along with FFmpeg; if not, write to the Free Software | |
| 20 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 21 | + */ | |
| 22 | + | |
| 23 | +#ifndef AVCODEC_FFV1ENC_H | |
| 24 | +#define AVCODEC_FFV1ENC_H | |
| 25 | + | |
| 26 | +#include "avcodec.h" | |
| 27 | + | |
| 28 | +av_cold int ff_ffv1_encode_init(AVCodecContext *avctx); | |
| 29 | + | |
| 30 | +#endif /* AVCODEC_FFV1ENC_H */ | |