static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)

{

    char *pix_fmts;

    OutputStream *ost = ofilter->ost;

    OutputFile    *of = output_files[ost->file_index];

    AVFilterContext *last_filter = out->filter_ctx;

    int pad_idx = out->pad_idx;

    int ret;

    char name[255];



    snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);

    ret = avfilter_graph_create_filter(&ofilter->filter,

                                       avfilter_get_by_name("buffersink"),

                                       name, NULL, NULL, fg->graph);

    if (ret < 0)

        return ret;



    if (!hw_device_ctx && (ofilter->width || ofilter->height)) {

        char args[255];

        AVFilterContext *filter;



        snprintf(args, sizeof(args), "%d:%d:0x%X",

                 ofilter->width, ofilter->height,

                 (unsigned)ost->sws_flags);

        snprintf(name, sizeof(name), "scaler for output stream %d:%d",

                 ost->file_index, ost->index);

        if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),

                                                name, args, NULL, fg->graph)) < 0)

            return ret;

        if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)

            return ret;



        last_filter = filter;

        pad_idx = 0;

    }



    if ((pix_fmts = choose_pix_fmts(ofilter))) {

        AVFilterContext *filter;

        snprintf(name, sizeof(name), "pixel format for output stream %d:%d",

                 ost->file_index, ost->index);

        ret = avfilter_graph_create_filter(&filter,

                                           avfilter_get_by_name("format"),

                                           "format", pix_fmts, NULL, fg->graph);

        av_freep(&pix_fmts);

        if (ret < 0)

            return ret;

        if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)

            return ret;



        last_filter = filter;

        pad_idx     = 0;

    }



    if (ost->frame_rate.num) {

        AVFilterContext *fps;

        char args[255];



        snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,

                 ost->frame_rate.den);

        snprintf(name, sizeof(name), "fps for output stream %d:%d",

                 ost->file_index, ost->index);

        ret = avfilter_graph_create_filter(&fps, avfilter_get_by_name("fps"),

                                           name, args, NULL, fg->graph);

        if (ret < 0)

            return ret;



        ret = avfilter_link(last_filter, pad_idx, fps, 0);

        if (ret < 0)

            return ret;

        last_filter = fps;

        pad_idx = 0;

    }



    snprintf(name, sizeof(name), "trim for output stream %d:%d",

             ost->file_index, ost->index);

    ret = insert_trim(of->start_time, of->recording_time,

                      &last_filter, &pad_idx, name);

    if (ret < 0)

        return ret;





    if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)

        return ret;



    return 0;

}

static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)

{

    char *pix_fmts;

    OutputStream *ost = ofilter->ost;

    OutputFile    *of = output_files[ost->file_index];

    AVFilterContext *last_filter = out->filter_ctx;

    int pad_idx = out->pad_idx;

    int ret;

    char name[255];



    snprintf(name, sizeof(name), "output stream %d:%d", ost->file_index, ost->index);

    ret = avfilter_graph_create_filter(&ofilter->filter,

                                       avfilter_get_by_name("buffersink"),

                                       name, NULL, NULL, fg->graph);

    if (ret < 0)

        return ret;



    if (!hw_device_ctx && (ofilter->width || ofilter->height)) {

        char args[255];

        AVFilterContext *filter;



        snprintf(args, sizeof(args), "%d:%d:0x%X",

                 ofilter->width, ofilter->height,

                 (unsigned)ost->sws_flags);

        snprintf(name, sizeof(name), "scaler for output stream %d:%d",

                 ost->file_index, ost->index);

        if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),

                                                name, args, NULL, fg->graph)) < 0)

            return ret;

        if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)

            return ret;



        last_filter = filter;

        pad_idx = 0;

    }



    if ((pix_fmts = choose_pix_fmts(ofilter))) {

        AVFilterContext *filter;

        snprintf(name, sizeof(name), "pixel format for output stream %d:%d",

                 ost->file_index, ost->index);

        ret = avfilter_graph_create_filter(&filter,

                                           avfilter_get_by_name("format"),

                                           "format", pix_fmts, NULL, fg->graph);

        av_freep(&pix_fmts);

        if (ret < 0)

            return ret;

        if ((ret = avfilter_link(last_filter, pad_idx, filter, 0)) < 0)

            return ret;



        last_filter = filter;

        pad_idx     = 0;

    }



    if (ost->frame_rate.num) {

        AVFilterContext *fps;

        char args[255];



        snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num,

                 ost->frame_rate.den);

        snprintf(name, sizeof(name), "fps for output stream %d:%d",

                 ost->file_index, ost->index);

        ret = avfilter_graph_create_filter(&fps, avfilter_get_by_name("fps"),

                                           name, args, NULL, fg->graph);

        if (ret < 0)

            return ret;



        ret = avfilter_link(last_filter, pad_idx, fps, 0);

        if (ret < 0)

            return ret;

        last_filter = fps;

        pad_idx = 0;

    }



    snprintf(name, sizeof(name), "trim for output stream %d:%d",

             ost->file_index, ost->index);

    ret = insert_trim(of->start_time, of->recording_time,

                      &last_filter, &pad_idx, name);

    if (ret < 0)

        return ret;





    if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0)

        return ret;



    return 0;

}

