avconv: decouple configuring filtergraphs and setting input parameters

Currently, calling configure_filtergraph() will pull in the input
parameters from the corresponding decoder context. This has the
following disadvantages:
- the decoded frame is a more proper source for this information
- a filter accessing decoder data breaks proper layering

Add functions for explicitly sending the input stream parameters to a
filtergraph input - currently from a frame and a decoder. The decoder
one will be dropped in future commits after some more restructuring.
This commit is contained in:
Anton Khirnov
2016-05-23 14:09:08 +02:00
parent 398f015f07
commit 722ec3eb35
4 changed files with 122 additions and 16 deletions

View File

@ -147,6 +147,7 @@ static void avconv_cleanup(int ret)
FilterGraph *fg = filtergraphs[i];
avfilter_graph_free(&fg->graph);
for (j = 0; j < fg->nb_inputs; j++) {
av_buffer_unref(&fg->inputs[j]->hw_frames_ctx);
av_freep(&fg->inputs[j]->name);
av_freep(&fg->inputs[j]);
}
@ -1252,6 +1253,16 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
ist->resample_channel_layout = decoded_frame->channel_layout;
ist->resample_channels = avctx->channels;
for (i = 0; i < ist->nb_filters; i++) {
err = ifilter_parameters_from_frame(ist->filters[i], decoded_frame);
if (err < 0) {
av_log(NULL, AV_LOG_ERROR,
"Error reconfiguring input stream %d:%d filter %d\n",
ist->file_index, ist->st->index, i);
goto fail;
}
}
for (i = 0; i < nb_filtergraphs; i++)
if (ist_in_filtergraph(filtergraphs[i], ist) &&
configure_filtergraph(filtergraphs[i]) < 0) {
@ -1279,6 +1290,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
break;
}
fail:
av_frame_unref(ist->filter_frame);
av_frame_unref(decoded_frame);
return err < 0 ? err : ret;
@ -1336,6 +1348,16 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
ist->resample_height = decoded_frame->height;
ist->resample_pix_fmt = decoded_frame->format;
for (i = 0; i < ist->nb_filters; i++) {
err = ifilter_parameters_from_frame(ist->filters[i], decoded_frame);
if (err < 0) {
av_log(NULL, AV_LOG_ERROR,
"Error reconfiguring input stream %d:%d filter %d\n",
ist->file_index, ist->st->index, i);
goto fail;
}
}
for (i = 0; i < nb_filtergraphs; i++)
if (ist_in_filtergraph(filtergraphs[i], ist) &&
configure_filtergraph(filtergraphs[i]) < 0) {
@ -2061,6 +2083,14 @@ static int transcode_init(void)
enc_ctx->codec_type == AVMEDIA_TYPE_AUDIO) &&
filtergraph_is_simple(ost->filter->graph)) {
FilterGraph *fg = ost->filter->graph;
ret = ifilter_parameters_from_decoder(fg->inputs[0],
dec_ctx);
if (ret < 0) {
av_log(NULL, AV_LOG_FATAL, "Error initializing filter input\n");
exit_program(1);
}
if (configure_filtergraph(fg)) {
av_log(NULL, AV_LOG_FATAL, "Error opening filters!\n");
exit_program(1);