static int format_name(char *buf, int buf_len, int index)

{

    const char *proto, *dir;

    char *orig_buf_dup = NULL, *mod_buf_dup = NULL;

    int ret = 0;



    if (!av_stristr(buf, "%v"))

        return ret;



    orig_buf_dup = av_strdup(buf);

    if (!orig_buf_dup) {

        ret = AVERROR(ENOMEM);

        goto fail;

    }



    if (replace_int_data_in_filename(buf, buf_len, orig_buf_dup, 'v', index) < 1) {

        ret = AVERROR(EINVAL);

        goto fail;

    }



    proto = avio_find_protocol_name(orig_buf_dup);

    dir = av_dirname(orig_buf_dup);



    /* if %v is present in the file's directory, create sub-directory */

    if (av_stristr(dir, "%v") && proto && !strcmp(proto, "file")) {

        mod_buf_dup = av_strdup(buf);

        if (!mod_buf_dup) {

            ret = AVERROR(ENOMEM);

            goto fail;

        }



        dir = av_dirname(mod_buf_dup);

        if (mkdir_p(dir) == -1 && errno != EEXIST) {

            ret = AVERROR(errno);

            goto fail;

        }

    }



fail:

    av_freep(&orig_buf_dup);

    av_freep(&mod_buf_dup);

    return ret;

}

static int format_name(char *buf, int buf_len, int index)

{

    const char *proto, *dir;

    char *orig_buf_dup = NULL, *mod_buf_dup = NULL;

    int ret = 0;



    if (!av_stristr(buf, "%v"))

        return ret;



    orig_buf_dup = av_strdup(buf);

    if (!orig_buf_dup) {

        ret = AVERROR(ENOMEM);

        goto fail;

    }



    if (replace_int_data_in_filename(buf, buf_len, orig_buf_dup, 'v', index) < 1) {

        ret = AVERROR(EINVAL);

        goto fail;

    }



    proto = avio_find_protocol_name(orig_buf_dup);

    dir = av_dirname(orig_buf_dup);



    

    if (av_stristr(dir, "%v") && proto && !strcmp(proto, "file")) {

        mod_buf_dup = av_strdup(buf);

        if (!mod_buf_dup) {

            ret = AVERROR(ENOMEM);

            goto fail;

        }



        dir = av_dirname(mod_buf_dup);

        if (mkdir_p(dir) == -1 && errno != EEXIST) {

            ret = AVERROR(errno);

            goto fail;

        }

    }



fail:

    av_freep(&orig_buf_dup);

    av_freep(&mod_buf_dup);

    return ret;

}

static int FUNC_0(char *VAR_0, int VAR_1, int VAR_2)

{

    const char *VAR_3, *VAR_4;

    char *VAR_5 = NULL, *VAR_6 = NULL;

    int VAR_7 = 0;



    if (!av_stristr(VAR_0, "%v"))

        return VAR_7;



    VAR_5 = av_strdup(VAR_0);

    if (!VAR_5) {

        VAR_7 = AVERROR(ENOMEM);

        goto fail;

    }



    if (replace_int_data_in_filename(VAR_0, VAR_1, VAR_5, 'v', VAR_2) < 1) {

        VAR_7 = AVERROR(EINVAL);

        goto fail;

    }



    VAR_3 = avio_find_protocol_name(VAR_5);

    VAR_4 = av_dirname(VAR_5);



    

    if (av_stristr(VAR_4, "%v") && VAR_3 && !strcmp(VAR_3, "file")) {

        VAR_6 = av_strdup(VAR_0);

        if (!VAR_6) {

            VAR_7 = AVERROR(ENOMEM);

            goto fail;

        }



        VAR_4 = av_dirname(VAR_6);

        if (mkdir_p(VAR_4) == -1 && errno != EEXIST) {

            VAR_7 = AVERROR(errno);

            goto fail;

        }

    }



fail:

    av_freep(&VAR_5);

    av_freep(&VAR_6);

    return VAR_7;

}

static int FUNC_0(char *VAR_0, int VAR_1, int VAR_2)
{ const char *VAR_3, *VAR_4; char *VAR_5 = NULL, *VAR_6 = NULL; int VAR_7 = 0; if (!av_stristr(VAR_0, "%v"))
return VAR_7; VAR_5 = av_strdup(VAR_0); if (!VAR_5) { VAR_7 = AVERROR(ENOMEM); goto fail; } if (replace_int_data_in_filename(VAR_0, VAR_1, VAR_5, 'v', VAR_2) < 1) { VAR_7 = AVERROR(EINVAL); goto fail; } VAR_3 = avio_find_protocol_name(VAR_5); VAR_4 = av_dirname(VAR_5); if (av_stristr(VAR_4, "%v") && VAR_3 && !strcmp(VAR_3, "file")) { VAR_6 = av_strdup(VAR_0); if (!VAR_6) { VAR_7 = AVERROR(ENOMEM); goto fail; } VAR_4 = av_dirname(VAR_6); if (mkdir_p(VAR_4) == -1 && errno != EEXIST) { VAR_7 = AVERROR(errno); goto fail; } } fail:
av_freep(&VAR_5); av_freep(&VAR_6); return VAR_7; }