static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pad_idx)

{

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

    AVFilterGraph *graph = (*last_filter)->graph;

    AVFilterContext *ctx;

    const AVFilter *trim;

    const char *name = ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO ? "trim" : "atrim";

    char filter_name[128];

    int ret = 0;



    if (of->recording_time == INT64_MAX && !of->start_time)

        return 0;



    trim = avfilter_get_by_name(name);

    if (!trim) {

        av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "

               "recording time.\n", name);

        return AVERROR_FILTER_NOT_FOUND;

    }



    snprintf(filter_name, sizeof(filter_name), "%s for output stream %d:%d",

             name, ost->file_index, ost->index);

    ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);

    if (!ctx)

        return AVERROR(ENOMEM);



    if (of->recording_time != INT64_MAX) {

        ret = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6,

                                AV_OPT_SEARCH_CHILDREN);

    }

    if (ret >= 0 && of->start_time) {

        ret = av_opt_set_double(ctx, "start", (double)of->start_time / 1e6,

                                AV_OPT_SEARCH_CHILDREN);

    }

    if (ret < 0) {

        av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);

        return ret;

    }



    ret = avfilter_init_str(ctx, NULL);

    if (ret < 0)

        return ret;



    ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);

    if (ret < 0)

        return ret;



    *last_filter = ctx;

    *pad_idx     = 0;

    return 0;

}

static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pad_idx)

{

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

    AVFilterGraph *graph = (*last_filter)->graph;

    AVFilterContext *ctx;

    const AVFilter *trim;

    const char *name = ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO ? "trim" : "atrim";

    char filter_name[128];

    int ret = 0;



    if (of->recording_time == INT64_MAX && !of->start_time)

        return 0;



    trim = avfilter_get_by_name(name);

    if (!trim) {

        av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "

               "recording time.\n", name);

        return AVERROR_FILTER_NOT_FOUND;

    }



    snprintf(filter_name, sizeof(filter_name), "%s for output stream %d:%d",

             name, ost->file_index, ost->index);

    ctx = avfilter_graph_alloc_filter(graph, trim, filter_name);

    if (!ctx)

        return AVERROR(ENOMEM);



    if (of->recording_time != INT64_MAX) {

        ret = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6,

                                AV_OPT_SEARCH_CHILDREN);

    }

    if (ret >= 0 && of->start_time) {

        ret = av_opt_set_double(ctx, "start", (double)of->start_time / 1e6,

                                AV_OPT_SEARCH_CHILDREN);

    }

    if (ret < 0) {

        av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name);

        return ret;

    }



    ret = avfilter_init_str(ctx, NULL);

    if (ret < 0)

        return ret;



    ret = avfilter_link(*last_filter, *pad_idx, ctx, 0);

    if (ret < 0)

        return ret;



    *last_filter = ctx;

    *pad_idx     = 0;

    return 0;

}

static int FUNC_0(OutputStream *VAR_0, AVFilterContext **VAR_1, int *VAR_2)

{

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

    AVFilterGraph *graph = (*VAR_1)->graph;

    AVFilterContext *ctx;

    const AVFilter *VAR_3;

    const char *VAR_4 = VAR_0->st->codec->codec_type == AVMEDIA_TYPE_VIDEO ? "VAR_3" : "atrim";

    char VAR_5[128];

    int VAR_6 = 0;



    if (of->recording_time == INT64_MAX && !of->start_time)

        return 0;



    VAR_3 = avfilter_get_by_name(VAR_4);

    if (!VAR_3) {

        av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "

               "recording time.\n", VAR_4);

        return AVERROR_FILTER_NOT_FOUND;

    }



    snprintf(VAR_5, sizeof(VAR_5), "%s for output stream %d:%d",

             VAR_4, VAR_0->file_index, VAR_0->index);

    ctx = avfilter_graph_alloc_filter(graph, VAR_3, VAR_5);

    if (!ctx)

        return AVERROR(ENOMEM);



    if (of->recording_time != INT64_MAX) {

        VAR_6 = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6,

                                AV_OPT_SEARCH_CHILDREN);

    }

    if (VAR_6 >= 0 && of->start_time) {

        VAR_6 = av_opt_set_double(ctx, "start", (double)of->start_time / 1e6,

                                AV_OPT_SEARCH_CHILDREN);

    }

    if (VAR_6 < 0) {

        av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", VAR_4);

        return VAR_6;

    }



    VAR_6 = avfilter_init_str(ctx, NULL);

    if (VAR_6 < 0)

        return VAR_6;



    VAR_6 = avfilter_link(*VAR_1, *VAR_2, ctx, 0);

    if (VAR_6 < 0)

        return VAR_6;



    *VAR_1 = ctx;

    *VAR_2     = 0;

    return 0;

}

static int FUNC_0(OutputStream *VAR_0, AVFilterContext **VAR_1, int *VAR_2)
{ OutputFile *of = output_files[VAR_0->file_index]; AVFilterGraph *graph = (*VAR_1)->graph; AVFilterContext *ctx; const AVFilter *VAR_3; const char *VAR_4 = VAR_0->st->codec->codec_type == AVMEDIA_TYPE_VIDEO ? "VAR_3" : "atrim"; char VAR_5[128]; int VAR_6 = 0; if (of->recording_time == INT64_MAX && !of->start_time)
return 0; VAR_3 = avfilter_get_by_name(VAR_4); if (!VAR_3) { av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit "
"recording time.\n", VAR_4); return AVERROR_FILTER_NOT_FOUND; } snprintf(VAR_5, sizeof(VAR_5), "%s for output stream %d:%d",
VAR_4, VAR_0->file_index, VAR_0->index); ctx = avfilter_graph_alloc_filter(graph, VAR_3, VAR_5); if (!ctx)
return AVERROR(ENOMEM); if (of->recording_time != INT64_MAX) { VAR_6 = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6,
AV_OPT_SEARCH_CHILDREN); } if (VAR_6 >= 0 && of->start_time) { VAR_6 = av_opt_set_double(ctx, "start", (double)of->start_time / 1e6,
AV_OPT_SEARCH_CHILDREN); } if (VAR_6 < 0) { av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", VAR_4); return VAR_6; } VAR_6 = avfilter_init_str(ctx, NULL); if (VAR_6 < 0)
return VAR_6; VAR_6 = avfilter_link(*VAR_1, *VAR_2, ctx, 0); if (VAR_6 < 0)
return VAR_6; *VAR_1 = ctx; *VAR_2     = 0; return 0; }