[FFmpeg-devel] [PATCH v3 1/8] avformat/file: add fd option for pipe
Zhao Zhili
quinkblack at foxmail.com
Wed Dec 14 19:10:07 EET 2022
From: Zhao Zhili <zhilizhao at tencent.com>
---
doc/protocols.texi | 4 +++-
libavformat/file.c | 9 +++++++--
libavformat/version.h | 2 +-
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
- at 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.
+ at 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, \
--
2.25.1
More information about the ffmpeg-devel
mailing list