summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhao Zhili <zhilizhao@tencent.com>2022-12-15 01:10:07 +0800
committerZhao Zhili <zhilizhao@tencent.com>2023-01-11 18:50:36 +0800
commit49b8f043ca3e39141929d8614876131be0a801a9 (patch)
treed78b62e0dab27fd8fb8c9eef8bd266ac94794e08
parent0d7c452d84e7ed228601b0285152f158ee2308fd (diff)
avformat/file: add fd option for pipe
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
-rw-r--r--doc/protocols.texi4
-rw-r--r--libavformat/file.c9
-rw-r--r--libavformat/version.h2
3 files changed, 11 insertions, 4 deletions
diff --git a/doc/protocols.texi b/doc/protocols.texi
index d1c6fced7b..a686a7f0ac 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -687,7 +687,7 @@ The accepted syntax is:
pipe:[@var{number}]
@end example
-@var{number} is the number corresponding to the file descriptor of the
+If @option{fd} isn't specified, @var{number} is the number corresponding to the file descriptor of the
pipe (e.g. 0 for stdin, 1 for stdout, 2 for stderr). If @var{number}
is not specified, by default the stdout file descriptor will be used
for writing, stdin for reading.
@@ -714,6 +714,8 @@ Set I/O operation maximum block size, in bytes. Default value is
@code{INT_MAX}, which results in not limiting the requested block size.
Setting this value reasonably low improves user termination request reaction
time, which is valuable if data transmission is slow.
+@item fd
+Set file descriptor.
@end table
Note that some formats (typically MOV), require the output protocol to
diff --git a/libavformat/file.c b/libavformat/file.c
index 6103c37b34..db619fcaac 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -92,6 +92,7 @@ static const AVOption file_options[] = {
static const AVOption pipe_options[] = {
{ "blocksize", "set I/O operation maximum block size", offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+ { "fd", "set file descriptor", offsetof(FileContext, fd), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
{ NULL }
};
@@ -381,6 +382,8 @@ static int pipe_open(URLContext *h, const char *filename, int flags)
FileContext *c = h->priv_data;
int fd;
char *final;
+
+ if (c->fd < 0) {
av_strstart(filename, "pipe:", &filename);
fd = strtol(filename, &final, 10);
@@ -391,10 +394,12 @@ static int pipe_open(URLContext *h, const char *filename, int flags)
fd = 0;
}
}
+ c->fd = fd;
+ }
+
#if HAVE_SETMODE
- setmode(fd, O_BINARY);
+ setmode(c->fd, O_BINARY);
#endif
- c->fd = fd;
h->is_streamed = 1;
return 0;
}
diff --git a/libavformat/version.h b/libavformat/version.h
index a7e5a9ac66..63e753a3aa 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
#include "version_major.h"
#define LIBAVFORMAT_VERSION_MINOR 34
-#define LIBAVFORMAT_VERSION_MICRO 102
+#define LIBAVFORMAT_VERSION_MICRO 103
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \