[FFmpeg-devel] [PATCH/WIP] lavf/gif: fix timing.
Clément Bœsch
ubitux at gmail.com
Thu Apr 18 19:53:16 CEST 2013
On Thu, Apr 18, 2013 at 03:14:43PM +0200, Clément Bœsch wrote:
> ---
> 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.
19:33:53 < michaelni> ubitux, iam not sure your use of duration in the muxer is a good idea
19:34:15 < michaelni> currently its set from ff_compute_frame_duration()
19:34:52 < michaelni> so its not the actual durations just values based on frame rate
So delay is now done with just pkt->pts diff.
I'll apply this patch on top of the gif FATE test patch, so FATE unchanged
in the current version.
--
Clément B.
-------------- next part --------------
From ef07177e13f6e69fd1bb46ed7adc35ae59d97587 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Thu, 18 Apr 2013 15:09:37 +0200
Subject: [PATCH] lavf/gif: fix timing.
pkt->duration can not be used since the values are only based on frame
rate.
---
libavformat/gif.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/libavformat/gif.c b/libavformat/gif.c
index 3d86f23..92a94d3 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"
@@ -67,6 +68,7 @@ static int gif_image_write_header(AVIOContext *pb, int width, int height,
typedef struct {
AVClass *class; /** Class for private options. */
int loop;
+ int64_t prev_pts;
} GIFContext;
static int gif_write_header(AVFormatContext *s)
@@ -89,6 +91,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, 100);
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 +105,19 @@ static int gif_write_header(AVFormatContext *s)
static int gif_write_packet(AVFormatContext *s, AVPacket *pkt)
{
- AVCodecContext *enc = s->streams[pkt->stream_index]->codec;
+ GIFContext *gif = s->priv_data;
AVIOContext *pb = s->pb;
- int jiffies;
+ int duration;
+
+ duration = pkt->pts == AV_NOPTS_VALUE ? 0 : av_clip_uint16(pkt->pts - gif->prev_pts);
+ gif->prev_pts = pkt->pts;
/* 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, duration);
avio_w8(pb, 0x1f); /* transparent color index */
avio_w8(pb, 0x00);
@@ -165,4 +162,5 @@ AVOutputFormat ff_gif_muxer = {
.write_packet = gif_write_packet,
.write_trailer = gif_write_trailer,
.priv_class = &gif_muxer_class,
+ .flags = AVFMT_VARIABLE_FPS,
};
--
1.8.2.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130418/b9b83995/attachment.asc>
More information about the ffmpeg-devel
mailing list