[FFmpeg-cvslog] Merge commit '933dec0e29ec4d2cb83474279a6c52d62fdb7310'

Derek Buitenhuis git at videolan.org
Tue Apr 19 15:42:03 CEST 2016


ffmpeg | branch: master | Derek Buitenhuis <derek.buitenhuis at gmail.com> | Tue Apr 19 14:41:19 2016 +0100| [90eb24996913238e1ad23d412fa3fa0fd93243c0] | committer: Derek Buitenhuis

Merge commit '933dec0e29ec4d2cb83474279a6c52d62fdb7310'

* commit '933dec0e29ec4d2cb83474279a6c52d62fdb7310':
  file: Add an option for following a file that is being written

Merged-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=90eb24996913238e1ad23d412fa3fa0fd93243c0
---

 doc/protocols.texi    |   11 +++++++++++
 libavformat/file.c    |    4 ++++
 libavformat/version.h |    2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index cfd7be7..a1084bd 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -224,6 +224,17 @@ it, unless special care is taken (tests, customized server configuration
 etc.). Different FTP servers behave in different way during seek
 operation. ff* tools may produce incomplete content due to server limitations.
 
+This protocol accepts the following options:
+
+ at table @option
+ at item follow
+If set to 1, the protocol will retry reading at the end of the file, allowing
+reading files that still are being written. In order for this to terminate,
+you either need to use the rw_timeout option, or use the interrupt callback
+(for API users).
+
+ at end table
+
 @section gopher
 
 Gopher protocol.
diff --git a/libavformat/file.c b/libavformat/file.c
index f37db1a..5765ce7 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -72,6 +72,7 @@ typedef struct FileContext {
     int fd;
     int trunc;
     int blocksize;
+    int follow;
 #if HAVE_DIRENT_H
     DIR *dir;
 #endif
@@ -80,6 +81,7 @@ typedef struct FileContext {
 static const AVOption file_options[] = {
     { "truncate", "truncate existing files on write", offsetof(FileContext, trunc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
     { "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 },
+    { "follow", "Follow a file as it is being written", offsetof(FileContext, follow), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
     { NULL }
 };
 
@@ -108,6 +110,8 @@ static int file_read(URLContext *h, unsigned char *buf, int size)
     int ret;
     size = FFMIN(size, c->blocksize);
     ret = read(c->fd, buf, size);
+    if (ret == 0 && c->follow)
+        return AVERROR(EAGAIN);
     return (ret == -1) ? AVERROR(errno) : ret;
 }
 
diff --git a/libavformat/version.h b/libavformat/version.h
index 93b87eb..5141b5b 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
 
 #define LIBAVFORMAT_VERSION_MAJOR  57
 #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, \


======================================================================

diff --cc doc/protocols.texi
index cfd7be7,c136c74..a1084bd
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@@ -156,74 -57,29 +156,85 @@@ ffmpeg -i "data:image/gif;base64,R0lGOD
  
  File access protocol.
  
 -Allow to read from or read to a file.
 +Read from or write to a file.
 +
 +A file URL can have the form:
 + at example
 +file:@var{filename}
 + at end example
 +
 +where @var{filename} is the path of the file to read.
 +
 +An URL that does not have a protocol prefix will be assumed to be a
 +file URL. Depending on the build, an URL that looks like a Windows
 +path with the drive letter at the beginning will also be assumed to be
 +a file URL (usually not the case in builds for unix-like systems).
  
 -For example to read from a file @file{input.mpeg} with @command{avconv}
 +For example to read from a file @file{input.mpeg} with @command{ffmpeg}
  use the command:
  @example
 -avconv -i file:input.mpeg output.mpeg
 +ffmpeg -i file:input.mpeg output.mpeg
 + at end example
 +
 +This protocol accepts the following options:
 +
 + at table @option
 + at item truncate
 +Truncate existing files on write, if set to 1. A value of 0 prevents
 +truncating. Default value is 1.
 +
 + at item blocksize
 +Set I/O operation maximum block size, in bytes. Default value is
 + at 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 for files on slow medium.
 + at end table
 +
 + at section ftp
 +
 +FTP (File Transfer Protocol).
 +
 +Read from or write to remote resources using FTP protocol.
 +
 +Following syntax is required.
 + at example
 +ftp://[user[:password]@@]server[:port]/path/to/remote/resource.mpeg
  @end example
  
 -The av* tools default to the file protocol, that is a resource
 -specified with the name "FILE.mpeg" is interpreted as the URL
 -"file:FILE.mpeg".
 +This protocol accepts the following options.
 +
 + at table @option
 + at item timeout
 +Set timeout in microseconds of socket I/O operations used by the underlying low level
 +operation. By default it is set to -1, which means that the timeout is
 +not specified.
 +
 + at item ftp-anonymous-password
 +Password used when login as anonymous user. Typically an e-mail address
 +should be used.
 +
 + at item ftp-write-seekable
 +Control seekability of connection during encoding. If set to 1 the
 +resource is supposed to be seekable, if set to 0 it is assumed not
 +to be seekable. Default value is 0.
 + at end table
 +
 +NOTE: Protocol can be used as output, but it is recommended to not do
 +it, unless special care is taken (tests, customized server configuration
 +etc.). Different FTP servers behave in different way during seek
 +operation. ff* tools may produce incomplete content due to server limitations.
  
+ This protocol accepts the following options:
+ 
+ @table @option
+ @item follow
+ If set to 1, the protocol will retry reading at the end of the file, allowing
+ reading files that still are being written. In order for this to terminate,
+ you either need to use the rw_timeout option, or use the interrupt callback
+ (for API users).
+ 
+ @end table
+ 
  @section gopher
  
  Gopher protocol.
diff --cc libavformat/file.c
index f37db1a,8683c1b..5765ce7
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@@ -71,15 -42,12 +71,17 @@@ typedef struct FileContext 
      const AVClass *class;
      int fd;
      int trunc;
 +    int blocksize;
+     int follow;
 +#if HAVE_DIRENT_H
 +    DIR *dir;
 +#endif
  } FileContext;
  
  static const AVOption file_options[] = {
 -    { "truncate", "Truncate existing files on write", offsetof(FileContext, trunc), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
 +    { "truncate", "truncate existing files on write", offsetof(FileContext, trunc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
 +    { "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 },
+     { "follow", "Follow a file as it is being written", offsetof(FileContext, follow), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
      { NULL }
  };
  
@@@ -105,9 -61,9 +107,11 @@@ static const AVClass pipe_class = 
  static int file_read(URLContext *h, unsigned char *buf, int size)
  {
      FileContext *c = h->priv_data;
 -    int ret = read(c->fd, buf, size);
 +    int ret;
 +    size = FFMIN(size, c->blocksize);
 +    ret = read(c->fd, buf, size);
+     if (ret == 0 && c->follow)
+         return AVERROR(EAGAIN);
      return (ret == -1) ? AVERROR(errno) : ret;
  }
  
diff --cc libavformat/version.h
index 93b87eb,aae1e23..5141b5b
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@@ -29,9 -29,9 +29,9 @@@
  
  #include "libavutil/version.h"
  
 -#define LIBAVFORMAT_VERSION_MAJOR 57
 -#define LIBAVFORMAT_VERSION_MINOR  5
 -#define LIBAVFORMAT_VERSION_MICRO  2
 +#define LIBAVFORMAT_VERSION_MAJOR  57
 +#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, \



More information about the ffmpeg-cvslog mailing list