Commit 3a06ea84 authored by Stefano Sabatini's avatar 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.
parent 0325e01f
......@@ -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@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:
@table @option
@item framerate
Set the framerate for the video stream. It defaults to 25.
@item loop
If set to 1, loop over the input. Default value is 0.
@item pattern_type
Select the pattern type used to interpret the provided filename.
@var{pattern_type} accepts one of the following values.
@table @option
@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@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@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@var{N}d", the first filename of
If the sequence pattern contains "%d" or "%0@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}+@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@var{N}d", for example to convert a single image file
@file{img.jpeg} you can employ the command:
@example
ffmpeg -i img.jpeg img.png
@end example
This demuxer accepts the following options:
@table @option
@item framerate
Set the framerate for the video stream. It defaults to 25.
@item loop
If set to 1, loop over the input. Default value is 0.
@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.
@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
@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
@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
@var{sequence}.
@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
@end itemize
Note that the pattern must not necessarily contain "%d" or
"%0@var{N}d", for example to convert a single image file
@file{img.jpeg} you can employ the command:
@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
@end itemize
@section applehttp
......
......@@ -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 },
......
......@@ -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, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment