| 609 | } |
| 610 | |
| 611 | static 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 */ |
no test coverage detected