[FFmpeg-cvslog] lavf/img2dec: add and document pattern_type option

Stefano Sabatini git at videolan.org
Thu Aug 9 00:22:49 CEST 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Mon Aug  6 14:54:06 2012 +0200| [3a06ea843656891fdb4d1072d9df2d5c3c9426f5] | committer: Stefano Sabatini

lavf/img2dec: add and document pattern_type option

Allow to override the default 'glob_sequence' value, which is deprecated
in favor of the new 'glob' and 'sequence' options.

The new pattern types should be easier on the user since they are more
predictable than 'glob_sequence', and do not require awkward escaping.

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

 doc/demuxers.texi     |   83 ++++++++++++++++++++++++++++++++++++++-----------
 libavformat/img2dec.c |   36 +++++++++++++++++++--
 libavformat/version.h |    2 +-
 3 files changed, 100 insertions(+), 21 deletions(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index f97c1ef..aea4c54 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -23,8 +23,31 @@ The description of some of the currently available demuxers follows.
 Image file demuxer.
 
 This demuxer reads from a list of image files specified by a pattern.
+The syntax and meaning of the pattern is specified by the
+option @var{pattern_type}.
 
-The pattern may contain the string "%d" or "%0 at var{N}d", which
+The pattern may contain a suffix which is used to automatically
+determine the format of the images contained in the files.
+
+The size, the pixel format, and the format of each image must be the
+same for all the files in the sequence.
+
+This demuxer accepts the following options:
+ at table @option
+ at item framerate
+Set the framerate for the video stream. It defaults to 25.
+ at item loop
+If set to 1, loop over the input. Default value is 0.
+ at item pattern_type
+Select the pattern type used to interpret the provided filename.
+
+ at var{pattern_type} accepts one of the following values.
+ at table @option
+ at item sequence
+Select a sequence pattern type, used to specify a sequence of files
+indexed by sequential numbers.
+
+A sequence pattern may contain the string "%d" or "%0 at var{N}d", which
 specifies the position of the characters representing a sequential
 number in each filename matched by the pattern. If the form
 "%d0 at var{N}d" is used, the string representing the number in each
@@ -32,30 +55,54 @@ filename is 0-padded and @var{N} is the total number of 0-padded
 digits representing the number. The literal character '%' can be
 specified in the pattern with the string "%%".
 
-If the pattern contains "%d" or "%0 at var{N}d", the first filename of
+If the sequence pattern contains "%d" or "%0 at var{N}d", the first filename of
 the file list specified by the pattern must contain a number
 inclusively contained between @var{start_number} and
 @var{start_number}+ at var{start_number_range}-1, and all the following
 numbers must be sequential.
 
-The pattern may contain a suffix which is used to automatically
-determine the format of the images contained in the files.
-
 For example the pattern "img-%03d.bmp" will match a sequence of
 filenames of the form @file{img-001.bmp}, @file{img-002.bmp}, ...,
 @file{img-010.bmp}, etc.; the pattern "i%%m%%g-%d.jpg" will match a
 sequence of filenames of the form @file{i%m%g-1.jpg},
 @file{i%m%g-2.jpg}, ..., @file{i%m%g-10.jpg}, etc.
 
-The size, the pixel format, and the format of each image must be the
-same for all the files in the sequence.
+Note that the pattern must not necessarily contain "%d" or
+"%0 at var{N}d", for example to convert a single image file
+ at file{img.jpeg} you can employ the command:
+ at example
+ffmpeg -i img.jpeg img.png
+ at end example
 
-This demuxer accepts the following options:
- at table @option
- at item framerate
-Set the framerate for the video stream. It defaults to 25.
- at item loop
-If set to 1, loop over the input. Default value is 0.
+ at item glob
+Select a glob wildcard pattern type.
+
+The pattern is interpreted like a @code{glob()} pattern. This is only
+selectable if libavformat was compiled with globbing support.
+
+ at item glob_sequence @emph{(deprecated, will be removed)}
+Select a mixed glob wildcard/sequence pattern.
+
+If your version of libavformat was compiled with globbing support, and
+the provided pattern contains at least one glob meta character among
+ at code{%*?[]@{@}} that is preceded by an unescaped "%", the pattern is
+interpreted like a @code{glob()} pattern, otherwise it is interpreted
+like a sequence pattern.
+
+All glob special characters @code{%*?[]@{@}} must be prefixed
+with "%". To escape a literal "%" you shall use "%%".
+
+For example the pattern @code{foo-%*.jpeg} will match all the
+filenames prefixed by "foo-" and terminating with ".jpeg", and
+ at code{foo-%?%?%?.jpeg} will match all the filenames prefixed with
+"foo-", followed by a sequence of three characters, and terminating
+with ".jpeg".
+
+This pattern type is deprecated in favor of @var{glob} and
+ at var{sequence}.
+ at end table
+
+Default value is @var{glob_sequence}.
 @item pixel_format
 Set the pixel format of the images to read. If not specified the pixel
 format is guessed from the first image file in the sequence.
@@ -87,14 +134,14 @@ As above, but start by reading from a file with index 100 in the sequence:
 @example
 ffmpeg -start_number 100 -i 'img-%03d.jpeg' -r 10 out.mkv
 @end example
- at end itemize
 
-Note that the pattern must not necessarily contain "%d" or
-"%0 at var{N}d", for example to convert a single image file
- at file{img.jpeg} you can employ the command:
+ at item
+Read images matching the "*.png" glob pattern , that is all the files
+terminating with the ".png" suffix:
 @example
-ffmpeg -i img.jpeg img.png
+ffmpeg -pattern_type glob -i "*.png" -r 10 out.mkv
 @end example
+ at end itemize
 
 @section applehttp
 
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index b87b5d5..31f1aa0 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -54,6 +54,7 @@ typedef struct {
     char *video_size;       /**< Set by a private option. */
     char *framerate;        /**< Set by a private option. */
     int loop;
+    enum { PT_GLOB_SEQUENCE, PT_GLOB, PT_SEQUENCE } pattern_type;
     int use_glob;
 #if HAVE_GLOB
     glob_t globstate;
@@ -233,12 +234,15 @@ static int read_header(AVFormatContext *s1)
     }
 
     if (!s->is_pipe) {
+        if (s->pattern_type == PT_GLOB_SEQUENCE) {
         s->use_glob = is_glob(s->path);
         if (s->use_glob) {
-#if HAVE_GLOB
             char *p = s->path, *q, *dup;
             int gerr;
 
+            av_log(s1, AV_LOG_WARNING, "Pattern type 'glob_sequence' is deprecated: "
+                   "use pattern_type 'glob' instead\n");
+#if HAVE_GLOB
             dup = q = av_strdup(p);
             while (*q) {
                 /* Do we have room for the next char and a \ insertion? */
@@ -260,7 +264,9 @@ static int read_header(AVFormatContext *s1)
             first_index = 0;
             last_index = s->globstate.gl_pathc - 1;
 #endif
-        } else {
+        }
+        }
+        if ((s->pattern_type == PT_GLOB_SEQUENCE && !s->use_glob) || s->pattern_type == PT_SEQUENCE) {
             if (find_image_range(&first_index, &last_index, s->path,
                                  s->start_number, s->start_number_range) < 0) {
                 av_log(s1, AV_LOG_ERROR,
@@ -268,6 +274,26 @@ static int read_header(AVFormatContext *s1)
                        s->path, s->start_number, s->start_number + s->start_number_range - 1);
                 return AVERROR(ENOENT);
             }
+        } else if (s->pattern_type == PT_GLOB) {
+#if HAVE_GLOB
+            int gerr;
+            gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
+            if (gerr != 0) {
+                return AVERROR(ENOENT);
+            }
+            first_index = 0;
+            last_index = s->globstate.gl_pathc - 1;
+            s->use_glob = 1;
+#else
+            av_log(s1, AV_LOG_ERROR,
+                   "Pattern type 'glob' was selected but globbing "
+                   "is not supported by this libavformat build\n");
+            return AVERROR(ENOSYS);
+#endif
+        } else if (s->pattern_type != PT_GLOB_SEQUENCE) {
+            av_log(s1, AV_LOG_ERROR,
+                   "Unknown value '%d' for pattern_type option\n", s->pattern_type);
+            return AVERROR(EINVAL);
         }
         s->img_first = first_index;
         s->img_last = last_index;
@@ -388,6 +414,12 @@ static int read_close(struct AVFormatContext* s1)
 static const AVOption options[] = {
     { "framerate",    "set the video framerate",             OFFSET(framerate),    AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC },
     { "loop",         "force loop over input file sequence", OFFSET(loop),         AV_OPT_TYPE_INT,    {.dbl = 0},    0, 1, DEC },
+
+    { "pattern_type", "set pattern type",                    OFFSET(pattern_type), AV_OPT_TYPE_INT, {.dbl=PT_GLOB_SEQUENCE}, 0, INT_MAX, DEC, "pattern_type"},
+    { "glob_sequence","glob/sequence pattern type",          0, AV_OPT_TYPE_CONST, {.dbl=PT_GLOB_SEQUENCE}, INT_MIN, INT_MAX, DEC, "pattern_type" },
+    { "glob",         "glob pattern type",                   0, AV_OPT_TYPE_CONST, {.dbl=PT_GLOB},          INT_MIN, INT_MAX, DEC, "pattern_type" },
+    { "sequence",     "glob pattern type",                   0, AV_OPT_TYPE_CONST, {.dbl=PT_SEQUENCE},      INT_MIN, INT_MAX, DEC, "pattern_type" },
+
     { "pixel_format", "set video pixel format",              OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
     { "start_number", "set first number in the sequence",    OFFSET(start_number), AV_OPT_TYPE_INT,    {.dbl = 0},    0, INT_MAX, DEC },
     { "start_number_range", "set range for looking at the first sequence number", OFFSET(start_number_range), AV_OPT_TYPE_INT, {.dbl = 5}, 1, INT_MAX, DEC },
diff --git a/libavformat/version.h b/libavformat/version.h
index 4cda247..ab34b33 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
 
 #define LIBAVFORMAT_VERSION_MAJOR 54
 #define LIBAVFORMAT_VERSION_MINOR 22
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MICRO 102
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list