Lines Matching refs:avctx

35 int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
38 av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
45 av_fast_padded_malloc(&avctx->internal->byte_buffer,
46 &avctx->internal->byte_buffer_size, size);
47 avpkt->data = avctx->internal->byte_buffer;
49 av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
57 int avcodec_default_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int flags)
65 av_log(avctx, AV_LOG_ERROR, "avpkt->{data,buf} != NULL in avcodec_default_get_encode_buffer()\n");
71 av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %d\n", avpkt->size);
79 int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
89 ret = avctx->get_encode_buffer(avctx, avpkt, flags);
94 av_log(avctx, AV_LOG_ERROR, "No buffer returned by get_encode_buffer()\n");
103 av_log(avctx, AV_LOG_ERROR, "get_encode_buffer() failed\n");
146 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
151 av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
155 ret = ffcodec(avctx->codec)->cb.encode_sub(avctx, buf, buf_size, sub);
156 avctx->frame_number++;
160 int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
162 AVCodecInternal *avci = avctx->internal;
175 static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
177 AVCodecInternal *avci = avctx->internal;
179 const FFCodec *const codec = ffcodec(avctx->codec);
188 ret = ff_encode_get_frame(avctx, frame);
194 if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
195 (avci->frame_thread_encoder && avctx->active_thread_type & FF_THREAD_FRAME)))
207 avci->frame_thread_encoder && (avctx->active_thread_type & FF_THREAD_FRAME))
212 ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
214 ret = codec->cb.encode(avctx, avpkt, frame, &got_packet);
215 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO && !ret && got_packet &&
216 !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
231 if (frame && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
232 if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
236 avpkt->duration = ff_samples_to_time_base(avctx,
240 if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
264 static int encode_simple_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
269 ret = encode_simple_internal(avctx, avpkt);
277 static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt)
279 AVCodecInternal *avci = avctx->internal;
287 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
288 if ((avctx->flags & AV_CODEC_FLAG_PASS1) && avctx->stats_out)
289 avctx->stats_out[0] = '\0';
290 if (av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
294 if (ffcodec(avctx->codec)->cb_type == FF_CODEC_CB_TYPE_RECEIVE_PACKET) {
295 ret = ffcodec(avctx->codec)->cb.receive_packet(avctx, avpkt);
303 ret = encode_simple_receive_packet(avctx, avpkt);
311 static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src)
313 AVCodecInternal *avci = avctx->internal;
317 if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
321 avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
324 if (avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME) {
325 if (src->nb_samples > avctx->frame_size) {
326 av_log(avctx, AV_LOG_ERROR, "more samples than frame size\n");
329 } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
331 if (avctx->internal->last_audio_frame) {
332 av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected for a non-last frame\n", avctx->frame_size);
336 if (src->nb_samples < avctx->frame_size) {
337 ret = pad_last_frame(avctx, dst, src);
341 avctx->internal->last_audio_frame = 1;
343 } else if (src->nb_samples > avctx->frame_size) {
344 av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d)\n", src->nb_samples, avctx->frame_size);
357 int attribute_align_arg avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
359 AVCodecInternal *avci = avctx->internal;
362 if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
374 ret = encode_send_frame_internal(avctx, frame);
380 ret = encode_receive_packet_internal(avctx, avci->buffer_pkt);
385 avctx->frame_number++;
390 int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
392 AVCodecInternal *avci = avctx->internal;
397 if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
403 ret = encode_receive_packet_internal(avctx, avpkt);
411 static int encode_preinit_video(AVCodecContext *avctx)
413 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
416 if (avctx->codec->pix_fmts) {
417 for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
418 if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
420 if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) {
422 snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt);
423 av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n",
424 (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf));
427 if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
428 avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
429 avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
430 avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
431 avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
432 avctx->color_range = AVCOL_RANGE_JPEG;
435 if ( avctx->bits_per_raw_sample < 0
436 || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) {
437 av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n",
438 avctx->bits_per_raw_sample, pixdesc->comp[0].depth);
439 avctx->bits_per_raw_sample = pixdesc->comp[0].depth;
441 if (avctx->width <= 0 || avctx->height <= 0) {
442 av_log(avctx, AV_LOG_ERROR, "dimensions not set\n");
446 if (avctx->ticks_per_frame && avctx->time_base.num &&
447 avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
448 av_log(avctx, AV_LOG_ERROR,
450 avctx->ticks_per_frame,
451 avctx->time_base.num,
452 avctx->time_base.den);
456 if (avctx->hw_frames_ctx) {
457 AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
458 if (frames_ctx->format != avctx->pix_fmt) {
459 av_log(avctx, AV_LOG_ERROR,
463 if (avctx->sw_pix_fmt != AV_PIX_FMT_NONE &&
464 avctx->sw_pix_fmt != frames_ctx->sw_format) {
465 av_log(avctx, AV_LOG_ERROR,
468 av_get_pix_fmt_name(avctx->sw_pix_fmt),
472 avctx->sw_pix_fmt = frames_ctx->sw_format;
478 static int encode_preinit_audio(AVCodecContext *avctx)
482 if (avctx->codec->sample_fmts) {
483 for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
484 if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
486 if (avctx->ch_layout.nb_channels == 1 &&
487 av_get_planar_sample_fmt(avctx->sample_fmt) ==
488 av_get_planar_sample_fmt(avctx->codec->sample_fmts[i])) {
489 avctx->sample_fmt = avctx->codec->sample_fmts[i];
493 if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
495 snprintf(buf, sizeof(buf), "%d", avctx->sample_fmt);
496 av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is invalid or not supported\n",
497 (char *)av_x_if_null(av_get_sample_fmt_name(avctx->sample_fmt), buf));
501 if (avctx->codec->supported_samplerates) {
502 for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
503 if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
505 if (avctx->codec->supported_samplerates[i] == 0) {
506 av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
507 avctx->sample_rate);
511 if (avctx->sample_rate < 0) {
512 av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
513 avctx->sample_rate);
516 if (avctx->codec->ch_layouts) {
517 if (!av_channel_layout_check(&avctx->ch_layout)) {
518 av_log(avctx, AV_LOG_WARNING, "Channel layout not specified correctly\n");
522 for (i = 0; avctx->codec->ch_layouts[i].nb_channels; i++) {
523 if (!av_channel_layout_compare(&avctx->ch_layout, &avctx->codec->ch_layouts[i]))
526 if (!avctx->codec->ch_layouts[i].nb_channels) {
528 int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
530 av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
536 if (avctx->channel_layout && avctx->channels) {
537 int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
538 if (channels != avctx->channels) {
540 av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
541 av_log(avctx, AV_LOG_ERROR,
543 buf, channels, avctx->channels);
546 } else if (avctx->channel_layout) {
547 avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
549 if (avctx->channels < 0) {
550 av_log(avctx, AV_LOG_ERROR, "Specified number of channels %d is not supported\n",
551 avctx->channels);
557 if (!avctx->bits_per_raw_sample)
558 avctx->bits_per_raw_sample = 8 * av_get_bytes_per_sample(avctx->sample_fmt);
563 int ff_encode_preinit(AVCodecContext *avctx)
565 AVCodecInternal *avci = avctx->internal;
568 if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) {
569 av_log(avctx, AV_LOG_ERROR, "The encoder timebase is not set.\n");
573 switch (avctx->codec_type) {
574 case AVMEDIA_TYPE_VIDEO: ret = encode_preinit_video(avctx); break;
575 case AVMEDIA_TYPE_AUDIO: ret = encode_preinit_audio(avctx); break;
580 if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
581 && avctx->bit_rate>0 && avctx->bit_rate<1000) {
582 av_log(avctx, AV_LOG_WARNING, "Bitrate %"PRId64" is extremely low, maybe you mean %"PRId64"k\n", avctx->bit_rate, avctx->bit_rate);
585 if (!avctx->rc_initial_buffer_occupancy)
586 avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3LL / 4;
588 if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY)
589 avctx->internal->intra_only_flag = AV_PKT_FLAG_KEY;
591 if (ffcodec(avctx->codec)->cb_type == FF_CODEC_CB_TYPE_ENCODE) {
600 int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
604 switch (avctx->codec->type) {
606 frame->format = avctx->pix_fmt;
608 frame->width = FFMAX(avctx->width, avctx->coded_width);
609 frame->height = FFMAX(avctx->height, avctx->coded_height);
614 frame->sample_rate = avctx->sample_rate;
615 frame->format = avctx->sample_fmt;
617 ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
624 ret = avcodec_default_get_buffer2(avctx, frame, 0);
626 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");