[FFmpeg-devel] [PATCH]Add an ignore_delay option to the gif demuxer

Carl Eugen Hoyos cehoyos at ag.or.at
Sat Mar 28 17:47:52 CET 2015


On Friday 27 March 2015 02:45:22 pm Michael Niedermayer wrote:
> On Fri, Mar 27, 2015 at 08:07:23AM +0000, Carl Eugen Hoyos wrote:
> > Michael Niedermayer <michaelni <at> gmx.at> writes:
> > > On Fri, Mar 27, 2015 at 12:21:00AM +0000, Carl Eugen Hoyos wrote:
> > > > Michael Niedermayer <michaelni <at> gmx.at> writes:
> > > > > iam not sure the default of 6 seconds is safe
> > > >
> > > > What would be a sensible default max_delay?
> > >
> > > for this file simply considering 0xFFFF as 0 would work
> > > and would so i think only replacing that would be the
> > > least change needed
> >
> > I did not find any specification that suggests to do this
> > (but many pages were 0xFFFF is explicitely mentioned as
> > allowing for maximum delay).
>
> one could add a option like max_delay which is then used in place
> of 0xFFFF, conforming to the spec if taken litterally

I attached a new version of the patch that does not change the 
current behaviour but gives users a chance to play long gifs in 
real-time.

> The only reason i can imagine a file would be using the "max delay"
> would be to wait for user input before displaying the next frame
> i thought thats not the reason for this file though but i might be
> wrong

Imo, the main reason to use "max delay" is if the creator wants a 
frame to be shown for more than ten minutes.

Carl Eugen
-------------- next part --------------
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 11dfe1b..289787d 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -205,6 +205,11 @@ It accepts the following options:
 Set the minimum valid delay between frames in hundredths of seconds.
 Range is 0 to 6000. Default value is 2.
 
+ at item max_gif_delay
+Set the maximum valid delay between frames in hundredth of seconds.
+Range is 0 to 65535. Default value is 65535, the maximum value
+allowed by the specification.
+
 @item default_delay
 Set the default delay between frames in hundredths of seconds.
 Range is 0 to 6000. Default value is 10.
diff --git a/libavformat/gifdec.c b/libavformat/gifdec.c
index 7db5a27..bb4c6ec 100644
--- a/libavformat/gifdec.c
+++ b/libavformat/gifdec.c
@@ -43,6 +43,7 @@ typedef struct GIFDemuxContext {
      * invalid and set to value of default_delay.
      */
     int min_delay;
+    int max_delay;
     int default_delay;
 
     /**
@@ -159,6 +160,7 @@ static int gif_read_ext(AVFormatContext *s)
 
         if (gdc->delay < gdc->min_delay)
             gdc->delay = gdc->default_delay;
+        gdc->delay = FFMIN(gdc->delay, gdc->max_delay);
 
         /* skip the rest of the Graphic Control Extension block */
         if ((ret = avio_skip(pb, sb_size - 3)) < 0 )
@@ -309,6 +311,7 @@ resync:
 
 static const AVOption options[] = {
     { "min_delay"    , "minimum valid delay between frames (in hundredths of second)", offsetof(GIFDemuxContext, min_delay)    , AV_OPT_TYPE_INT, {.i64 = GIF_MIN_DELAY}    , 0, 100 * 60, AV_OPT_FLAG_DECODING_PARAM },
+    { "max_gif_delay", "maximum valid delay between frames (in hundredths of seconds)", offsetof(GIFDemuxContext, max_delay)   , AV_OPT_TYPE_INT, {.i64 = 65535}            , 0, 65535   , AV_OPT_FLAG_DECODING_PARAM },
     { "default_delay", "default delay between frames (in hundredths of second)"      , offsetof(GIFDemuxContext, default_delay), AV_OPT_TYPE_INT, {.i64 = GIF_DEFAULT_DELAY}, 0, 100 * 60, AV_OPT_FLAG_DECODING_PARAM },
     { "ignore_loop"  , "ignore loop setting (netscape extension)"                    , offsetof(GIFDemuxContext, ignore_loop)  , AV_OPT_TYPE_INT, {.i64 = 1}                , 0,        1, AV_OPT_FLAG_DECODING_PARAM },
     { NULL },


More information about the ffmpeg-devel mailing list