fftools/ffmpeg_filter: treat apad filter as a source

Ideally lavfi should have a dedicated API for detecting this.

Fixes #11168 and #11061
This commit is contained in:
Anton Khirnov 2024-10-12 19:08:55 +02:00
parent 79c47dfd25
commit 9e2a231236
1 changed files with 12 additions and 9 deletions

View File

@ -1104,8 +1104,9 @@ int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch)
for (unsigned i = 0; i < graph->nb_filters; i++) { for (unsigned i = 0; i < graph->nb_filters; i++) {
const AVFilter *f = graph->filters[i]->filter; const AVFilter *f = graph->filters[i]->filter;
if (!avfilter_filter_pad_count(f, 0) && if ((!avfilter_filter_pad_count(f, 0) &&
!(f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) { !(f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
!strcmp(f->name, "apad")) {
fgp->have_sources = 1; fgp->have_sources = 1;
break; break;
} }
@ -1502,7 +1503,7 @@ static int insert_filter(AVFilterContext **last_filter, int *pad_idx,
return 0; return 0;
} }
static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph, static int configure_output_video_filter(FilterGraphPriv *fgp, AVFilterGraph *graph,
OutputFilter *ofilter, AVFilterInOut *out) OutputFilter *ofilter, AVFilterInOut *out)
{ {
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
@ -1581,7 +1582,7 @@ static int configure_output_video_filter(FilterGraph *fg, AVFilterGraph *graph,
return 0; return 0;
} }
static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph, static int configure_output_audio_filter(FilterGraphPriv *fgp, AVFilterGraph *graph,
OutputFilter *ofilter, AVFilterInOut *out) OutputFilter *ofilter, AVFilterInOut *out)
{ {
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
@ -1644,8 +1645,10 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
pad_idx = 0; pad_idx = 0;
} }
if (ofilter->apad) if (ofilter->apad) {
AUTO_INSERT_FILTER("-apad", "apad", ofilter->apad); AUTO_INSERT_FILTER("-apad", "apad", ofilter->apad);
fgp->have_sources = 1;
}
snprintf(name, sizeof(name), "trim for output %s", ofp->name); snprintf(name, sizeof(name), "trim for output %s", ofp->name);
ret = insert_trim(ofp->trim_start_us, ofp->trim_duration_us, ret = insert_trim(ofp->trim_start_us, ofp->trim_duration_us,
@ -1661,12 +1664,12 @@ fail:
return ret; return ret;
} }
static int configure_output_filter(FilterGraph *fg, AVFilterGraph *graph, static int configure_output_filter(FilterGraphPriv *fgp, AVFilterGraph *graph,
OutputFilter *ofilter, AVFilterInOut *out) OutputFilter *ofilter, AVFilterInOut *out)
{ {
switch (ofilter->type) { switch (ofilter->type) {
case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, graph, ofilter, out); case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fgp, graph, ofilter, out);
case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, graph, ofilter, out); case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fgp, graph, ofilter, out);
default: av_assert0(0); return 0; default: av_assert0(0); return 0;
} }
} }
@ -1944,7 +1947,7 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt)
avfilter_inout_free(&inputs); avfilter_inout_free(&inputs);
for (cur = outputs, i = 0; cur; cur = cur->next, i++) { for (cur = outputs, i = 0; cur; cur = cur->next, i++) {
ret = configure_output_filter(fg, fgt->graph, fg->outputs[i], cur); ret = configure_output_filter(fgp, fgt->graph, fg->outputs[i], cur);
if (ret < 0) { if (ret < 0) {
avfilter_inout_free(&outputs); avfilter_inout_free(&outputs);
goto fail; goto fail;