From 60dade104033f04fdd64f400d3f6707cf16d0ed7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 29 Apr 2018 02:49:49 +0200 Subject: encode: restore 2-pass mode While I'm not sure whether it really works, at least it writes the pass1 log correctly now. How 2-pass stat output is supposed to interact with the new decode API is rather fishy. ffmpeg.c does the same, and before this change, the log was not written on EOF (when at least libvpx actually outputs its stats). --- common/encode_lavc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/encode_lavc.c b/common/encode_lavc.c index 6f8378ac7f..5d34af609b 100644 --- a/common/encode_lavc.c +++ b/common/encode_lavc.c @@ -820,6 +820,7 @@ static void encoder_2pass_prepare(struct encoder_context *p) stream_type_name(p->type)); if (p->encoder->flags & AV_CODEC_FLAG_PASS2) { + MP_INFO(p, "Reading 2-pass log: %s\n", filename); struct stream *s = stream_open(filename, p->global); if (s) { struct bstr content = stream_read_complete(s, p, 1000000000); @@ -838,6 +839,7 @@ static void encoder_2pass_prepare(struct encoder_context *p) } if (p->encoder->flags & AV_CODEC_FLAG_PASS1) { + MP_INFO(p, "Writing to 2-pass log: %s\n", filename); p->twopass_bytebuffer = open_output_stream(filename, p->global); if (!p->twopass_bytebuffer) { MP_WARN(p, "could not open '%s', " @@ -927,9 +929,9 @@ bool encoder_encode(struct encoder_context *p, AVFrame *frame) av_init_packet(&packet); status = avcodec_receive_packet(p->encoder, &packet); - if (status == AVERROR(EAGAIN) || status == AVERROR_EOF) + if (status == AVERROR(EAGAIN)) break; - if (status < 0) + if (status < 0 && status != AVERROR_EOF) goto fail; if (p->twopass_bytebuffer && p->encoder->stats_out) { @@ -937,6 +939,9 @@ bool encoder_encode(struct encoder_context *p, AVFrame *frame) strlen(p->encoder->stats_out)); } + if (status == AVERROR_EOF) + break; + encode_lavc_add_packet(p->mux_stream, &packet); av_packet_unref(&packet); } -- cgit v1.2.3