FFmpeg: libavformat/gifdec.c Source File
Go to the documentation of this file. 1 /*
2 * GIF demuxer
3 * Copyright (c) 2012 Vitaliy E Sugrobov
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
22 /**
23 * @file
24 * GIF demuxer.
25 */
26
35
36 #define GIF_PACKET_SIZE 1024
37
40 /**
41 * Time span in hundredths of second before
42 * the next frame should be drawn on screen.
43 */
45 /**
46 * Minimum allowed delay between frames in hundredths of
47 * second. Values below this threshold considered to be
48 * invalid and set to value of default_delay.
49 */
53
54 /**
55 * loop options
56 */
61
62 /**
63 * Major web browsers display gifs at ~10-15fps when rate
64 * is not explicitly set or have too low values. We assume default rate to be 10.
65 * Default delay = 100hundredths of second / 10fps = 10hos per frame.
66 */
67 #define GIF_DEFAULT_DELAY 10
68 /**
69 * By default delay values less than this threshold considered to be invalid.
70 */
71 #define GIF_MIN_DELAY 2
72
74 {
75 /* check magick */
77 return 0;
78
79 /* width or height contains zero? */
81 return 0;
82
84 }
85
87 {
91
92 for (
int i = 0;
i < 6;
i++) {
98 }
99 return 0;
100 }
101
103 {
104 int sb_size,
ret = 0;
105
106 while (0x00 != (sb_size =
avio_r8(pb))) {
109 }
110
112 }
113
115 {
121
124
132
135
137 if (!st)
139
142
145
148 break;
152 AVBPrint bp;
153 int block_size;
154
156 while ((block_size =
avio_r8(pb)) != 0) {
158 }
163
164 if (block_size == 4) {
165 int delay;
166
172 } else {
174 }
178 int sb_size;
179
182 if (
ret < 0 || !sb_size)
183 break;
184
188 if (
ret < 0 || !sb_size)
189 break;
190
191 if (sb_size == 3 &&
data[0] == 1) {
194
197 }
198 }
200 } else {
202 }
210 nb_frames++;
211 } else {
212 break;
213 }
214 }
215
217 /* jump to start because gif decoder needs header data too */
220
221 /* GIF format operates with time in "hundredths of second",
222 * therefore timebase is 1/100 */
229 if (nb_frames > 1) {
231 100,
duration / nb_frames, INT_MAX);
234 }
238 if (n)
240
241 return 0;
242 }
243
245 {
249
254 }
257
264 }
267 }
268
275 };
276
283 };
284
289 .p.extensions = "gif",
295 };
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_BPRINT_SIZE_UNLIMITED
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVMediaType codec_type
General type of the encoded data.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_EOF
End of file.
AVRational avg_frame_rate
Average framerate.
#define GIF_GCE_EXT_LABEL
#define GIF_COM_EXT_LABEL
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
int64_t duration
Decoding: duration of the stream, in stream time base.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
unsigned int avio_rl16(AVIOContext *s)
static const uint8_t gif89a_sig[6]
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
int min_delay
Minimum allowed delay between frames in hundredths of second.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
int avio_read_to_bprint(AVIOContext *h, struct AVBPrint *pb, size_t max_size)
Read contents of h into print buffer, up to max_size bytes, or up to EOF.
AVRational sample_aspect_ratio
Video only.
#define GIF_IMAGE_SEPARATOR
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
@ AV_CLASS_CATEGORY_DEMUXER
enum AVStreamParseType need_parsing
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
const char * av_default_item_name(void *ptr)
Return the context name.
This structure contains the data a format has to probe a file.
int64_t nb_frames
number of frames in this stream if known or 0
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
static AVRational av_make_q(int num, int den)
Create an AVRational.
int avio_r8(AVIOContext *s)
int total_iter
loop options
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
static int read_header(FFV1Context *f, RangeCoder *c)
#define i(width, name, range_min, range_max)
static const uint8_t gif87a_sig[6]
#define GIF_EXTENSION_INTRODUCER
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int delay
Time span in hundredths of second before the next frame should be drawn on screen.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
@ AV_OPT_TYPE_INT
Underlying C type is int.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
static int read_probe(const AVProbeData *p)
#define GIF_APP_EXT_LABEL
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int64_t pos
byte position in stream, -1 if unknown
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Generated on Sat Oct 18 2025 19:22:05 for FFmpeg by
doxygen
1.8.17