| 745 | } |
| 746 | |
| 747 | int ff_encode_preinit(AVCodecContext *avctx) |
| 748 | { |
| 749 | AVCodecInternal *avci = avctx->internal; |
| 750 | EncodeContext *ec = encode_ctx(avci); |
| 751 | int ret = 0; |
| 752 | |
| 753 | if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) { |
| 754 | av_log(avctx, AV_LOG_ERROR, "The encoder timebase is not set.\n"); |
| 755 | return AVERROR(EINVAL); |
| 756 | } |
| 757 | |
| 758 | if (avctx->bit_rate < 0) { |
| 759 | av_log(avctx, AV_LOG_ERROR, "The encoder bitrate is negative.\n"); |
| 760 | return AVERROR(EINVAL); |
| 761 | } |
| 762 | |
| 763 | if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE && |
| 764 | !(avctx->codec->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE)) { |
| 765 | av_log(avctx, AV_LOG_ERROR, "The copy_opaque flag is set, but the " |
| 766 | "encoder does not support it.\n"); |
| 767 | return AVERROR(EINVAL); |
| 768 | } |
| 769 | |
| 770 | switch (avctx->codec_type) { |
| 771 | case AVMEDIA_TYPE_VIDEO: ret = encode_preinit_video(avctx); break; |
| 772 | case AVMEDIA_TYPE_AUDIO: ret = encode_preinit_audio(avctx); break; |
| 773 | } |
| 774 | if (ret < 0) |
| 775 | return ret; |
| 776 | |
| 777 | if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO) |
| 778 | && avctx->bit_rate>0 && avctx->bit_rate<1000) { |
| 779 | av_log(avctx, AV_LOG_WARNING, "Bitrate %"PRId64" is extremely low, maybe you mean %"PRId64"k\n", avctx->bit_rate, avctx->bit_rate); |
| 780 | } |
| 781 | |
| 782 | if (!avctx->rc_initial_buffer_occupancy) |
| 783 | avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3LL / 4; |
| 784 | |
| 785 | if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) |
| 786 | ec->intra_only_flag = AV_PKT_FLAG_KEY; |
| 787 | |
| 788 | if (ffcodec(avctx->codec)->cb_type == FF_CODEC_CB_TYPE_ENCODE) { |
| 789 | avci->in_frame = av_frame_alloc(); |
| 790 | if (!avci->in_frame) |
| 791 | return AVERROR(ENOMEM); |
| 792 | } |
| 793 | |
| 794 | if ((avctx->flags & AV_CODEC_FLAG_RECON_FRAME)) { |
| 795 | if (!(avctx->codec->capabilities & AV_CODEC_CAP_ENCODER_RECON_FRAME)) { |
| 796 | av_log(avctx, AV_LOG_ERROR, "Reconstructed frame output requested " |
| 797 | "from an encoder not supporting it\n"); |
| 798 | return AVERROR(ENOSYS); |
| 799 | } |
| 800 | |
| 801 | avci->recon_frame = av_frame_alloc(); |
| 802 | if (!avci->recon_frame) |
| 803 | return AVERROR(ENOMEM); |
| 804 | } |
no test coverage detected