| 1917 | } |
| 1918 | |
| 1919 | static int format_name(const char *buf, char **s, int index, const char *varname) |
| 1920 | { |
| 1921 | const char *proto, *dir; |
| 1922 | char *orig_buf_dup = NULL, *mod_buf_dup = NULL; |
| 1923 | int ret = 0; |
| 1924 | |
| 1925 | orig_buf_dup = av_strdup(buf); |
| 1926 | if (!orig_buf_dup) |
| 1927 | return AVERROR(ENOMEM); |
| 1928 | |
| 1929 | if (!av_stristr(buf, "%v")) { |
| 1930 | *s = orig_buf_dup; |
| 1931 | return 0; |
| 1932 | } |
| 1933 | |
| 1934 | if (!varname) { |
| 1935 | if (replace_int_data_in_filename(s, orig_buf_dup, 'v', index) < 1) { |
| 1936 | ret = AVERROR(EINVAL); |
| 1937 | goto fail; |
| 1938 | } |
| 1939 | } else { |
| 1940 | if (replace_str_data_in_filename(s, orig_buf_dup, 'v', varname) < 1) { |
| 1941 | ret = AVERROR(EINVAL); |
| 1942 | goto fail; |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | proto = avio_find_protocol_name(orig_buf_dup); |
| 1947 | dir = av_dirname(orig_buf_dup); |
| 1948 | |
| 1949 | /* if %v is present in the file's directory, create sub-directory */ |
| 1950 | if (av_stristr(dir, "%v") && proto && !strcmp(proto, "file")) { |
| 1951 | mod_buf_dup = av_strdup(*s); |
| 1952 | dir = av_dirname(mod_buf_dup); |
| 1953 | if (ff_mkdir_p(dir) == -1 && errno != EEXIST) { |
| 1954 | ret = AVERROR(errno); |
| 1955 | goto fail; |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | fail: |
| 1960 | av_freep(&orig_buf_dup); |
| 1961 | av_freep(&mod_buf_dup); |
| 1962 | return ret; |
| 1963 | } |
| 1964 | |
| 1965 | static int get_nth_codec_stream_index(AVFormatContext *s, |
| 1966 | enum AVMediaType codec_type, |
no test coverage detected