func: static int encode_apng(AVCodecContext *avctx, AVPacket const AVFrame *pict, int *got_packet) PNGEncContext * s = avctx -> priv_data ; int ret ; int enc_row_size ; size_t max_packet_size ; if ( pict && avctx -> codec_id == AV_CODEC_ID_APNG && s -> color_type == PNG_COLOR_TYPE_PALETTE )  uint32_t checksum = ~av_crc ( av_crc_get_table ( AV_CRC_32_IEEE_LE ) , ~0U , pict -> data [ 1 ] , 256 * sizeof ( uint32_t ) ) ; if ( avctx -> frame_number == 0 )  s -> palette_checksum = checksum; if ( checksum != s -> palette_checksum )  enc_row_size = deflateBound ( & s -> zstream , ( avctx -> width * s -> bits_per_pixel + 7 ) >> 3 ); max_packet_size = AV_INPUT_BUFFER_MIN_SIZE + avctx -> height * ( enc_row_size + ( 4 + 12 ) * ( ( ( int64_t ) enc_row_size + IOBUF_SIZE - 1 ) / IOBUF_SIZE ) ); if ( max_packet_size > INT_MAX )  if ( avctx -> frame_number == 0 )  s -> bytestream = avctx -> extradata = av_malloc ( FF_MIN_BUFFER_SIZE ); if ( ! avctx -> extradata )  ret = encode_headers ( avctx , pict ); static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) PNGEncContext * s = avctx -> priv_data ; s -> buf [ 8 ] = s -> bit_depth; s -> buf [ 9 ] = s -> color_type; s -> buf [ 10 ] = 0; s -> buf [ 11 ] = 0; s -> buf [ 12 ] = s -> is_progressive; if ( s -> dpm )  s -> buf [ 8 ] = 0; if ( pict -> color_primaries == AVCOL_PRI_BT709 && pict -> color_trc == AVCOL_TRC_IEC61966_2_1 )  s -> buf [ 0 ] = 1; if ( png_get_gama ( pict -> color_trc , s -> buf ) )  static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf) double gamma = avpriv_get_gamma_from_trc ( trc ) ; if ( gamma <= 1e-6 )  return 0 ; return 1 ; png_write_chunk ( & s -> bytestream , MKTAG ( 'g' , 'A' , 'M' , 'A' ) , s -> buf , 4 ); static void png_write_chunk(uint8_t **f, uint32_t const uint8_t *buf, int length) if ( length > 0 )  memcpy ( * f , buf , length ); * f += length; bytestream_put_be32 ( f , ~crc ); 