MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / encode_frame

Function encode_frame

fftools/ffmpeg_enc.c:611–732  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

609}
610
611static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame,
612 AVPacket *pkt)
613{
614 Encoder *e = ost->enc;
615 EncoderPriv *ep = ep_from_enc(e);
616 AVCodecContext *enc = e->enc_ctx;
617 const char *type_desc = av_get_media_type_string(enc->codec_type);
618 const char *action = frame ? "encode" : "flush";
619 int ret;
620
621 if (frame) {
622 FrameData *fd = frame_data(frame);
623
624 if (!fd)
625 return AVERROR(ENOMEM);
626
627 fd->wallclock[LATENCY_PROBE_ENC_PRE] = av_gettime_relative();
628
629 if (ost->enc_stats_pre.io)
630 enc_stats_write(ost, &ost->enc_stats_pre, frame, NULL,
631 e->frames_encoded);
632
633 e->frames_encoded++;
634 e->samples_encoded += frame->nb_samples;
635
636 if (debug_ts) {
637 av_log(e, AV_LOG_INFO, "encoder <- type:%s "
638 "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
639 type_desc,
640 av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base),
641 enc->time_base.num, enc->time_base.den);
642 }
643
644 if (frame->sample_aspect_ratio.num && !ost->frame_aspect_ratio.num)
645 enc->sample_aspect_ratio = frame->sample_aspect_ratio;
646 }
647
648 update_benchmark(NULL);
649
650 ret = avcodec_send_frame(enc, frame);
651 if (ret < 0 && !(ret == AVERROR_EOF && !frame)) {
652 av_log(e, AV_LOG_ERROR, "Error submitting %s frame to the encoder\n",
653 type_desc);
654 return ret;
655 }
656
657 while (1) {
658 FrameData *fd;
659
660 av_packet_unref(pkt);
661
662 ret = avcodec_receive_packet(enc, pkt);
663 update_benchmark("%s_%s %d.%d", action, type_desc,
664 of->index, ost->index);
665
666 pkt->time_base = enc->time_base;
667
668 /* if two pass, output log on success and EOF */

Callers 1

frame_encodeFunction · 0.70

Calls 15

ep_from_encFunction · 0.85
av_get_media_type_stringFunction · 0.85
frame_dataFunction · 0.85
av_gettime_relativeFunction · 0.85
enc_stats_writeFunction · 0.85
av_logFunction · 0.85
update_benchmarkFunction · 0.85
avcodec_send_frameFunction · 0.85
av_packet_unrefFunction · 0.85
avcodec_receive_packetFunction · 0.85
packet_dataFunction · 0.85
avcodec_parameters_freeFunction · 0.85

Tested by

no test coverage detected