static int FUNC_0(FilterGraph *VAR_0, OutputFilter *VAR_1, AVFilterInOut *VAR_2)

{

    char *VAR_3;

    OutputStream *ost = VAR_1->ost;

    OutputFile    *of = output_files[ost->file_index];

    AVFilterContext *last_filter = VAR_2->filter_ctx;

    int VAR_4 = VAR_2->VAR_4;

    int VAR_5;

    char VAR_6[255];



    snprintf(VAR_6, sizeof(VAR_6), "output stream %d:%d", ost->file_index, ost->index);

    VAR_5 = avfilter_graph_create_filter(&VAR_1->filter,

                                       avfilter_get_by_name("buffersink"),

                                       VAR_6, NULL, NULL, VAR_0->graph);

    if (VAR_5 < 0)

        return VAR_5;



    if (!hw_device_ctx && (VAR_1->width || VAR_1->height)) {

        char VAR_8[255];

        AVFilterContext *filter;



        snprintf(VAR_8, sizeof(VAR_8), "%d:%d:0x%X",

                 VAR_1->width, VAR_1->height,

                 (unsigned)ost->sws_flags);

        snprintf(VAR_6, sizeof(VAR_6), "scaler for output stream %d:%d",

                 ost->file_index, ost->index);

        if ((VAR_5 = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),

                                                VAR_6, VAR_8, NULL, VAR_0->graph)) < 0)

            return VAR_5;

        if ((VAR_5 = avfilter_link(last_filter, VAR_4, filter, 0)) < 0)

            return VAR_5;



        last_filter = filter;

        VAR_4 = 0;

    }



    if ((VAR_3 = choose_pix_fmts(VAR_1))) {

        AVFilterContext *filter;

        snprintf(VAR_6, sizeof(VAR_6), "pixel format for output stream %d:%d",

                 ost->file_index, ost->index);

        VAR_5 = avfilter_graph_create_filter(&filter,

                                           avfilter_get_by_name("format"),

                                           "format", VAR_3, NULL, VAR_0->graph);

        av_freep(&VAR_3);

        if (VAR_5 < 0)

            return VAR_5;

        if ((VAR_5 = avfilter_link(last_filter, VAR_4, filter, 0)) < 0)

            return VAR_5;



        last_filter = filter;

        VAR_4     = 0;

    }



    if (ost->frame_rate.num) {

        AVFilterContext *fps;

        char VAR_8[255];



        snprintf(VAR_8, sizeof(VAR_8), "fps=%d/%d", ost->frame_rate.num,

                 ost->frame_rate.den);

        snprintf(VAR_6, sizeof(VAR_6), "fps for output stream %d:%d",

                 ost->file_index, ost->index);

        VAR_5 = avfilter_graph_create_filter(&fps, avfilter_get_by_name("fps"),

                                           VAR_6, VAR_8, NULL, VAR_0->graph);

        if (VAR_5 < 0)

            return VAR_5;



        VAR_5 = avfilter_link(last_filter, VAR_4, fps, 0);

        if (VAR_5 < 0)

            return VAR_5;

        last_filter = fps;

        VAR_4 = 0;

    }



    snprintf(VAR_6, sizeof(VAR_6), "trim for output stream %d:%d",

             ost->file_index, ost->index);

    VAR_5 = insert_trim(of->start_time, of->recording_time,

                      &last_filter, &VAR_4, VAR_6);

    if (VAR_5 < 0)

        return VAR_5;





    if ((VAR_5 = avfilter_link(last_filter, VAR_4, VAR_1->filter, 0)) < 0)

        return VAR_5;



    return 0;

}

