From: Stefano Sabatini <stefano.sabatini-l...@poste.it> The problem with url_exist() is that it tries to open a file in RDONLY mode. If the file is a FIFO and there is a reading client, the open() call will hang, and the ffmpeg process will get stuck.
Using avio_check() with no access mode of ~0 check if the file simply exists without attempting to open it, thus avoiding locks. Fix issue #1663. --- ffmpeg.c | 2 +- ffserver.c | 4 ++-- libavformat/avio.c | 2 ++ libavformat/avio.h | 3 +++ libavformat/img2.c | 6 +++--- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 46adb9a..3cd887b 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -3733,7 +3733,7 @@ static void opt_output_file(const char *filename) (strchr(filename, ':') == NULL || filename[1] == ':' || av_strstart(filename, "file:", NULL))) { - if (url_exist(filename)) { + if (avio_check(filename, 0) != AVERROR(ENOENT)) { if (!using_stdin) { fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); fflush(stderr); diff --git a/ffserver.c b/ffserver.c index eab8ae2..dd8ed23 100644 --- a/ffserver.c +++ b/ffserver.c @@ -3684,7 +3684,7 @@ static void build_feed_streams(void) for(feed = first_feed; feed != NULL; feed = feed->next_feed) { int fd; - if (url_exist(feed->feed_filename)) { + if (avio_check(feed->feed_filename, URL_RDONLY) > 0) { /* See if it matches */ AVFormatContext *s; int matches = 0; @@ -3757,7 +3757,7 @@ static void build_feed_streams(void) unlink(feed->feed_filename); } } - if (!url_exist(feed->feed_filename)) { + if (avio_check(feed->feed_filename, URL_RDONLY) <= 0) { AVFormatContext s1 = {0}, *s = &s1; if (feed->readonly) { diff --git a/libavformat/avio.c b/libavformat/avio.c index ecc7f27..f811073 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -365,6 +365,7 @@ int ffurl_close(URLContext *h) return ret; } +#if FF_API_OLD_AVIO int url_exist(const char *filename) { URLContext *h; @@ -373,6 +374,7 @@ int url_exist(const char *filename) ffurl_close(h); return 1; } +#endif int avio_check(const char *url, int flags) { diff --git a/libavformat/avio.h b/libavformat/avio.h index 823aa97..806822c 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -119,11 +119,14 @@ attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index, attribute_deprecated void url_set_interrupt_cb(int (*interrupt_cb)(void)); #endif +#if FF_API_OLD_AVIO /** * Return a non-zero value if the resource indicated by url * exists, 0 otherwise. */ +attribute_deprecated int url_exist(const char *url); +#endif /** * Return a positive value if the resource indicated by url can be diff --git a/libavformat/img2.c b/libavformat/img2.c index 2b5d63b..917bae6 100644 --- a/libavformat/img2.c +++ b/libavformat/img2.c @@ -131,11 +131,11 @@ static int find_image_range(int *pfirst_index, int *plast_index, if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){ *pfirst_index = *plast_index = 1; - if(url_exist(buf)) + if (avio_check(buf, URL_RDONLY) != AVERROR(ENOENT)) return 0; return -1; } - if (url_exist(buf)) + if (avio_check(buf, URL_RDONLY) != AVERROR(ENOENT)) break; } if (first_index == 5) @@ -153,7 +153,7 @@ static int find_image_range(int *pfirst_index, int *plast_index, if (av_get_frame_filename(buf, sizeof(buf), path, last_index + range1) < 0) goto fail; - if (!url_exist(buf)) + if (avio_check(buf, URL_RDONLY) == AVERROR(ENOENT)) break; range = range1; /* just in case... */ -- 1.7.4.1 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel