On Wed, May 20, 2015 at 12:39 PM Michael Niedermayer <michae...@gmx.at> wrote:
> On Wed, May 20, 2015 at 01:56:17AM +0000, Urvang Joshi wrote: > > This is 1st out of 3 patches. > > Attached. > > > webpenc.c | 63 > +++++++++++++++++++++++++++++++++++++++++++++----------------- > > 1 file changed, 46 insertions(+), 17 deletions(-) > > ee0eae792572bbcce5b6ce0e982e1347f0241418 > 1.WebP-muxer-support-a-packet-containing-animated-WebP.patch > > From a47778d6b0514097668881c9d2f5ecbfce5970a3 Mon Sep 17 00:00:00 2001 > > From: Urvang Joshi <urv...@google.com> > > Date: Tue, 19 May 2015 17:39:54 -0700 > > Subject: [PATCH] WebP muxer: support a packet containing animated WebP. > > > > This is the 1st patch in preparation for using WebPAnimEncoder API for > encoding > > and muxing WebP images. > > this breaks the code > > > ./ffmpeg -i lena.pnm test.webp > vwebp test.webp > "Input file doesn't appear to be WebP format." > Thanks for catching! Here's an updated patch which works for static images too. > > [...] > > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > In a rich man's house there is no place to spit but his face. > -- Diogenes of Sinope > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >
From ebca78a25a96bc172cc4de58f488b912ba20e220 Mon Sep 17 00:00:00 2001 From: Urvang Joshi <urv...@google.com> Date: Tue, 19 May 2015 17:39:54 -0700 Subject: [PATCH] WebP muxer: support a packet containing animated WebP. This is the 1st patch in preparation for using WebPAnimEncoder API for encoding and muxing WebP images. --- libavformat/webpenc.c | 69 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c index ee110de..8a5a5ce 100644 --- a/libavformat/webpenc.c +++ b/libavformat/webpenc.c @@ -29,6 +29,8 @@ typedef struct WebpContext{ int frame_count; AVPacket last_pkt; int loop; + int wrote_webp_header; + int using_webp_anim_encoder; } WebpContext; static int webp_write_header(AVFormatContext *s) @@ -46,8 +48,24 @@ static int webp_write_header(AVFormatContext *s) } avpriv_set_pts_info(st, 24, 1, 1000); - avio_write(s->pb, "RIFF\0\0\0\0WEBP", 12); + return 0; +} + +static int is_animated_webp_packet(AVPacket *pkt) +{ + if (pkt->size) { + int skip = 0; + unsigned flags = 0; + + if (AV_RL32(pkt->data) == AV_RL32("RIFF")) + skip = 12; + if (AV_RL32(pkt->data + skip) == AV_RL32("VP8X")) { + flags |= pkt->data[skip + 4 + 4]; + } + if (flags & 2) // ANIMATION_FLAG is on + return 1; + } return 0; } @@ -69,7 +87,12 @@ static int flush(AVFormatContext *s, int trailer, int64_t pts) skip += AV_RL32(w->last_pkt.data + skip + 4) + 8; } - w->frame_count ++; + if (!w->wrote_webp_header) { + avio_write(s->pb, "RIFF\0\0\0\0WEBP", 12); + w->wrote_webp_header = 1; + if (w->frame_count > 1) // first non-empty packet + w->frame_count = 1; // so we don't count previous empty packets. + } if (w->frame_count == 1) { if (!trailer) { @@ -116,12 +139,18 @@ static int flush(AVFormatContext *s, int trailer, int64_t pts) static int webp_write_packet(AVFormatContext *s, AVPacket *pkt) { WebpContext *w = s->priv_data; - int ret; - - if ((ret = flush(s, 0, pkt->pts)) < 0) - return ret; - - av_copy_packet(&w->last_pkt, pkt); + w->using_webp_anim_encoder |= is_animated_webp_packet(pkt); + + if (w->using_webp_anim_encoder) { + avio_write(s->pb, pkt->data, pkt->size); + w->wrote_webp_header = 1; // for good measure + } else { + int ret; + if ((ret = flush(s, 0, pkt->pts)) < 0) + return ret; + av_copy_packet(&w->last_pkt, pkt); + } + ++w->frame_count; return 0; } @@ -129,14 +158,24 @@ static int webp_write_packet(AVFormatContext *s, AVPacket *pkt) static int webp_write_trailer(AVFormatContext *s) { unsigned filesize; - int ret; - - if ((ret = flush(s, 1, AV_NOPTS_VALUE)) < 0) - return ret; + WebpContext *w = s->priv_data; - filesize = avio_tell(s->pb); - avio_seek(s->pb, 4, SEEK_SET); - avio_wl32(s->pb, filesize - 8); + if (w->using_webp_anim_encoder) { + if ((w->frame_count > 1) && w->loop) { // Write loop count. + avio_seek(s->pb, 42, SEEK_SET); + avio_wl16(s->pb, w->loop); + } + } else { + int ret; + if ((ret = flush(s, 1, AV_NOPTS_VALUE)) < 0) + return ret; + + filesize = avio_tell(s->pb); + avio_seek(s->pb, 4, SEEK_SET); + avio_wl32(s->pb, filesize - 8); + // Note: without the following, avio only writes 8 bytes to the file. + avio_seek(s->pb, filesize, SEEK_SET); + } return 0; } -- 2.2.0.rc0.207.ga3a616c
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel