[FFmpeg-devel] [PATCH] lavf/img2dec: add -pattern_type option
Stefano Sabatini
stefasab at gmail.com
Tue Aug 7 01:59:31 CEST 2012
On date Monday 2012-08-06 15:03:26 +0200, Nicolas George encoded:
> Le decadi 20 thermidor, an CCXX, Stefano Sabatini a écrit :
> > 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.
>
> Thanks!
>
> >
> > FIXME: bump micro before pushing
> > ---
> > libavformat/img2dec.c | 34 +++++++++++++++++++++++++++++++++-
> > 1 files changed, 33 insertions(+), 1 deletions(-)
> >
> > diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
> > index 0443b1a..a108656 100644
> > --- a/libavformat/img2dec.c
> > +++ b/libavformat/img2dec.c
> > @@ -41,6 +41,8 @@
> >
> > #endif /* HAVE_GLOB */
> >
> > +enum PatternType { PT_GLOB_SEQUENCE, PT_GLOB, PT_SEQUENCE };
> > +
> > typedef struct {
> > const AVClass *class; /**< Class for private options. */
> > int img_first;
> > @@ -54,6 +56,7 @@ typedef struct {
> > char *video_size; /**< Set by a private option. */
> > char *framerate; /**< Set by a private option. */
> > int loop;
> > + enum PatternType pattern_type;
> > int use_glob;
> > #if HAVE_GLOB
> > glob_t globstate;
> > @@ -233,6 +236,9 @@ static int read_header(AVFormatContext *s1)
> > }
> >
> > if (!s->is_pipe) {
> > + if (s->pattern_type == PT_GLOB_SEQUENCE) {
> > + av_log(s1, AV_LOG_WARNING, "Pattern type 'glob_sequence' is deprecated: "
> > + "use -pattern_type 'glob' or 'sequence' instead\n");
> > s->use_glob = is_glob(s->path);
> > if (s->use_glob) {
> > #if HAVE_GLOB
> > @@ -260,7 +266,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,7 +276,25 @@ 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) {
> > + int gerr;
>
> > + if (!HAVE_GLOB) {
> > + av_log(s1, AV_LOG_ERROR, "Pattern type 'glob' was selected but is not supported by libavformat\n");
> > + return AVERROR(ENOSYS);
> > + }
> > + gerr = glob(s->path, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate);
>
> Does it build on systems that lack glob? I do not see how it could. My guess
> is it requires #ifdefry.
>
> > + if (gerr != 0) {
> > + return AVERROR(ENOENT);
> > + }
> > + first_index = 0;
> > + last_index = s->globstate.gl_pathc - 1;
> > + s->use_glob = 1;
> > + } 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;
> > s->img_number = first_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 },
>
> You forgot to update the docs.
>
> Apart from that, looks very good, thanks again.
Updated, will send a new patch tomorrow trying to address Alexander's
remarks.
--
FFmpeg = Friendly & Funny Multimedia Political Embarassing Game
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-lavf-img2dec-add-pattern_type-option.patch
Type: text/x-diff
Size: 9093 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120807/9a6ed981/attachment.bin>
More information about the ffmpeg-devel
mailing list