From: Paul B Mahol <onemda@gmail.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avcodec/gif: fix duration of last packet/frame
Date: Tue, 23 Aug 2022 11:56:38 +0200
Message-ID: <CAPYw7P6hxe_Awcd5bAahCwHQREwWt-u1o1nhA5VzsK9vbpi6hg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 21 bytes --]
Hi,
patch attached.
[-- Attachment #2: 0001-avcodec-gif-fix-duration-of-last-packet-frame.patch --]
[-- Type: text/x-patch, Size: 3919 bytes --]
From f126c6ef9e5fa8b51272508af6603f05c26a3f26 Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Tue, 23 Aug 2022 11:51:24 +0200
Subject: [PATCH] avcodec/gif: fix duration of last packet/frame
Fixes #6294
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
libavcodec/gif.c | 2 ++
libavformat/gif.c | 33 +++++++--------------------------
2 files changed, 9 insertions(+), 26 deletions(-)
diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index 8e84b79b8c..2484cc92e2 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -513,6 +513,8 @@ static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
return ret;
}
+ pkt->duration = av_rescale_q(pict->duration, (AVRational){ 1, 100 },
+ avctx->time_base);
pkt->size = outbuf_ptr - pkt->data;
if (s->image || !avctx->frame_number)
pkt->flags |= AV_PKT_FLAG_KEY;
diff --git a/libavformat/gif.c b/libavformat/gif.c
index b52ff4dd39..afb5767541 100644
--- a/libavformat/gif.c
+++ b/libavformat/gif.c
@@ -36,7 +36,6 @@ typedef struct GIFContext {
int duration;
int64_t last_pos;
int have_end;
- AVPacket *prev_pkt;
} GIFContext;
static int gif_write_header(AVFormatContext *s)
@@ -81,28 +80,20 @@ static int gif_parse_packet(AVFormatContext *s, const uint8_t *data, int size)
return 0;
}
-static int gif_get_delay(GIFContext *gif, AVPacket *prev, AVPacket *new)
+static int gif_get_delay(GIFContext *gif, AVPacket *pkt)
{
- if (new && new->pts != AV_NOPTS_VALUE)
- gif->duration = av_clip_uint16(new->pts - prev->pts);
- else if (!new && gif->last_delay >= 0)
+ if (pkt->duration != 0)
+ gif->duration = av_clip_uint16(pkt->duration);
+ else if (!pkt && gif->last_delay >= 0)
gif->duration = gif->last_delay;
return gif->duration;
}
-static int gif_write_packet(AVFormatContext *s, AVPacket *new_pkt)
+static int gif_write_packet(AVFormatContext *s, AVPacket *pkt)
{
GIFContext *gif = s->priv_data;
AVIOContext *pb = s->pb;
- AVPacket *pkt = gif->prev_pkt;
-
- if (!gif->prev_pkt) {
- gif->prev_pkt = av_packet_alloc();
- if (!gif->prev_pkt)
- return AVERROR(ENOMEM);
- return av_packet_ref(gif->prev_pkt, new_pkt);
- }
gif->last_pos = avio_tell(pb);
if (pkt->size > 0)
@@ -144,7 +135,7 @@ static int gif_write_packet(AVFormatContext *s, AVPacket *new_pkt)
delay_pos = gif_parse_packet(s, pkt->data + off, pkt->size - off);
if (delay_pos > 0 && delay_pos < pkt->size - off - 2) {
avio_write(pb, pkt->data + off, delay_pos);
- avio_wl16(pb, gif_get_delay(gif, pkt, new_pkt));
+ avio_wl16(pb, gif_get_delay(gif, pkt));
avio_write(pb, pkt->data + off + delay_pos + 2, pkt->size - off - delay_pos - 2);
} else {
avio_write(pb, pkt->data + off, pkt->size - off);
@@ -154,17 +145,13 @@ static int gif_write_packet(AVFormatContext *s, AVPacket *new_pkt)
if (delay_pos > 0 && delay_pos < pkt->size - 2) {
avio_write(pb, pkt->data, delay_pos);
- avio_wl16(pb, gif_get_delay(gif, pkt, new_pkt));
+ avio_wl16(pb, gif_get_delay(gif, pkt));
avio_write(pb, pkt->data + delay_pos + 2, pkt->size - delay_pos - 2);
} else {
avio_write(pb, pkt->data, pkt->size);
}
}
- av_packet_unref(gif->prev_pkt);
- if (new_pkt)
- return av_packet_ref(gif->prev_pkt, new_pkt);
-
return 0;
}
@@ -173,14 +160,8 @@ static int gif_write_trailer(AVFormatContext *s)
GIFContext *gif = s->priv_data;
AVIOContext *pb = s->pb;
- if (!gif->prev_pkt)
- return AVERROR(EINVAL);
-
- gif_write_packet(s, NULL);
-
if (!gif->have_end)
avio_w8(pb, GIF_TRAILER);
- av_packet_free(&gif->prev_pkt);
return 0;
}
--
2.37.2
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2022-08-23 9:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-23 9:56 Paul B Mahol [this message]
2022-08-23 12:18 ` Andreas Rheinhardt
2022-08-23 12:36 ` Paul B Mahol
2022-08-23 12:37 ` Andreas Rheinhardt
2022-08-24 16:15 ` Tomas Härdin
2022-08-24 16:23 ` Paul B Mahol
2022-08-23 12:56 ` Andreas Rheinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPYw7P6hxe_Awcd5bAahCwHQREwWt-u1o1nhA5VzsK9vbpi6hg@mail.gmail.com \
--to=onemda@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git