static int FUNC_0(FilterGraph *VAR_0, OutputFilter *VAR_1, AVFilterInOut *VAR_2)
{ char *VAR_3; OutputStream *ost = VAR_1->ost; OutputFile    *of = output_files[ost->file_index]; AVFilterContext *last_filter = VAR_2->filter_ctx; int VAR_4 = VAR_2->VAR_4; int VAR_5; char VAR_6[255]; snprintf(VAR_6, sizeof(VAR_6), "output stream %d:%d", ost->file_index, ost->index); VAR_5 = avfilter_graph_create_filter(&VAR_1->filter,
avfilter_get_by_name("buffersink"),
VAR_6, NULL, NULL, VAR_0->graph); if (VAR_5 < 0)
return VAR_5; if (!hw_device_ctx && (VAR_1->width || VAR_1->height)) { char VAR_8[255]; AVFilterContext *filter; snprintf(VAR_8, sizeof(VAR_8), "%d:%d:0x%X",
VAR_1->width, VAR_1->height,
(unsigned)ost->sws_flags); snprintf(VAR_6, sizeof(VAR_6), "scaler for output stream %d:%d",
ost->file_index, ost->index); if ((VAR_5 = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"),
VAR_6, VAR_8, NULL, VAR_0->graph)) < 0)
return VAR_5; if ((VAR_5 = avfilter_link(last_filter, VAR_4, filter, 0)) < 0)
return VAR_5; last_filter = filter; VAR_4 = 0; } if ((VAR_3 = choose_pix_fmts(VAR_1))) { AVFilterContext *filter; snprintf(VAR_6, sizeof(VAR_6), "pixel format for output stream %d:%d",
ost->file_index, ost->index); VAR_5 = avfilter_graph_create_filter(&filter,
avfilter_get_by_name("format"),
"format", VAR_3, NULL, VAR_0->graph); av_freep(&VAR_3); if (VAR_5 < 0)
return VAR_5; if ((VAR_5 = avfilter_link(last_filter, VAR_4, filter, 0)) < 0)
return VAR_5; last_filter = filter; VAR_4     = 0; } if (ost->frame_rate.num) { AVFilterContext *fps; char VAR_8[255]; snprintf(VAR_8, sizeof(VAR_8), "fps=%d/%d", ost->frame_rate.num,
ost->frame_rate.den); snprintf(VAR_6, sizeof(VAR_6), "fps for output stream %d:%d",
ost->file_index, ost->index); VAR_5 = avfilter_graph_create_filter(&fps, avfilter_get_by_name("fps"),
VAR_6, VAR_8, NULL, VAR_0->graph); if (VAR_5 < 0)
return VAR_5; VAR_5 = avfilter_link(last_filter, VAR_4, fps, 0); if (VAR_5 < 0)
return VAR_5; last_filter = fps; VAR_4 = 0; } snprintf(VAR_6, sizeof(VAR_6), "trim for output stream %d:%d",
ost->file_index, ost->index); VAR_5 = insert_trim(of->start_time, of->recording_time,
&last_filter, &VAR_4, VAR_6); if (VAR_5 < 0)
return VAR_5; if ((VAR_5 = avfilter_link(last_filter, VAR_4, VAR_1->filter, 0)) < 0)
return VAR_5; return 0; }