1 /*
2 * webp muxer
3 * Copyright (c) 2014 Michael Niedermayer
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
28
37
39 {
42
44
46
47 return 0;
48 }
49
51 {
54
59 // Safe to do this as a valid WebP bitstream is >=30 bytes.
64 }
65
66 if (
flags & 2)
// ANIMATION_FLAG is on
67 return 1;
68 return 0;
69 }
70
71 /**
72 * Returns 1 if it has written a RIFF header with a correct length field
73 */
75 {
78 uint8_t buf[12 /* RIFF+WEBP */ + 18 /* VP8X */ +
79 14 /* ANIM */ + 24 /* ANMF */], *bufp = buf;
80 int writing_webp_header = 0,
skip = 0;
82 int vp8x = 0;
83
84 if (!
w->last_pkt->size)
85 return 0;
86
89
92 vp8x = 1;
94 }
95
96 if (!
w->wrote_webp_header) {
97 bytestream_put_le32(&bufp,
MKTAG(
'R',
'I',
'F',
'F'));
98 bytestream_put_le32(&bufp, 0); /* Size to be patched later */
99 bytestream_put_le32(&bufp,
MKTAG(
'W',
'E',
'B',
'P'));
100 writing_webp_header = 1;
101 w->wrote_webp_header = 1;
102 if (
w->frame_count > 1)
// first non-empty packet
103 w->frame_count = 1;
// so we don't count previous empty packets.
104 }
105
106 if (
w->frame_count == 1) {
107 if (!trailer) {
108 vp8x = 1;
110 }
111
112 if (vp8x) {
113 bytestream_put_le32(&bufp,
MKTAG(
'V',
'P',
'8',
'X'));
114 bytestream_put_le32(&bufp, 10);
115 bytestream_put_byte(&bufp,
flags);
116 bytestream_put_le24(&bufp, 0);
119 }
120 if (!trailer) {
121 bytestream_put_le32(&bufp,
MKTAG(
'A',
'N',
'I',
'M'));
122 bytestream_put_le32(&bufp, 6);
123 bytestream_put_le32(&bufp, 0xFFFFFFFF);
124 bytestream_put_le16(&bufp,
w->loop);
125 }
126 }
127
128 if (
w->frame_count > trailer) {
129 bytestream_put_le32(&bufp,
MKTAG(
'A',
'N',
'M',
'F'));
130 bytestream_put_le32(&bufp, 16 +
w->last_pkt->size -
skip);
131 bytestream_put_le24(&bufp, 0);
132 bytestream_put_le24(&bufp, 0);
136 bytestream_put_le24(&bufp,
pts -
w->last_pkt->pts);
137 } else
138 bytestream_put_le24(&bufp,
w->last_pkt->duration);
139 bytestream_put_byte(&bufp, 0);
140 }
141 if (trailer && writing_webp_header)
142 AV_WL32(buf + 4, bufp - (buf + 8) +
w->last_pkt->size -
skip);
146
147 return trailer && writing_webp_header;
148 }
149
151 {
154
156 return 0;
160 w->using_webp_anim_encoder |=
ret;
161
162 if (
w->using_webp_anim_encoder) {
164 w->wrote_webp_header = 1;
// for good measure
165 } else {
170 }
172
173 return 0;
174 }
175
177 {
180
181 if (
w->using_webp_anim_encoder) {
182 if (
w->loop) {
// Write loop count.
185 }
186 } else {
190
195 // Note: without the following, avio only writes 8 bytes to the file.
197 }
198 }
199 }
200
201 return 0;
202 }
203
204 #define OFFSET(x) offsetof(WebpContext, x)
205 #define ENC AV_OPT_FLAG_ENCODING_PARAM
207 {
"loop",
"Number of times to loop the output: 0 - infinite loop",
OFFSET(
loop),
210 };
211
217 };
221 .p.extensions = "webp",
233 };