return ret;
}
- if (ist->framerate.num) {
- AVFilterContext *setpts;
-
- snprintf(name, sizeof(name), "forcecfr_in_%d_%d",
- ist->file_index, ist->st->index);
- if ((ret = avfilter_graph_create_filter(&setpts,
- avfilter_get_by_name("setpts"),
- name, "N", NULL,
- fg->graph)) < 0)
- return ret;
-
- if ((ret = avfilter_link(last_filter, 0, setpts, 0)) < 0)
- return ret;
-
- last_filter = setpts;
- }
-
if (do_deinterlace) {
AVFilterContext *yadif;
}
}
+static void cleanup_filtergraph(FilterGraph *fg)
+{
+ int i;
+ for (i = 0; i < fg->nb_outputs; i++)
+ fg->outputs[i]->filter = (AVFilterContext *)NULL;
+ for (i = 0; i < fg->nb_inputs; i++)
+ fg->inputs[i]->filter = (AVFilterContext *)NULL;
+ avfilter_graph_free(&fg->graph);
+}
+
int configure_filtergraph(FilterGraph *fg)
{
AVFilterInOut *inputs, *outputs, *cur;
const char *graph_desc = simple ? fg->outputs[0]->ost->avfilter :
fg->graph_desc;
- avfilter_graph_free(&fg->graph);
+ cleanup_filtergraph(fg);
if (!(fg->graph = avfilter_graph_alloc()))
return AVERROR(ENOMEM);
}
if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
- return ret;
+ goto fail;
if (hw_device_ctx) {
for (i = 0; i < fg->graph->nb_filters; i++) {
" However, it had %s input(s) and %s output(s)."
" Please adjust, or use a complex filtergraph (-filter_complex) instead.\n",
graph_desc, num_inputs, num_outputs);
- return AVERROR(EINVAL);
+ ret = AVERROR(EINVAL);
+ goto fail;
}
for (cur = inputs, i = 0; cur; cur = cur->next, i++)
if ((ret = configure_input_filter(fg, fg->inputs[i], cur)) < 0) {
avfilter_inout_free(&inputs);
avfilter_inout_free(&outputs);
- return ret;
+ goto fail;
}
avfilter_inout_free(&inputs);
avfilter_inout_free(&outputs);
if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0)
- return ret;
+ goto fail;
/* limit the lists of allowed formats to the ones selected, to
* make sure they stay the same if the filtergraph is reconfigured later */
complex filter graphs are initialized earlier */
av_log(NULL, AV_LOG_ERROR, "Encoder (codec %s) not found for output stream #%d:%d\n",
avcodec_get_name(ost->st->codecpar->codec_id), ost->file_index, ost->index);
- return AVERROR(EINVAL);
+ ret = AVERROR(EINVAL);
+ goto fail;
}
if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
!(ost->enc->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE))
ret = av_buffersrc_add_frame(fg->inputs[i]->filter, tmp);
av_frame_free(&tmp);
if (ret < 0)
- return ret;
+ goto fail;
+ }
+ }
+
+ /* send the EOFs for the finished inputs */
+ for (i = 0; i < fg->nb_inputs; i++) {
+ if (fg->inputs[i]->eof) {
+ ret = av_buffersrc_add_frame(fg->inputs[i]->filter, NULL);
+ if (ret < 0)
+ goto fail;
+ }
+ }
+
+ /* process queued up subtitle packets */
+ for (i = 0; i < fg->nb_inputs; i++) {
+ InputStream *ist = fg->inputs[i]->ist;
+ if (ist->sub2video.sub_queue && ist->sub2video.frame) {
+ while (av_fifo_size(ist->sub2video.sub_queue)) {
+ AVSubtitle tmp;
+ av_fifo_generic_read(ist->sub2video.sub_queue, &tmp, sizeof(tmp), NULL);
+ sub2video_update(ist, &tmp);
+ avsubtitle_free(&tmp);
+ }
}
}
return 0;
+
+fail:
+ cleanup_filtergraph(fg);
+ return ret;
}
int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)