64 uint8_t *buf,
size_t length)
74 crc =
av_crc(crc_table, crc, tagbuf, 4);
77 crc =
av_crc(crc_table, crc, buf, length);
92 "Last frame delay is too precise. Reducing to %d/%d (%f).\n",
115 uint8_t *side_data =
NULL;
116 size_t side_data_size;
122 if (side_data_size) {
132 const uint8_t *existing_acTL_chunk;
133 const uint8_t *existing_fcTL_chunk;
135 av_log(format_context,
AV_LOG_INFO,
"Only a single frame so saving as a normal PNG.\n");
139 if (existing_acTL_chunk) {
140 const uint8_t *chunk_after_acTL = existing_acTL_chunk +
AV_RB32(existing_acTL_chunk) + 12;
149 if (existing_fcTL_chunk) {
150 const uint8_t *chunk_after_fcTL = existing_fcTL_chunk +
AV_RB32(existing_fcTL_chunk) + 12;
157 const uint8_t *
data, *data_end;
158 const uint8_t *existing_fcTL_chunk;
161 const uint8_t *existing_acTL_chunk;
167 if (!existing_acTL_chunk) {
180 if (existing_fcTL_chunk) {
186 existing_fcTL_chunk += 8;
187 delay.
num =
AV_RB16(existing_fcTL_chunk + 20);
188 delay.
den =
AV_RB16(existing_fcTL_chunk + 22);
190 if (delay.
num == 0 && delay.
den == 0) {
196 if (!
av_reduce(&delay.
num, &delay.
den, delay_num_raw, delay_den_raw, UINT16_MAX) &&
199 "Frame rate is too high or specified too precisely. Unable to copy losslessly.\n");
211 memcpy(new_fcTL_chunk, existing_fcTL_chunk,
sizeof(new_fcTL_chunk));
215 new_fcTL_chunk,
sizeof(new_fcTL_chunk));
286#define OFFSET(x) offsetof(APNGMuxContext, x)
287#define ENC AV_OPT_FLAG_ENCODING_PARAM
289 {
"plays",
"Number of times to play the output: 0 - infinite loop, 1 - no loop",
OFFSET(plays),
291 {
"final_delay",
"Force delay after the last frame",
OFFSET(last_delay),
297 .class_name =
"APNG muxer",
306 .p.mime_type =
"image/png",
307 .p.extensions =
"apng",
#define APNG_FCTL_CHUNK_SIZE
static void apng_deinit(AVFormatContext *s)
static int apng_write_trailer(AVFormatContext *format_context)
static int apng_write_packet(AVFormatContext *format_context, AVPacket *packet)
static const uint8_t * apng_find_chunk(uint32_t tag, const uint8_t *buf, size_t length)
static const AVClass apng_muxer_class
static int apng_write_header(AVFormatContext *format_context)
static void apng_write_chunk(AVIOContext *io_context, uint32_t tag, uint8_t *buf, size_t length)
static int flush_packet(AVFormatContext *format_context, AVPacket *packet)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
void avio_wb32(AVIOContext *s, unsigned int val)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
void avio_wb64(AVIOContext *s, uint64_t val)
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Public header for CRC hash function implementation.
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT
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.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#define LIBAVUTIL_VERSION_INT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define MKBETAG(a, b, c, d)
Memory handling functions.
#define FF_OFMT_FLAG_MAX_ONE_OF_EACH
If this flag is set, it indicates that for each codec type whose corresponding default codec (i....
#define FF_OFMT_FLAG_ONLY_DEFAULT_CODECS
If this flag is set, then the only permitted audio/video/subtitle codec ids are AVOutputFormat....
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.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVIOContext * pb
I/O context.
void * priv_data
Format private data.
AVStream ** streams
A list of all streams in the file.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
This structure stores compressed data.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.