fftools/ffmpeg: rework initializing encoders with no frames

When no frames were passed from a filtergraph to an encoder, but the
filtergraph is configured (i.e. has output parameters), encoder flush
code will use those parameters to initialize the encoder in a last-ditch
effort to produce some useful output.

Rework this process so that it is triggered by the filtergraph, which
now sends a dummy frame with parameters, but no data, to the encoder,
rather than the encoder reaching backwards into the filter.

This approach is more in line with the natural data flow from filters to
encoders and will allow to reduce encoder-filter interactions in
following commits.

This code is tested by fate-adpcm-ima-cunning-trunc-t2-track1, which (as
confirmed by Zane) is supposed to produce empty output.
This commit is contained in:
Anton Khirnov
2023-07-06 21:31:49 +02:00
parent 20c42213ea
commit 0a6751a78a
2 changed files with 52 additions and 24 deletions

View File

@@ -1142,26 +1142,8 @@ void enc_flush(void)
AVCodecContext *enc = ost->enc_ctx;
OutputFile *of = output_files[ost->file_index];
if (!enc)
continue;
// Try to enable encoding with no input frames.
// Maybe we should just let encoding fail instead.
if (!e->opened) {
FilterGraph *fg = ost->filter->graph;
av_log(ost, AV_LOG_WARNING,
"Finishing stream without any data written to it.\n");
if (!fg->graph)
continue;
ret = enc_open(ost, NULL);
if (ret < 0)
exit_program(1);
}
if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO)
if (!enc || !e->opened ||
(enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO))
continue;
ret = submit_encode_frame(of, ost, NULL);