fftools/ffmpeg_filter: add a function for creating a filtergraph

Code creating a new filtergraph is currently duplicated in 3 places.
This commit unifies it and moves towards making filtergraphs more
self-contained.
pull/389/head
Anton Khirnov 2 years ago
parent 2104de13e9
commit 8b56480652
  1. 8
      fftools/ffmpeg.h
  2. 18
      fftools/ffmpeg_filter.c
  3. 14
      fftools/ffmpeg_opt.c

@ -803,6 +803,14 @@ int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame);
int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par);
int ifilter_has_all_input_formats(FilterGraph *fg);
/**
* Create a new filtergraph in the global filtergraph list.
*
* @param graph_desc Graph description; an av_malloc()ed string, filtergraph
* takes ownership of it.
*/
FilterGraph *fg_create(char *graph_desc);
int ffmpeg_parse_options(int argc, char **argv);
void enc_stats_write(OutputStream *ost, EncStats *es,

@ -188,15 +188,26 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg)
return ofilter;
}
FilterGraph *fg_create(char *graph_desc)
{
FilterGraph *fg;
fg = ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
fg->index = nb_filtergraphs - 1;
fg->graph_desc = graph_desc;
return fg;
}
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
{
FilterGraph *fg = av_mallocz(sizeof(*fg));
FilterGraph *fg;
OutputFilter *ofilter;
InputFilter *ifilter;
fg = fg_create(NULL);
if (!fg)
report_and_exit(AVERROR(ENOMEM));
fg->index = nb_filtergraphs;
ofilter = ofilter_alloc(fg);
ofilter->ost = ost;
@ -212,9 +223,6 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
if (!ifilter->frame_queue)
report_and_exit(AVERROR(ENOMEM));
GROW_ARRAY(filtergraphs, nb_filtergraphs);
filtergraphs[nb_filtergraphs - 1] = fg;
ist_filter_add(ist, ifilter, 1);
return 0;

@ -1106,26 +1106,22 @@ static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
{
FilterGraph *fg = ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
fg->index = nb_filtergraphs - 1;
fg->graph_desc = av_strdup(arg);
if (!fg->graph_desc)
char *graph_desc = av_strdup(arg);
if (!graph_desc)
return AVERROR(ENOMEM);
fg_create(graph_desc);
return 0;
}
static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
{
FilterGraph *fg;
char *graph_desc = file_read(arg);
if (!graph_desc)
return AVERROR(EINVAL);
fg = ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
fg->index = nb_filtergraphs - 1;
fg->graph_desc = graph_desc;
fg_create(graph_desc);
return 0;
}

Loading…
Cancel
Save