[FFmpeg-devel] [PATCH/WIP] lavf/gif: fix timing.

Clément Bœsch ubitux at gmail.com
Thu Apr 18 15:14:43 CEST 2013


---
Delay between frames in GIF are expressed in ms, or 1/100.
Unfortunately, I need to use 1/1000 and rescale manually the
pkt->duration because they are otherwise incorrect: using
avpriv_set_pts_info(..., 1, 100) leads to pkt->duration=1 for any rate.

Can be reproduced with -f lavfi testsrc=r={1,10,30,100...} or -r option
with a random input.

Any idea what could cause this?

Note: patch as WIP for this reason and the required FATE update.
---
 libavformat/gif.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/libavformat/gif.c b/libavformat/gif.c
index 3d86f23..0a94a26 100644
--- a/libavformat/gif.c
+++ b/libavformat/gif.c
@@ -22,6 +22,7 @@
  */
 
 #include "avformat.h"
+#include "internal.h"
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/log.h"
@@ -89,6 +90,7 @@ static int gif_write_header(AVFormatContext *s)
     width  = video_enc->width;
     height = video_enc->height;
 
+    avpriv_set_pts_info(s->streams[0], 64, 1, 1000);
     if (avpriv_set_systematic_pal2(palette, video_enc->pix_fmt) < 0) {
         av_assert0(video_enc->pix_fmt == AV_PIX_FMT_PAL8);
         gif_image_write_header(pb, width, height, gif->loop, NULL);
@@ -102,25 +104,14 @@ static int gif_write_header(AVFormatContext *s)
 
 static int gif_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
-    AVCodecContext *enc = s->streams[pkt->stream_index]->codec;
     AVIOContext *pb = s->pb;
-    int jiffies;
 
     /* graphic control extension block */
     avio_w8(pb, 0x21);
     avio_w8(pb, 0xf9);
     avio_w8(pb, 0x04); /* block size */
     avio_w8(pb, 0x04); /* flags */
-
-    /* 1 jiffy is 1/70 s */
-    /* the delay_time field indicates the number of jiffies - 1 */
-    /* XXX: should use delay, in order to be more accurate */
-    /* instead of using the same rounded value each time */
-    /* XXX: don't even remember if I really use it for now */
-    jiffies = (70 * enc->time_base.num / enc->time_base.den) - 1;
-
-    avio_wl16(pb, jiffies);
-
+    avio_wl16(pb, av_clip_uint16(pkt->duration / 10));
     avio_w8(pb, 0x1f); /* transparent color index */
     avio_w8(pb, 0x00);
 
-- 
1.8.2.1



More information about the ffmpeg-devel mailing list