* commit 'bd2ab27c488ae92c7820efe11d4f53d84e94d58e': avconv: use read_file() for reading the 2pass stats Conflicts: cmdutils.c cmdutils.h ffmpeg_opt.c
Showing the changes to cmdutils.c (1 of 3 files). Show all
Unified · Split
| @@ -1875,64 +1875,6 @@ int read_yesno(void) · 1874 unmodified lines | |||
| 1875 | return yesno; | 1875 | return yesno; |
| 1876 | } | 1876 | } |
| 1877 | 1877 | ||
| 1878 | int cmdutils_read_file(const char *filename, char **bufptr, size_t *size) | ||
| 1879 | { | ||
| 1880 | int64_t ret; | ||
| 1881 | FILE *f = av_fopen_utf8(filename, "rb"); | ||
| 1882 | |||
| 1883 | if (!f) { | ||
| 1884 | ret = AVERROR(errno); | ||
| 1885 | av_log(NULL, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, | ||
| 1886 | strerror(errno)); | ||
| 1887 | return ret; | ||
| 1888 | } | ||
| 1889 | |||
| 1890 | ret = fseek(f, 0, SEEK_END); | ||
| 1891 | if (ret == -1) { | ||
| 1892 | ret = AVERROR(errno); | ||
| 1893 | goto out; | ||
| 1894 | } | ||
| 1895 | |||
| 1896 | ret = ftell(f); | ||
| 1897 | if (ret < 0) { | ||
| 1898 | ret = AVERROR(errno); | ||
| 1899 | goto out; | ||
| 1900 | } | ||
| 1901 | *size = ret; | ||
| 1902 | |||
| 1903 | ret = fseek(f, 0, SEEK_SET); | ||
| 1904 | if (ret == -1) { | ||
| 1905 | ret = AVERROR(errno); | ||
| 1906 | goto out; | ||
| 1907 | } | ||
| 1908 | |||
| 1909 | *bufptr = av_malloc(*size + 1); | ||
| 1910 | if (!*bufptr) { | ||
| 1911 | av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n"); | ||
| 1912 | ret = AVERROR(ENOMEM); | ||
| 1913 | goto out; | ||
| 1914 | } | ||
| 1915 | ret = fread(*bufptr, 1, *size, f); | ||
| 1916 | if (ret < *size) { | ||
| 1917 | av_free(*bufptr); | ||
| 1918 | if (ferror(f)) { | ||
| 1919 | ret = AVERROR(errno); | ||
| 1920 | av_log(NULL, AV_LOG_ERROR, "Error while reading file '%s': %s\n", | ||
| 1921 | filename, strerror(errno)); | ||
| 1922 | } else | ||
| 1923 | ret = AVERROR_EOF; | ||
| 1924 | } else { | ||
| 1925 | ret = 0; | ||
| 1926 | (*bufptr)[(*size)++] = '\0'; | ||
| 1927 | } | ||
| 1928 | |||
| 1929 | out: | ||
| 1930 | if (ret < 0) | ||
| 1931 | av_log(NULL, AV_LOG_ERROR, "IO error: %s\n", av_err2str(ret)); | ||
| 1932 | fclose(f); | ||
| 1933 | return ret; | ||
| 1934 | } | ||
| 1935 | |||
| 1936 | FILE *get_preset_file(char *filename, size_t filename_size, | 1878 | FILE *get_preset_file(char *filename, size_t filename_size, |
| 1937 | const char *preset_name, int is_path, | 1879 | const char *preset_name, int is_path, |
| 1938 | const char *codec_name) | 1880 | const char *codec_name) |