diff options
-rw-r--r-- | DOCS/man/mpv.rst | 5 | ||||
-rw-r--r-- | stream/stream_file.c | 13 |
2 files changed, 13 insertions, 5 deletions
diff --git a/DOCS/man/mpv.rst b/DOCS/man/mpv.rst index 3ca135439d..a9fc5edab9 100644 --- a/DOCS/man/mpv.rst +++ b/DOCS/man/mpv.rst @@ -769,6 +769,11 @@ PROTOCOLS Read data from the given file descriptor (for example 123). This is similar to piping data to stdin via ``-``, but can use an arbitrary file descriptor. +``fdclose://123`` + + Like ``fd://``, but the file descriptor is closed after use. When using this + you need to ensure that the same fd URL will only be used once. + ``edl://[edl specification as in edl-mpv.rst]`` Stitch together parts of multiple files and play them. diff --git a/stream/stream_file.c b/stream/stream_file.c index 7d2b82fb58..d12d0d20b1 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -246,13 +246,16 @@ static int open_f(stream_t *stream) filename = stream->path; } - if (strncmp(stream->url, "fd://", 5) == 0) { - char *end = NULL; - p->fd = strtol(stream->url + 5, &end, 0); - if (!end || end == stream->url + 5 || end[0]) { + bool is_fdclose = strncmp(stream->url, "fdclose://", 10) == 0; + if (strncmp(stream->url, "fd://", 5) == 0 || is_fdclose) { + char *begin = strstr(stream->url, "://") + 3, *end = NULL; + p->fd = strtol(begin, &end, 0); + if (!end || end == begin || end[0]) { MP_ERR(stream, "Invalid FD: %s\n", stream->url); return STREAM_ERROR; } + if (is_fdclose) + p->close = true; } else if (!strcmp(filename, "-")) { if (!write) { MP_INFO(stream, "Reading from stdin...\n"); @@ -322,7 +325,7 @@ static int open_f(stream_t *stream) const stream_info_t stream_info_file = { .name = "file", .open = open_f, - .protocols = (const char*const[]){ "file", "", "fd", NULL }, + .protocols = (const char*const[]){ "file", "", "fd", "fdclose", NULL }, .can_write = true, .is_safe = true, }; |