static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)

{

    InputStream *ist;

    enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx);

    int i;



    // TODO: support other filter types

    if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {

        av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "

               "currently.\n");

        exit_program(1);

    }



    if (in->name) {

        AVFormatContext *s;

        AVStream       *st = NULL;

        char *p;

        int file_idx = strtol(in->name, &p, 0);



        if (file_idx < 0 || file_idx >= nb_input_files) {

            av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtegraph description %s.\n",

                   file_idx, fg->graph_desc);

            exit_program(1);

        }

        s = input_files[file_idx]->ctx;



        for (i = 0; i < s->nb_streams; i++) {

            if (s->streams[i]->codec->codec_type != type)

                continue;

            if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {

                st = s->streams[i];

                break;

            }

        }

        if (!st) {

            av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "

                   "matches no streams.\n", p, fg->graph_desc);

            exit_program(1);

        }

        ist = input_streams[input_files[file_idx]->ist_index + st->index];

    } else {

        /* find the first unused stream of corresponding type */

        for (i = 0; i < nb_input_streams; i++) {

            ist = input_streams[i];

            if (ist->st->codec->codec_type == type && ist->discard)

                break;

        }

        if (i == nb_input_streams) {

            av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "

                   "unlabeled input pad %d on filter %s", in->pad_idx,

                   in->filter_ctx->name);

            exit_program(1);

        }

    }

    ist->discard         = 0;

    ist->decoding_needed = 1;

    ist->st->discard = AVDISCARD_NONE;



    fg->inputs = grow_array(fg->inputs, sizeof(*fg->inputs),

                            &fg->nb_inputs, fg->nb_inputs + 1);

    if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))

        exit_program(1);

    fg->inputs[fg->nb_inputs - 1]->ist   = ist;

    fg->inputs[fg->nb_inputs - 1]->graph = fg;



    ist->filters = grow_array(ist->filters, sizeof(*ist->filters),

                              &ist->nb_filters, ist->nb_filters + 1);

    ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];

}

static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)

{

    InputStream *ist;

    enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx);

    int i;



    

    if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) {

        av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "

               "currently.\n");

        exit_program(1);

    }



    if (in->name) {

        AVFormatContext *s;

        AVStream       *st = NULL;

        char *p;

        int file_idx = strtol(in->name, &p, 0);



        if (file_idx < 0 || file_idx >= nb_input_files) {

            av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtegraph description %s.\n",

                   file_idx, fg->graph_desc);

            exit_program(1);

        }

        s = input_files[file_idx]->ctx;



        for (i = 0; i < s->nb_streams; i++) {

            if (s->streams[i]->codec->codec_type != type)

                continue;

            if (check_stream_specifier(s, s->streams[i], *p == ':' ? p + 1 : p) == 1) {

                st = s->streams[i];

                break;

            }

        }

        if (!st) {

            av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s "

                   "matches no streams.\n", p, fg->graph_desc);

            exit_program(1);

        }

        ist = input_streams[input_files[file_idx]->ist_index + st->index];

    } else {

        

        for (i = 0; i < nb_input_streams; i++) {

            ist = input_streams[i];

            if (ist->st->codec->codec_type == type && ist->discard)

                break;

        }

        if (i == nb_input_streams) {

            av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "

                   "unlabeled input pad %d on filter %s", in->pad_idx,

                   in->filter_ctx->name);

            exit_program(1);

        }

    }

    ist->discard         = 0;

    ist->decoding_needed = 1;

    ist->st->discard = AVDISCARD_NONE;



    fg->inputs = grow_array(fg->inputs, sizeof(*fg->inputs),

                            &fg->nb_inputs, fg->nb_inputs + 1);

    if (!(fg->inputs[fg->nb_inputs - 1] = av_mallocz(sizeof(*fg->inputs[0]))))

        exit_program(1);

    fg->inputs[fg->nb_inputs - 1]->ist   = ist;

    fg->inputs[fg->nb_inputs - 1]->graph = fg;



    ist->filters = grow_array(ist->filters, sizeof(*ist->filters),

                              &ist->nb_filters, ist->nb_filters + 1);

    ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1];

}

    InputStream *ist;
static void FUNC_0(FilterGraph *VAR_0, AVFilterInOut *VAR_1)

{

    InputStream *ist;

    enum AVMediaType VAR_2 = avfilter_pad_get_type(VAR_1->filter_ctx->input_pads, VAR_1->pad_idx);

    int VAR_3;



    

    if (VAR_2 != AVMEDIA_TYPE_VIDEO && VAR_2 != AVMEDIA_TYPE_AUDIO) {

        av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "

               "currently.\n");

        exit_program(1);

    }



    if (VAR_1->name) {

        AVFormatContext *s;

        AVStream       *st = NULL;

        char *VAR_4;

        int VAR_5 = strtol(VAR_1->name, &VAR_4, 0);



        if (VAR_5 < 0 || VAR_5 >= nb_input_files) {

            av_log(NULL, AV_LOG_FATAL, "Invalid file index %d VAR_1 filtegraph description %s.\n",

                   VAR_5, VAR_0->graph_desc);

            exit_program(1);

        }

        s = input_files[VAR_5]->ctx;



        for (VAR_3 = 0; VAR_3 < s->nb_streams; VAR_3++) {

            if (s->streams[VAR_3]->codec->codec_type != VAR_2)

                continue;

            if (check_stream_specifier(s, s->streams[VAR_3], *VAR_4 == ':' ? VAR_4 + 1 : VAR_4) == 1) {

                st = s->streams[VAR_3];

                break;

            }

        }

        if (!st) {

            av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' VAR_1 filtergraph description %s "

                   "matches no streams.\n", VAR_4, VAR_0->graph_desc);

            exit_program(1);

        }

        ist = input_streams[input_files[VAR_5]->ist_index + st->index];

    } else {

        

        for (VAR_3 = 0; VAR_3 < nb_input_streams; VAR_3++) {

            ist = input_streams[VAR_3];

            if (ist->st->codec->codec_type == VAR_2 && ist->discard)

                break;

        }

        if (VAR_3 == nb_input_streams) {

            av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "

                   "unlabeled input pad %d on filter %s", VAR_1->pad_idx,

                   VAR_1->filter_ctx->name);

            exit_program(1);

        }

    }

    ist->discard         = 0;

    ist->decoding_needed = 1;

    ist->st->discard = AVDISCARD_NONE;



    VAR_0->inputs = grow_array(VAR_0->inputs, sizeof(*VAR_0->inputs),

                            &VAR_0->nb_inputs, VAR_0->nb_inputs + 1);

    if (!(VAR_0->inputs[VAR_0->nb_inputs - 1] = av_mallocz(sizeof(*VAR_0->inputs[0]))))

        exit_program(1);

    VAR_0->inputs[VAR_0->nb_inputs - 1]->ist   = ist;

    VAR_0->inputs[VAR_0->nb_inputs - 1]->graph = VAR_0;



    ist->filters = grow_array(ist->filters, sizeof(*ist->filters),

                              &ist->nb_filters, ist->nb_filters + 1);

    ist->filters[ist->nb_filters - 1] = VAR_0->inputs[VAR_0->nb_inputs - 1];

}

static void FUNC_0(FilterGraph *VAR_0, AVFilterInOut *VAR_1)
{ InputStream *ist; enum AVMediaType VAR_2 = avfilter_pad_get_type(VAR_1->filter_ctx->input_pads, VAR_1->pad_idx); int VAR_3; if (VAR_2 != AVMEDIA_TYPE_VIDEO && VAR_2 != AVMEDIA_TYPE_AUDIO) { av_log(NULL, AV_LOG_FATAL, "Only video and audio filters supported "
"currently.\n"); exit_program(1); } if (VAR_1->name) { AVFormatContext *s; AVStream       *st = NULL; char *VAR_4; int VAR_5 = strtol(VAR_1->name, &VAR_4, 0); if (VAR_5 < 0 || VAR_5 >= nb_input_files) { av_log(NULL, AV_LOG_FATAL, "Invalid file index %d VAR_1 filtegraph description %s.\n",
VAR_5, VAR_0->graph_desc); exit_program(1); } s = input_files[VAR_5]->ctx; for (VAR_3 = 0; VAR_3 < s->nb_streams; VAR_3++) { if (s->streams[VAR_3]->codec->codec_type != VAR_2)
continue; if (check_stream_specifier(s, s->streams[VAR_3], *VAR_4 == ':' ? VAR_4 + 1 : VAR_4) == 1) { st = s->streams[VAR_3]; break; } } if (!st) { av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' VAR_1 filtergraph description %s "
"matches no streams.\n", VAR_4, VAR_0->graph_desc); exit_program(1); } ist = input_streams[input_files[VAR_5]->ist_index + st->index]; } else { for (VAR_3 = 0; VAR_3 < nb_input_streams; VAR_3++) { ist = input_streams[VAR_3]; if (ist->st->codec->codec_type == VAR_2 && ist->discard)
break; } if (VAR_3 == nb_input_streams) { av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for "
"unlabeled input pad %d on filter %s", VAR_1->pad_idx,
VAR_1->filter_ctx->name); exit_program(1); } } ist->discard         = 0; ist->decoding_needed = 1; ist->st->discard = AVDISCARD_NONE; VAR_0->inputs = grow_array(VAR_0->inputs, sizeof(*VAR_0->inputs),
&VAR_0->nb_inputs, VAR_0->nb_inputs + 1); if (!(VAR_0->inputs[VAR_0->nb_inputs - 1] = av_mallocz(sizeof(*VAR_0->inputs[0]))))
exit_program(1); VAR_0->inputs[VAR_0->nb_inputs - 1]->ist   = ist; VAR_0->inputs[VAR_0->nb_inputs - 1]->graph = VAR_0; ist->filters = grow_array(ist->filters, sizeof(*ist->filters),
&ist->nb_filters, ist->nb_filters + 1); ist->filters[ist->nb_filters - 1] = VAR_0->inputs[VAR_0->nb_inputs - 1]; }