41#define DEFAULT_APNG_FPS 15
83 if (bytestream2_get_be64(&gb) !=
PNGSIG)
87 len = bytestream2_get_be32(&gb);
91 tag = bytestream2_get_le32(&gb);
94 if (
tag !=
MKTAG(
'I',
'D',
'A',
'T') &&
99 case MKTAG(
'I',
'H',
'D',
'R'):
107 case MKTAG(
'a',
'c',
'T',
'L'):
110 bytestream2_get_be32(&gb) == 0)
115 case MKTAG(
'I',
'D',
'A',
'T'):
134 uint8_t *new_extradata;
139 new_size = previous_size +
len;
150 return previous_size;
198 if (acTL_found &&
ctx->num_play != 1) {
207 if ((
ctx->num_play == 1 || !acTL_found) &&
212 if (
len > INT_MAX - 12)
217 case MKTAG(
'a',
'c',
'T',
'L'):
225 ctx->num_frames,
ctx->num_play);
227 case MKTAG(
'f',
'c',
'T',
'L'):
245 const char *
name, uint32_t sequence_number)
248 if (
s->io_repositioned) {
249 ctx->expected_seq = sequence_number;
250 s->io_repositioned = 0;
253 if (sequence_number !=
ctx->expected_seq)
255 ", expected %"PRIu32
"\n",
name, sequence_number,
ctx->expected_seq);
257 ctx->expected_seq = sequence_number + 1;
270 uint32_t sequence_number,
width,
height, x_offset, y_offset;
271 uint16_t delay_num, delay_den;
272 uint8_t dispose_op, blend_op;
290 if (!delay_num || (
ctx->max_fps && delay_den / delay_num >
ctx->max_fps)) {
292 delay_den =
ctx->default_fps;
296 s->streams[0]->time_base);
299 "sequence_number: %"PRId32
", "
301 "height: %"PRIu32
", "
302 "x_offset: %"PRIu32
", "
303 "y_offset: %"PRIu32
", "
304 "delay_num: %"PRIu16
", "
305 "delay_den: %"PRIu16
", "
319 if (
width !=
s->streams[0]->codecpar->width ||
320 height !=
s->streams[0]->codecpar->height ||
323 if (sequence_number == 0 ||
324 x_offset >=
s->streams[0]->codecpar->width ||
325 width >
s->streams[0]->codecpar->width - x_offset ||
326 y_offset >=
s->streams[0]->codecpar->height ||
327 height >
s->streams[0]->codecpar->height - y_offset)
329 ctx->is_key_frame = 0;
369 case MKTAG(
'f',
'c',
'T',
'L'):
379 if (
len > 0x7fffffff)
383 if (
tag ==
MKTAG(
'f',
'c',
'T',
'L') ||
395 if (
tag ==
MKTAG(
'f',
'd',
'A',
'T')) {
409 if (
len > 0x7fffffff)
415 if (
tag ==
MKTAG(
'f',
'd',
'A',
'T')) {
429 if (
ctx->is_key_frame)
432 pkt->duration =
ctx->pkt_duration;
434 case MKTAG(
'I',
'E',
'N',
'D'):
436 if (
ctx->ignore_loop ||
ctx->num_play >= 1 &&
ctx->cur_loop ==
ctx->num_play) {
440 ctx->expected_seq = 0;
441 if ((
ret =
avio_seek(pb,
s->streams[0]->codecpar->extradata_size + 8, SEEK_SET)) < 0)
455 {
"ignore_loop",
"ignore loop setting" , offsetof(
APNGDemuxContext, ignore_loop),
457 {
"max_fps" ,
"maximum framerate (0 is no limit)" , offsetof(
APNGDemuxContext, max_fps),
459 {
"default_fps",
"default framerate (0 is as fast as possible)", offsetof(
APNGDemuxContext, default_fps),
465 .class_name =
"APNG demuxer",
static AVFormatContext * ctx
#define APNG_FCTL_CHUNK_SIZE
@ APNG_DISPOSE_OP_BACKGROUND
@ APNG_DISPOSE_OP_PREVIOUS
static int apng_read_header(AVFormatContext *s)
static int decode_fctl_chunk(AVFormatContext *s, APNGDemuxContext *ctx)
static int apng_probe(const AVProbeData *p)
static const AVClass demuxer_class
static int append_extradata(AVCodecParameters *par, AVIOContext *pb, int len)
static void check_fdat_chunk(AVFormatContext *s, APNGDemuxContext *ctx, AVPacket *pkt, uint32_t len)
static void check_chunk_sequence(AVFormatContext *s, APNGDemuxContext *ctx, const char *name, uint32_t sequence_number)
static int apng_read_packet(AVFormatContext *s, AVPacket *pkt)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
uint64_t avio_rb64(AVIOContext *s)
int64_t avio_size(AVIOContext *s)
Get the filesize.
unsigned int avio_rb16(AVIOContext *s)
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
unsigned int avio_rl32(AVIOContext *s)
unsigned int avio_rb32(AVIOContext *s)
int avio_r8(AVIOContext *s)
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static int read_probe(const AVProbeData *p)
static int read_header(FFV1Context *f, RangeCoder *c)
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define av_fourcc2str(fourcc)
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define LIBAVUTIL_VERSION_INT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AV_CLASS_CATEGORY_DEMUXER
#define MKTAG(a, b, c, d)
Memory handling functions.
Describe the class of an AVClass context structure.
This struct describes the properties of an encoded stream.
int extradata_size
Size of the extradata content in bytes.
int height
The height of the video frame in pixels.
int width
The width of the video frame in pixels.
enum AVMediaType codec_type
General type of the encoded data.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
This structure contains the data a format has to probe a file.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define avpriv_request_sample(...)
static struct @232240247175332074307271266321204261331170211232 state