fftools/ffmpeg_opt: merge init_complex_filters() and check_filter_outputs()
The first of these binds inputs of complex filtergraphs to demuxer streams (with a misleading comment claiming it *creates* complex filtergraphs). The second ensures that all filtergraph outputs are connected to an encoder. Merge them into a single function, which simplifies the ffmpeg_filter API, is shorter, and will also be useful in following commits. Also, rename misleadingly-named init_input_filter() to fg_complex_bind_input().
This commit is contained in:
@@ -671,12 +671,11 @@ int find_codec(void *logctx, const char *name,
|
|||||||
enum AVMediaType type, int encoder, const AVCodec **codec);
|
enum AVMediaType type, int encoder, const AVCodec **codec);
|
||||||
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
|
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
|
||||||
|
|
||||||
int check_filter_outputs(void);
|
|
||||||
int filtergraph_is_simple(const FilterGraph *fg);
|
int filtergraph_is_simple(const FilterGraph *fg);
|
||||||
int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
|
int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
|
||||||
char *graph_desc,
|
char *graph_desc,
|
||||||
Scheduler *sch, unsigned sch_idx_enc);
|
Scheduler *sch, unsigned sch_idx_enc);
|
||||||
int init_complex_filtergraph(FilterGraph *fg);
|
int fg_finalise_bindings(FilterGraph *fg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get our axiliary frame data attached to the frame, allocating it
|
* Get our axiliary frame data attached to the frame, allocating it
|
||||||
|
|||||||
@@ -1096,7 +1096,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init_input_filter(FilterGraph *fg, InputFilter *ifilter)
|
static int fg_complex_bind_input(FilterGraph *fg, InputFilter *ifilter)
|
||||||
{
|
{
|
||||||
FilterGraphPriv *fgp = fgp_from_fg(fg);
|
FilterGraphPriv *fgp = fgp_from_fg(fg);
|
||||||
InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
|
InputFilterPriv *ifp = ifp_from_ifilter(ifilter);
|
||||||
@@ -1162,14 +1162,29 @@ static int init_input_filter(FilterGraph *fg, InputFilter *ifilter)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_complex_filtergraph(FilterGraph *fg)
|
int fg_finalise_bindings(FilterGraph *fg)
|
||||||
{
|
{
|
||||||
// bind filtergraph inputs to input streams
|
// bind filtergraph inputs to input streams
|
||||||
for (int i = 0; i < fg->nb_inputs; i++) {
|
for (int i = 0; i < fg->nb_inputs; i++) {
|
||||||
int ret = init_input_filter(fg, fg->inputs[i]);
|
InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (ifp->bound)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ret = fg_complex_bind_input(fg, &ifp->ifilter);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < fg->nb_outputs; i++) {
|
||||||
|
OutputFilter *output = fg->outputs[i];
|
||||||
|
if (!output->ost) {
|
||||||
|
av_log(filtergraphs[i], AV_LOG_FATAL,
|
||||||
|
"Filter %s has an unconnected output\n", output->name);
|
||||||
|
return AVERROR(EINVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1436,23 +1451,6 @@ static int configure_output_filter(FilterGraph *fg, AVFilterGraph *graph,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_filter_outputs(void)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < nb_filtergraphs; i++) {
|
|
||||||
int n;
|
|
||||||
for (n = 0; n < filtergraphs[i]->nb_outputs; n++) {
|
|
||||||
OutputFilter *output = filtergraphs[i]->outputs[n];
|
|
||||||
if (!output->ost) {
|
|
||||||
av_log(filtergraphs[i], AV_LOG_FATAL,
|
|
||||||
"Filter %s has an unconnected output\n", output->name);
|
|
||||||
return AVERROR(EINVAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sub2video_prepare(InputFilterPriv *ifp)
|
static void sub2video_prepare(InputFilterPriv *ifp)
|
||||||
{
|
{
|
||||||
ifp->sub2video.last_pts = INT64_MIN;
|
ifp->sub2video.last_pts = INT64_MIN;
|
||||||
|
|||||||
@@ -674,18 +674,6 @@ static int opt_streamid(void *optctx, const char *opt, const char *arg)
|
|||||||
return av_dict_set(&o->streamid, idx_str, p, 0);
|
return av_dict_set(&o->streamid, idx_str, p, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int init_complex_filters(void)
|
|
||||||
{
|
|
||||||
int i, ret = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < nb_filtergraphs; i++) {
|
|
||||||
ret = init_complex_filtergraph(filtergraphs[i]);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int opt_target(void *optctx, const char *opt, const char *arg)
|
static int opt_target(void *optctx, const char *opt, const char *arg)
|
||||||
{
|
{
|
||||||
OptionsContext *o = optctx;
|
OptionsContext *o = optctx;
|
||||||
@@ -1264,13 +1252,6 @@ int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create the complex filtergraphs */
|
|
||||||
ret = init_complex_filters();
|
|
||||||
if (ret < 0) {
|
|
||||||
errmsg = "initializing complex filters";
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* open output files */
|
/* open output files */
|
||||||
ret = open_files(&octx.groups[GROUP_OUTFILE], "output", sch, of_open);
|
ret = open_files(&octx.groups[GROUP_OUTFILE], "output", sch, of_open);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -1278,16 +1259,21 @@ int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bind unbound filtegraph inputs/outputs and check consistency
|
||||||
|
for (int i = 0; i < nb_filtergraphs; i++) {
|
||||||
|
ret = fg_finalise_bindings(filtergraphs[i]);
|
||||||
|
if (ret < 0) {
|
||||||
|
errmsg = "binding filtergraph inputs/outputs";
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
correct_input_start_times();
|
correct_input_start_times();
|
||||||
|
|
||||||
ret = apply_sync_offsets();
|
ret = apply_sync_offsets();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
ret = check_filter_outputs();
|
|
||||||
if (ret < 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
uninit_parse_context(&octx);
|
uninit_parse_context(&octx);
|
||||||
if (ret < 0 && ret != AVERROR_EXIT) {
|
if (ret < 0 && ret != AVERROR_EXIT) {
|
||||||
|
|||||||
Reference in New Issue
Block a user