3 * Copyright (c) 2003 Fabrice Bellard
5 * This file is part of FFmpeg.
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.
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.
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
24 #include "bytestream.h"
25 #include "huffyuvencdsp.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/crc.h"
31 #include "libavutil/libm.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/color_utils.h"
37 #define IOBUF_SIZE 4096
39 typedef struct PNGEncContext {
41 HuffYUVEncDSPContext hdsp;
44 uint8_t *bytestream_start;
45 uint8_t *bytestream_end;
50 uint8_t buf[IOBUF_SIZE];
51 int dpi; ///< Physical pixel density, in dots per inch, if set
52 int dpm; ///< Physical pixel density, in dots per meter, if set
60 uint32_t palette_checksum; // Used to ensure a single unique palette
61 uint32_t sequence_number;
64 static void png_get_interlaced_row(uint8_t *dst, int row_size,
65 int bits_per_pixel, int pass,
66 const uint8_t *src, int width)
68 int x, mask, dst_x, j, b, bpp;
71 static const int masks[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
74 switch (bits_per_pixel) {
76 memset(dst, 0, row_size);
78 for (x = 0; x < width; x++) {
80 if ((mask << j) & 0x80) {
81 b = (src[x >> 3] >> (7 - j)) & 1;
82 dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
88 bpp = bits_per_pixel >> 3;
91 for (x = 0; x < width; x++) {
93 if ((mask << j) & 0x80) {
103 static void sub_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top,
107 for (i = 0; i < w; i++) {
108 int a, b, c, p, pa, pb, pc;
121 if (pa <= pb && pa <= pc)
131 static void sub_left_prediction(PNGEncContext *c, uint8_t *dst, const uint8_t *src, int bpp, int size)
133 const uint8_t *src1 = src + bpp;
134 const uint8_t *src2 = src;
137 memcpy(dst, src, bpp);
140 unaligned_w = FFMIN(32 - bpp, size);
141 for (x = 0; x < unaligned_w; x++)
142 *dst++ = *src1++ - *src2++;
144 c->hdsp.diff_bytes(dst, src1, src2, size);
147 static void png_filter_row(PNGEncContext *c, uint8_t *dst, int filter_type,
148 uint8_t *src, uint8_t *top, int size, int bpp)
152 switch (filter_type) {
153 case PNG_FILTER_VALUE_NONE:
154 memcpy(dst, src, size);
156 case PNG_FILTER_VALUE_SUB:
157 sub_left_prediction(c, dst, src, bpp, size);
159 case PNG_FILTER_VALUE_UP:
160 c->hdsp.diff_bytes(dst, src, top, size);
162 case PNG_FILTER_VALUE_AVG:
163 for (i = 0; i < bpp; i++)
164 dst[i] = src[i] - (top[i] >> 1);
165 for (; i < size; i++)
166 dst[i] = src[i] - ((src[i - bpp] + top[i]) >> 1);
168 case PNG_FILTER_VALUE_PAETH:
169 for (i = 0; i < bpp; i++)
170 dst[i] = src[i] - top[i];
171 sub_png_paeth_prediction(dst + i, src + i, top + i, size - i, bpp);
176 static uint8_t *png_choose_filter(PNGEncContext *s, uint8_t *dst,
177 uint8_t *src, uint8_t *top, int size, int bpp)
179 int pred = s->filter_type;
180 av_assert0(bpp || !pred);
182 pred = PNG_FILTER_VALUE_SUB;
183 if (pred == PNG_FILTER_VALUE_MIXED) {
185 int cost, bcost = INT_MAX;
186 uint8_t *buf1 = dst, *buf2 = dst + size + 16;
187 for (pred = 0; pred < 5; pred++) {
188 png_filter_row(s, buf1 + 1, pred, src, top, size, bpp);
191 for (i = 0; i <= size; i++)
192 cost += abs((int8_t) buf1[i]);
195 FFSWAP(uint8_t *, buf1, buf2);
200 png_filter_row(s, dst + 1, pred, src, top, size, bpp);
206 static void png_write_chunk(uint8_t **f, uint32_t tag,
207 const uint8_t *buf, int length)
209 const AVCRC *crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
213 bytestream_put_be32(f, length);
214 AV_WL32(tagbuf, tag);
215 crc = av_crc(crc_table, crc, tagbuf, 4);
216 bytestream_put_be32(f, av_bswap32(tag));
218 crc = av_crc(crc_table, crc, buf, length);
219 memcpy(*f, buf, length);
222 bytestream_put_be32(f, ~crc);
225 static void png_write_image_data(AVCodecContext *avctx,
226 const uint8_t *buf, int length)
228 PNGEncContext *s = avctx->priv_data;
229 const AVCRC *crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
232 if (avctx->codec_id == AV_CODEC_ID_PNG || avctx->frame_number == 0) {
233 png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), buf, length);
237 bytestream_put_be32(&s->bytestream, length + 4);
239 bytestream_put_be32(&s->bytestream, MKBETAG('f', 'd', 'A', 'T'));
240 bytestream_put_be32(&s->bytestream, s->sequence_number);
241 crc = av_crc(crc_table, crc, s->bytestream - 8, 8);
243 crc = av_crc(crc_table, crc, buf, length);
244 memcpy(s->bytestream, buf, length);
245 s->bytestream += length;
247 bytestream_put_be32(&s->bytestream, ~crc);
249 ++s->sequence_number;
252 /* XXX: do filtering */
253 static int png_write_row(AVCodecContext *avctx, const uint8_t *data, int size)
255 PNGEncContext *s = avctx->priv_data;
258 s->zstream.avail_in = size;
259 s->zstream.next_in = data;
260 while (s->zstream.avail_in > 0) {
261 ret = deflate(&s->zstream, Z_NO_FLUSH);
264 if (s->zstream.avail_out == 0) {
265 if (s->bytestream_end - s->bytestream > IOBUF_SIZE + 100)
266 png_write_image_data(avctx, s->buf, IOBUF_SIZE);
267 s->zstream.avail_out = IOBUF_SIZE;
268 s->zstream.next_out = s->buf;
274 #define AV_WB32_PNG(buf, n) AV_WB32(buf, lrint((n) * 100000))
275 static int png_get_chrm(enum AVColorPrimaries prim, uint8_t *buf)
277 double rx, ry, gx, gy, bx, by, wx = 0.3127, wy = 0.3290;
279 case AVCOL_PRI_BT709:
280 rx = 0.640; ry = 0.330;
281 gx = 0.300; gy = 0.600;
282 bx = 0.150; by = 0.060;
284 case AVCOL_PRI_BT470M:
285 rx = 0.670; ry = 0.330;
286 gx = 0.210; gy = 0.710;
287 bx = 0.140; by = 0.080;
288 wx = 0.310; wy = 0.316;
290 case AVCOL_PRI_BT470BG:
291 rx = 0.640; ry = 0.330;
292 gx = 0.290; gy = 0.600;
293 bx = 0.150; by = 0.060;
295 case AVCOL_PRI_SMPTE170M:
296 case AVCOL_PRI_SMPTE240M:
297 rx = 0.630; ry = 0.340;
298 gx = 0.310; gy = 0.595;
299 bx = 0.155; by = 0.070;
301 case AVCOL_PRI_BT2020:
302 rx = 0.708; ry = 0.292;
303 gx = 0.170; gy = 0.797;
304 bx = 0.131; by = 0.046;
310 AV_WB32_PNG(buf , wx); AV_WB32_PNG(buf + 4 , wy);
311 AV_WB32_PNG(buf + 8 , rx); AV_WB32_PNG(buf + 12, ry);
312 AV_WB32_PNG(buf + 16, gx); AV_WB32_PNG(buf + 20, gy);
313 AV_WB32_PNG(buf + 24, bx); AV_WB32_PNG(buf + 28, by);
317 static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf)
319 double gamma = avpriv_get_gamma_from_trc(trc);
323 AV_WB32_PNG(buf, 1.0 / gamma);
327 static int encode_headers(AVCodecContext *avctx, const AVFrame *pict)
329 PNGEncContext *s = avctx->priv_data;
331 /* write png header */
332 AV_WB32(s->buf, avctx->width);
333 AV_WB32(s->buf + 4, avctx->height);
334 s->buf[8] = s->bit_depth;
335 s->buf[9] = s->color_type;
336 s->buf[10] = 0; /* compression type */
337 s->buf[11] = 0; /* filter type */
338 s->buf[12] = s->is_progressive; /* interlace type */
339 png_write_chunk(&s->bytestream, MKTAG('I', 'H', 'D', 'R'), s->buf, 13);
341 /* write physical information */
343 AV_WB32(s->buf, s->dpm);
344 AV_WB32(s->buf + 4, s->dpm);
345 s->buf[8] = 1; /* unit specifier is meter */
347 AV_WB32(s->buf, avctx->sample_aspect_ratio.num);
348 AV_WB32(s->buf + 4, avctx->sample_aspect_ratio.den);
349 s->buf[8] = 0; /* unit specifier is unknown */
351 png_write_chunk(&s->bytestream, MKTAG('p', 'H', 'Y', 's'), s->buf, 9);
353 /* write colorspace information */
354 if (pict->color_primaries == AVCOL_PRI_BT709 &&
355 pict->color_trc == AVCOL_TRC_IEC61966_2_1) {
356 s->buf[0] = 1; /* rendering intent, relative colorimetric by default */
357 png_write_chunk(&s->bytestream, MKTAG('s', 'R', 'G', 'B'), s->buf, 1);
360 if (png_get_chrm(pict->color_primaries, s->buf))
361 png_write_chunk(&s->bytestream, MKTAG('c', 'H', 'R', 'M'), s->buf, 32);
362 if (png_get_gama(pict->color_trc, s->buf))
363 png_write_chunk(&s->bytestream, MKTAG('g', 'A', 'M', 'A'), s->buf, 4);
365 /* put the palette if needed */
366 if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
367 int has_alpha, alpha, i;
370 uint8_t *ptr, *alpha_ptr;
372 palette = (uint32_t *)pict->data[1];
374 alpha_ptr = s->buf + 256 * 3;
376 for (i = 0; i < 256; i++) {
381 *alpha_ptr++ = alpha;
382 bytestream_put_be24(&ptr, v);
384 png_write_chunk(&s->bytestream,
385 MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3);
387 png_write_chunk(&s->bytestream,
388 MKTAG('t', 'R', 'N', 'S'), s->buf + 256 * 3, 256);
395 static int encode_frame(AVCodecContext *avctx, const AVFrame *pict)
397 PNGEncContext *s = avctx->priv_data;
398 const AVFrame *const p = pict;
400 int row_size, pass_row_size;
401 uint8_t *ptr, *top, *crow_buf, *crow;
402 uint8_t *crow_base = NULL;
403 uint8_t *progressive_buf = NULL;
404 uint8_t *top_buf = NULL;
406 row_size = (avctx->width * s->bits_per_pixel + 7) >> 3;
408 crow_base = av_malloc((row_size + 32) << (s->filter_type == PNG_FILTER_VALUE_MIXED));
410 ret = AVERROR(ENOMEM);
413 // pixel data should be aligned, but there's a control byte before it
414 crow_buf = crow_base + 15;
415 if (s->is_progressive) {
416 progressive_buf = av_malloc(row_size + 1);
417 top_buf = av_malloc(row_size + 1);
418 if (!progressive_buf || !top_buf) {
419 ret = AVERROR(ENOMEM);
425 s->zstream.avail_out = IOBUF_SIZE;
426 s->zstream.next_out = s->buf;
427 if (s->is_progressive) {
430 for (pass = 0; pass < NB_PASSES; pass++) {
431 /* NOTE: a pass is completely omitted if no pixels would be
433 pass_row_size = ff_png_pass_row_size(pass, s->bits_per_pixel, avctx->width);
434 if (pass_row_size > 0) {
436 for (y = 0; y < avctx->height; y++)
437 if ((ff_png_pass_ymask[pass] << (y & 7)) & 0x80) {
438 ptr = p->data[0] + y * p->linesize[0];
439 FFSWAP(uint8_t *, progressive_buf, top_buf);
440 png_get_interlaced_row(progressive_buf, pass_row_size,
441 s->bits_per_pixel, pass,
443 crow = png_choose_filter(s, crow_buf, progressive_buf,
444 top, pass_row_size, s->bits_per_pixel >> 3);
445 png_write_row(avctx, crow, pass_row_size + 1);
446 top = progressive_buf;
452 for (y = 0; y < avctx->height; y++) {
453 ptr = p->data[0] + y * p->linesize[0];
454 crow = png_choose_filter(s, crow_buf, ptr, top,
455 row_size, s->bits_per_pixel >> 3);
456 png_write_row(avctx, crow, row_size + 1);
460 /* compress last bytes */
462 ret = deflate(&s->zstream, Z_FINISH);
463 if (ret == Z_OK || ret == Z_STREAM_END) {
464 len = IOBUF_SIZE - s->zstream.avail_out;
465 if (len > 0 && s->bytestream_end - s->bytestream > len + 100) {
466 png_write_image_data(avctx, s->buf, len);
468 s->zstream.avail_out = IOBUF_SIZE;
469 s->zstream.next_out = s->buf;
470 if (ret == Z_STREAM_END)
481 av_freep(&crow_base);
482 av_freep(&progressive_buf);
484 deflateReset(&s->zstream);
488 static int encode_png(AVCodecContext *avctx, AVPacket *pkt,
489 const AVFrame *pict, int *got_packet)
491 PNGEncContext *s = avctx->priv_data;
494 size_t max_packet_size;
496 enc_row_size = deflateBound(&s->zstream, (avctx->width * s->bits_per_pixel + 7) >> 3);
498 FF_MIN_BUFFER_SIZE + // headers
501 12 * (((int64_t)enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) // IDAT * ceil(enc_row_size / IOBUF_SIZE)
503 if (max_packet_size > INT_MAX)
504 return AVERROR(ENOMEM);
505 ret = ff_alloc_packet2(avctx, pkt, max_packet_size);
509 s->bytestream_start =
510 s->bytestream = pkt->data;
511 s->bytestream_end = pkt->data + pkt->size;
513 AV_WB64(s->bytestream, PNGSIG);
516 ret = encode_headers(avctx, pict);
520 ret = encode_frame(avctx, pict);
524 png_write_chunk(&s->bytestream, MKTAG('I', 'E', 'N', 'D'), NULL, 0);
526 pkt->size = s->bytestream - s->bytestream_start;
527 pkt->flags |= AV_PKT_FLAG_KEY;
533 static int encode_apng(AVCodecContext *avctx, AVPacket *pkt,
534 const AVFrame *pict, int *got_packet)
536 PNGEncContext *s = avctx->priv_data;
539 size_t max_packet_size;
542 if (avctx->codec_id == AV_CODEC_ID_APNG && s->color_type == PNG_COLOR_TYPE_PALETTE) {
543 uint32_t checksum = ~av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), ~0U, pict->data[1], 256 * sizeof(uint32_t));
545 if (avctx->frame_number == 0) {
546 s->palette_checksum = checksum;
547 } else if (checksum != s->palette_checksum) {
548 av_log(avctx, AV_LOG_ERROR,
549 "Input contains more than one unique palette. APNG does not support multiple palettes.\n");
554 enc_row_size = deflateBound(&s->zstream, (avctx->width * s->bits_per_pixel + 7) >> 3);
556 FF_MIN_BUFFER_SIZE + // headers
559 (4 + 12) * (((int64_t)enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) // fdAT * ceil(enc_row_size / IOBUF_SIZE)
561 if (max_packet_size > INT_MAX)
562 return AVERROR(ENOMEM);
563 ret = ff_alloc_packet2(avctx, pkt, max_packet_size);
567 s->bytestream_start =
568 s->bytestream = pkt->data;
569 s->bytestream_end = pkt->data + pkt->size;
571 if (avctx->frame_number == 0) {
572 ret = encode_headers(avctx, pict);
576 avctx->extradata = av_malloc(s->bytestream - s->bytestream_start);
577 if (!avctx->extradata)
578 return AVERROR(ENOMEM);
579 avctx->extradata_size = s->bytestream - s->bytestream_start;
580 memcpy(avctx->extradata, s->bytestream_start, s->bytestream - s->bytestream_start);
582 s->bytestream = s->bytestream_start;
585 AV_WB32(buf, s->sequence_number);
586 AV_WB32(buf + 4, avctx->width);
587 AV_WB32(buf + 8, avctx->height);
588 AV_WB32(buf + 12, 0); // x offset
589 AV_WB32(buf + 16, 0); // y offset
590 AV_WB16(buf + 20, 0); // delay numerator (filled in during muxing)
591 AV_WB16(buf + 22, 0); // delay denominator
592 buf[24] = APNG_DISPOSE_OP_BACKGROUND;
593 buf[25] = APNG_BLEND_OP_SOURCE;
594 png_write_chunk(&s->bytestream, MKTAG('f', 'c', 'T', 'L'), buf, 26);
595 ++s->sequence_number;
597 ret = encode_frame(avctx, pict);
601 pkt->size = s->bytestream - s->bytestream_start;
602 pkt->flags |= AV_PKT_FLAG_KEY;
608 static av_cold int png_enc_init(AVCodecContext *avctx)
610 PNGEncContext *s = avctx->priv_data;
611 int compression_level;
613 switch (avctx->pix_fmt) {
614 case AV_PIX_FMT_RGBA:
615 avctx->bits_per_coded_sample = 32;
617 case AV_PIX_FMT_RGB24:
618 avctx->bits_per_coded_sample = 24;
620 case AV_PIX_FMT_GRAY8:
621 avctx->bits_per_coded_sample = 0x28;
623 case AV_PIX_FMT_MONOBLACK:
624 avctx->bits_per_coded_sample = 1;
626 case AV_PIX_FMT_PAL8:
627 avctx->bits_per_coded_sample = 8;
630 avctx->coded_frame = av_frame_alloc();
631 if (!avctx->coded_frame)
632 return AVERROR(ENOMEM);
634 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
635 avctx->coded_frame->key_frame = 1;
637 ff_huffyuvencdsp_init(&s->hdsp);
639 s->filter_type = av_clip(avctx->prediction_method,
640 PNG_FILTER_VALUE_NONE,
641 PNG_FILTER_VALUE_MIXED);
642 if (avctx->pix_fmt == AV_PIX_FMT_MONOBLACK)
643 s->filter_type = PNG_FILTER_VALUE_NONE;
645 if (s->dpi && s->dpm) {
646 av_log(avctx, AV_LOG_ERROR, "Only one of 'dpi' or 'dpm' options should be set\n");
647 return AVERROR(EINVAL);
649 s->dpm = s->dpi * 10000 / 254;
652 s->is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT);
653 switch (avctx->pix_fmt) {
654 case AV_PIX_FMT_RGBA64BE:
656 s->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
658 case AV_PIX_FMT_RGB48BE:
660 s->color_type = PNG_COLOR_TYPE_RGB;
662 case AV_PIX_FMT_RGBA:
664 s->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
666 case AV_PIX_FMT_RGB24:
668 s->color_type = PNG_COLOR_TYPE_RGB;
670 case AV_PIX_FMT_GRAY16BE:
672 s->color_type = PNG_COLOR_TYPE_GRAY;
674 case AV_PIX_FMT_GRAY8:
676 s->color_type = PNG_COLOR_TYPE_GRAY;
678 case AV_PIX_FMT_GRAY8A:
680 s->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
682 case AV_PIX_FMT_YA16BE:
684 s->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
686 case AV_PIX_FMT_MONOBLACK:
688 s->color_type = PNG_COLOR_TYPE_GRAY;
690 case AV_PIX_FMT_PAL8:
692 s->color_type = PNG_COLOR_TYPE_PALETTE;
697 s->bits_per_pixel = ff_png_get_nb_channels(s->color_type) * s->bit_depth;
699 s->zstream.zalloc = ff_png_zalloc;
700 s->zstream.zfree = ff_png_zfree;
701 s->zstream.opaque = NULL;
702 compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT
703 ? Z_DEFAULT_COMPRESSION
704 : av_clip(avctx->compression_level, 0, 9);
705 if (deflateInit2(&s->zstream, compression_level, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY) != Z_OK)
711 static av_cold int png_enc_close(AVCodecContext *avctx)
713 PNGEncContext *s = avctx->priv_data;
715 deflateEnd(&s->zstream);
716 av_frame_free(&avctx->coded_frame);
720 #define OFFSET(x) offsetof(PNGEncContext, x)
721 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
722 static const AVOption options[] = {
723 {"dpi", "Set image resolution (in dots per inch)", OFFSET(dpi), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, VE},
724 {"dpm", "Set image resolution (in dots per meter)", OFFSET(dpm), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, VE},
728 static const AVClass pngenc_class = {
729 .class_name = "PNG encoder",
730 .item_name = av_default_item_name,
732 .version = LIBAVUTIL_VERSION_INT,
735 static const AVClass apngenc_class = {
736 .class_name = "APNG encoder",
737 .item_name = av_default_item_name,
739 .version = LIBAVUTIL_VERSION_INT,
742 AVCodec ff_png_encoder = {
744 .long_name = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"),
745 .type = AVMEDIA_TYPE_VIDEO,
746 .id = AV_CODEC_ID_PNG,
747 .priv_data_size = sizeof(PNGEncContext),
748 .init = png_enc_init,
749 .close = png_enc_close,
750 .encode2 = encode_png,
751 .capabilities = CODEC_CAP_FRAME_THREADS | CODEC_CAP_INTRA_ONLY,
752 .pix_fmts = (const enum AVPixelFormat[]) {
753 AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA,
754 AV_PIX_FMT_RGB48BE, AV_PIX_FMT_RGBA64BE,
756 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A,
757 AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_YA16BE,
758 AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_NONE
760 .priv_class = &pngenc_class,
763 AVCodec ff_apng_encoder = {
765 .long_name = NULL_IF_CONFIG_SMALL("APNG (Animated Portable Network Graphics) image"),
766 .type = AVMEDIA_TYPE_VIDEO,
767 .id = AV_CODEC_ID_APNG,
768 .priv_data_size = sizeof(PNGEncContext),
769 .init = png_enc_init,
770 .close = png_enc_close,
771 .encode2 = encode_apng,
772 .pix_fmts = (const enum AVPixelFormat[]) {
773 AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA,
774 AV_PIX_FMT_RGB48BE, AV_PIX_FMT_RGBA64BE,
776 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A,
777 AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_YA16BE,
778 AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_NONE
780 .priv_class = &apngenc_class,