Lines Matching defs:avctx

186         av_log(s->avctx, AV_LOG_INFO,
201 if (ff_mpeg2_non_linear_qscale[i] < s->avctx->qmin ||
202 (ff_mpeg2_non_linear_qscale[i] > s->avctx->qmax && !s->vbv_ignore_qmax))
213 s->qscale = av_clip(s->qscale, s->avctx->qmin, s->vbv_ignore_qmax ? 31 : s->avctx->qmax);
244 qscale_table[s->mb_index2xy[i]] = av_clip(qp, s->avctx->qmin,
245 s->avctx->qmax);
304 if (s->avctx->trellis)
311 av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
313 MpegEncContext *s = avctx->priv_data;
319 switch (avctx->pix_fmt) {
335 avctx->bits_per_raw_sample = av_clip(avctx->bits_per_raw_sample, 0, 8);
337 s->bit_rate = avctx->bit_rate;
338 s->width = avctx->width;
339 s->height = avctx->height;
340 if (avctx->gop_size > 600 &&
341 avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
342 av_log(avctx, AV_LOG_WARNING,
344 avctx->gop_size, 600);
345 avctx->gop_size = 600;
347 s->gop_size = avctx->gop_size;
348 s->avctx = avctx;
349 if (avctx->max_b_frames > MAX_B_FRAMES) {
350 av_log(avctx, AV_LOG_ERROR, "Too many B-frames requested, maximum "
352 avctx->max_b_frames = MAX_B_FRAMES;
353 } else if (avctx->max_b_frames < 0) {
354 av_log(avctx, AV_LOG_ERROR,
358 s->max_b_frames = avctx->max_b_frames;
359 s->codec_id = avctx->codec->id;
360 if (s->max_b_frames && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
361 av_log(avctx, AV_LOG_ERROR, "B-frames not supported by codec\n");
365 s->quarter_sample = (avctx->flags & AV_CODEC_FLAG_QPEL) != 0;
367 s->intra_dc_precision = avctx->intra_dc_precision;
376 av_log(avctx, AV_LOG_ERROR,
382 if (s->intra_dc_precision > (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 3 : 0)) {
383 av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n");
396 s->fixed_qscale = !!(avctx->flags & AV_CODEC_FLAG_QSCALE);
398 s->adaptive_quant = (avctx->lumi_masking ||
399 avctx->dark_masking ||
400 avctx->temporal_cplx_masking ||
401 avctx->spatial_cplx_masking ||
402 avctx->p_masking ||
407 s->loop_filter = !!(avctx->flags & AV_CODEC_FLAG_LOOP_FILTER);
409 if (avctx->rc_max_rate && !avctx->rc_buffer_size) {
410 switch(avctx->codec_id) {
413 avctx->rc_buffer_size = FFMAX(avctx->rc_max_rate, 15000000) * 112LL / 15000000 * 16384;
419 if (avctx->rc_max_rate >= 15000000) {
420 avctx->rc_buffer_size = 320 + (avctx->rc_max_rate - 15000000LL) * (760-320) / (38400000 - 15000000);
421 } else if(avctx->rc_max_rate >= 2000000) {
422 avctx->rc_buffer_size = 80 + (avctx->rc_max_rate - 2000000LL) * (320- 80) / (15000000 - 2000000);
423 } else if(avctx->rc_max_rate >= 384000) {
424 avctx->rc_buffer_size = 40 + (avctx->rc_max_rate - 384000LL) * ( 80- 40) / ( 2000000 - 384000);
426 avctx->rc_buffer_size = 40;
427 avctx->rc_buffer_size *= 16384;
430 if (avctx->rc_buffer_size) {
431 av_log(avctx, AV_LOG_INFO, "Automatically choosing VBV buffer size of %d kbyte\n", avctx->rc_buffer_size/8192);
435 if ((!avctx->rc_max_rate) != (!avctx->rc_buffer_size)) {
436 av_log(avctx, AV_LOG_ERROR, "Either both buffer size and max rate or neither must be specified\n");
440 if (avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate) {
441 av_log(avctx, AV_LOG_INFO,
445 if (avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate) {
446 av_log(avctx, AV_LOG_ERROR, "bitrate below min bitrate\n");
450 if (avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate) {
451 av_log(avctx, AV_LOG_ERROR, "bitrate above max bitrate\n");
455 if (avctx->rc_max_rate &&
456 avctx->rc_max_rate == avctx->bit_rate &&
457 avctx->rc_max_rate != avctx->rc_min_rate) {
458 av_log(avctx, AV_LOG_INFO,
462 if (avctx->rc_buffer_size &&
463 avctx->bit_rate * (int64_t)avctx->time_base.num >
464 avctx->rc_buffer_size * (int64_t)avctx->time_base.den) {
465 av_log(avctx, AV_LOG_ERROR, "VBV buffer too small for bitrate\n");
470 avctx->bit_rate * av_q2d(avctx->time_base) >
471 avctx->bit_rate_tolerance) {
472 double nbt = avctx->bit_rate * av_q2d(avctx->time_base) * 5;
473 av_log(avctx, AV_LOG_WARNING,
474 "bitrate tolerance %d too small for bitrate %"PRId64", overriding\n", avctx->bit_rate_tolerance, avctx->bit_rate);
476 avctx->bit_rate_tolerance = nbt;
478 avctx->bit_rate_tolerance = INT_MAX;
481 if (avctx->rc_max_rate &&
482 avctx->rc_min_rate == avctx->rc_max_rate &&
485 90000LL * (avctx->rc_buffer_size - 1) >
486 avctx->rc_max_rate * 0xFFFFLL) {
487 av_log(avctx, AV_LOG_INFO,
492 if ((avctx->flags & AV_CODEC_FLAG_4MV) && s->codec_id != AV_CODEC_ID_MPEG4 &&
495 av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n");
499 if (s->obmc && avctx->mb_decision != FF_MB_DECISION_SIMPLE) {
500 av_log(avctx, AV_LOG_ERROR,
506 av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n");
513 (avctx->sample_aspect_ratio.num > 255 ||
514 avctx->sample_aspect_ratio.den > 255)) {
515 av_log(avctx, AV_LOG_WARNING,
517 avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den);
518 av_reduce(&avctx->sample_aspect_ratio.num, &avctx->sample_aspect_ratio.den,
519 avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 255);
524 (avctx->width > 2048 ||
525 avctx->height > 1152 )) {
526 av_log(avctx, AV_LOG_ERROR, "H.263 does not support resolutions above 2048x1152\n");
532 ((avctx->width &3) ||
533 (avctx->height&3) )) {
534 av_log(avctx, AV_LOG_ERROR, "width and height must be a multiple of 4\n");
539 (avctx->width &15 ||
540 avctx->height&15 )) {
541 av_log(avctx, AV_LOG_ERROR, "width and height must be a multiple of 16\n");
547 avctx->width & 1) {
548 av_log(avctx, AV_LOG_ERROR, "width must be multiple of 2\n");
552 if ((avctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME)) &&
554 av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n");
558 if ((s->mpv_flags & FF_MPV_FLAG_CBP_RD) && !avctx->trellis) {
559 av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
564 avctx->mb_decision != FF_MB_DECISION_RD) {
565 av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
570 (avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)) {
571 av_log(avctx, AV_LOG_ERROR,
577 if (avctx->flags & AV_CODEC_FLAG_LOW_DELAY) {
579 avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) {
580 av_log(avctx, AV_LOG_ERROR,
586 av_log(avctx, AV_LOG_ERROR,
593 if (avctx->qmax > 28) {
594 av_log(avctx, AV_LOG_ERROR,
600 if (avctx->slices > 1 &&
601 !(avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS)) {
602 av_log(avctx, AV_LOG_ERROR, "Multiple slices are not supported by this codec\n");
606 if (s->b_frame_strategy && (avctx->flags & AV_CODEC_FLAG_PASS2)) {
607 av_log(avctx, AV_LOG_INFO,
612 i = av_gcd(avctx->time_base.den, avctx->time_base.num);
614 av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n");
615 avctx->time_base.den /= i;
616 avctx->time_base.num /= i;
630 if (avctx->qmin > avctx->qmax || avctx->qmin <= 0) {
631 av_log(avctx, AV_LOG_ERROR, "qmin and or qmax are invalid, they must be 0 < min <= max\n");
635 av_log(avctx, AV_LOG_DEBUG, "intra_quant_bias = %d inter_quant_bias = %d\n",s->intra_quant_bias,s->inter_quant_bias);
637 if (avctx->codec_id == AV_CODEC_ID_MPEG4 &&
638 avctx->time_base.den > (1 << 16) - 1) {
639 av_log(avctx, AV_LOG_ERROR,
642 "is %d\n", avctx->time_base.num, avctx->time_base.den,
646 s->time_increment_bits = av_log2(avctx->time_base.den - 1) + 1;
648 switch (avctx->codec->id) {
651 s->low_delay = !!(avctx->flags & AV_CODEC_FLAG_LOW_DELAY);
652 avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1);
656 s->low_delay = !!(avctx->flags & AV_CODEC_FLAG_LOW_DELAY);
657 avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1);
667 avctx->delay = 0;
678 avctx->delay = 0;
685 av_log(avctx, AV_LOG_ERROR,
692 avctx->delay = 0;
701 av_log(avctx, AV_LOG_ERROR,
709 avctx->delay = 0;
716 s->h263_aic = (avctx->flags & AV_CODEC_FLAG_AC_PRED) ? 1 : 0;
718 s->loop_filter = (avctx->flags & AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0;
723 avctx->delay = 0;
731 avctx->delay = 0;
736 avctx->delay = 0;
741 avctx->delay = 0;
754 avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1);
761 avctx->delay = 0;
770 avctx->delay = 0;
779 avctx->delay = 0;
788 avctx->delay = 0;
795 avctx->has_b_frames = !s->low_delay;
800 s->progressive_sequence = !(avctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT |
809 ff_fdctdsp_init(&s->fdsp, avctx);
810 ff_me_cmp_init(&s->mecc, avctx);
811 ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);
812 ff_pixblockdsp_init(&s->pdsp, avctx);
815 if (!(avctx->stats_out = av_mallocz(256)) ||
839 if (avctx->codec_id == AV_CODEC_ID_H263P)
845 ret = ff_set_cmp(&s->mecc, s->mecc.ildct_cmp, avctx->ildct_cmp);
880 if (avctx->intra_matrix)
881 s->intra_matrix[j] = avctx->intra_matrix[i];
882 if (avctx->inter_matrix)
883 s->inter_matrix[j] = avctx->inter_matrix[i];
890 s->intra_matrix, s->intra_quant_bias, avctx->qmin,
893 s->inter_matrix, s->inter_quant_bias, avctx->qmin,
916 cpb_props = ff_add_cpb_side_data(avctx);
919 cpb_props->max_bitrate = avctx->rc_max_rate;
920 cpb_props->min_bitrate = avctx->rc_min_rate;
921 cpb_props->avg_bitrate = avctx->bit_rate;
922 cpb_props->buffer_size = avctx->rc_buffer_size;
927 av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
929 MpegEncContext *s = avctx->priv_data;
941 av_freep(&avctx->stats_out);
997 return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, shared, 1,
1022 av_log(s->avctx, AV_LOG_ERROR,
1036 av_log(s->avctx, AV_LOG_INFO,
1056 ff_dlog(s->avctx, "%d %d %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"\n", pic_arg->linesize[0],
1059 i = ff_find_unused_picture(s->avctx, s->picture, direct);
1081 av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
1101 if (!s->avctx->rc_buffer_size)
1236 //p_lambda * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset;
1292 c->flags |= s->avctx->flags & AV_CODEC_FLAG_QPEL;
1293 c->mb_decision = s->avctx->mb_decision;
1294 c->me_cmp = s->avctx->me_cmp;
1295 c->mb_cmp = s->avctx->mb_cmp;
1296 c->me_sub_cmp = s->avctx->me_sub_cmp;
1298 c->time_base = s->avctx->time_base;
1301 ret = avcodec_open2(c, s->avctx->codec, NULL);
1394 if (s->avctx->flags & AV_CODEC_FLAG_PASS2) {
1453 av_log(s->avctx, AV_LOG_ERROR,
1462 if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)
1468 if ((s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && b_frames &&
1498 if (s->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) {
1503 int i = ff_find_unused_picture(s->avctx, s->picture, 0);
1540 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
1601 ff_mpeg_unref_picture(s->avctx, s->last_picture_ptr);
1607 ff_mpeg_unref_picture(s->avctx, &s->current_picture);
1608 if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture,
1618 ff_mpeg_unref_picture(s->avctx, &s->last_picture);
1620 (ret = ff_mpeg_ref_picture(s->avctx, &s->last_picture,
1625 ff_mpeg_unref_picture(s->avctx, &s->next_picture);
1627 (ret = ff_mpeg_ref_picture(s->avctx, &s->next_picture,
1664 int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
1667 MpegEncContext *s = avctx->priv_data;
1687 if (CONFIG_MJPEG_ENCODER && avctx->codec_id == AV_CODEC_ID_MJPEG) {
1688 ret = ff_mjpeg_add_icc_profile_size(avctx, s->new_picture, &pkt_size);
1692 if ((ret = ff_alloc_packet(avctx, pkt, pkt_size)) < 0)
1694 pkt->size = avctx->internal->byte_buffer_size - AV_INPUT_BUFFER_PADDING_SIZE;
1720 av_assert0(s->pb.buf == avctx->internal->byte_buffer);
1722 pkt->size = avctx->internal->byte_buffer_size;
1732 if (avctx->rc_buffer_size) {
1734 int max_size = FFMAX(rcc->buffer_index * avctx->rc_max_available_vbv_use, rcc->buffer_index - 500);
1735 int hq = (avctx->mb_decision == FF_MB_DECISION_RD || avctx->trellis);
1767 av_log(avctx, AV_LOG_VERBOSE, "reencoding frame due to VBV\n");
1771 av_assert0(avctx->rc_max_rate);
1774 if (avctx->flags & AV_CODEC_FLAG_PASS1)
1779 avctx->error[i] += s->current_picture_ptr->encoding_error[i];
1783 (avctx->flags&AV_CODEC_FLAG_PSNR) ? MPEGVIDEO_MAX_PLANES : 0,
1786 if (avctx->flags & AV_CODEC_FLAG_PASS1)
1797 av_log(avctx, AV_LOG_ERROR, "stuffing too large\n");
1817 av_log(avctx, AV_LOG_ERROR, "vbv buffer overflow\n");
1825 if (avctx->rc_max_rate &&
1826 avctx->rc_min_rate == avctx->rc_max_rate &&
1828 90000LL * (avctx->rc_buffer_size - 1) <=
1829 avctx->rc_max_rate * 0xFFFFLL) {
1834 double inbits = avctx->rc_max_rate *
1835 av_q2d(avctx->time_base);
1842 av_log(avctx, AV_LOG_ERROR,
1847 vbv_delay = bits * 90000 / avctx->rc_max_rate;
1848 min_delay = (minbits * 90000LL + avctx->rc_max_rate - 1) /
1849 avctx->rc_max_rate;
1895 ff_mpeg_unref_picture(avctx, &s->picture[i]);
1989 if (overflow && s->avctx->mb_decision == FF_MB_DECISION_SIMPLE)
1990 av_log(s->avctx, AV_LOG_INFO,
2031 (s)->avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT)
2140 if (s->avctx->flags & AV_CODEC_FLAG_GRAY) {
2197 if (s->avctx->ildct_cmp == FF_CMP_VSSE)
2226 if (s->avctx->flags & AV_CODEC_FLAG_GRAY) {
2336 if ((s->avctx->flags & AV_CODEC_FLAG_GRAY) && s->mb_intra) {
2520 if(s->avctx->mb_decision == FF_MB_DECISION_RD){
2570 if(s->avctx->mb_cmp == FF_CMP_NSSE){
2599 s->me.dia_size= s->avctx->pre_dia_size;
2616 s->me.dia_size= s->avctx->dia_size;
2677 if ((s->avctx->flags & AV_CODEC_FLAG_PASS1) && !s->partitioned_frame)
2728 && s->pb.buf == s->avctx->internal->byte_buffer) {
2734 if ((s->avctx->internal->byte_buffer_size + size_increase) >= INT_MAX/8) {
2735 av_log(s->avctx, AV_LOG_ERROR, "Cannot reallocate putbit buffer\n");
2742 s->avctx->internal->byte_buffer_size + size_increase);
2746 memcpy(new_buffer, s->avctx->internal->byte_buffer, s->avctx->internal->byte_buffer_size);
2747 av_free(s->avctx->internal->byte_buffer);
2748 s->avctx->internal->byte_buffer = new_buffer;
2749 s->avctx->internal->byte_buffer_size = new_buffer_size;
2839 int size_increase = s->avctx->internal->byte_buffer_size/4
2844 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
2850 av_log(s->avctx, AV_LOG_ERROR, "encoded partitioned frame too large\n");
2939 if (s->avctx->flags & AV_CODEC_FLAG_PASS1) {
3123 if(qp < s->avctx->qmin || qp > s->avctx->qmax)
3230 if(s->avctx->mb_decision == FF_MB_DECISION_BITS)
3338 av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\n");
3359 if (s->avctx->flags & AV_CODEC_FLAG_PSNR) {
3380 ff_dlog(s->avctx, "MB %d %d bits\n",
3469 s->time = s->current_picture_ptr->f->pts * s->avctx->time_base.num;
3512 if (s->avctx->flags & AV_CODEC_FLAG_PASS2) {
3516 } else if (!(s->avctx->flags & AV_CODEC_FLAG_QSCALE)) {
3548 s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
3552 s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
3560 s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
3585 if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) {
3594 if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) {
3617 if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME) {
3638 !(s->avctx->flags & AV_CODEC_FLAG_QSCALE))
3645 if (s->avctx->intra_matrix) {
3647 luma_matrix = s->avctx->intra_matrix;
3649 if (s->avctx->chroma_intra_matrix)
3650 chroma_matrix = s->avctx->chroma_intra_matrix;
3752 s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));