func: static int encode_frame(AVCodecContext *avctx, const AVFrame *pict) PNGEncContext * s = avctx -> priv_data ; int y , len , ret ; int row_size , pass_row_size ; uint8_t * ptr , * top , * crow_buf , * crow ; uint8_t * progressive_buf = NULL ; row_size = ( pict -> width * s -> bits_per_pixel + 7 ) >> 3; crow_base = av_malloc ( ( row_size + 32 ) << ( s -> filter_type == PNG_FILTER_VALUE_MIXED ) ); if ( ! crow_base )  crow_buf = crow_base + 15; if ( s -> is_progressive )  progressive_buf = av_malloc ( row_size + 1 ); top_buf = av_malloc ( row_size + 1 ); if ( ! progressive_buf || ! top_buf )  s -> zstream . avail_out = IOBUF_SIZE; s -> zstream . next_out = s -> buf; if ( s -> is_progressive )  int pass ; for (pass = 0; pass < NB_PASSES; pass++) pass_row_size = ff_png_pass_row_size ( pass , s -> bits_per_pixel , pict -> width ); if ( pass_row_size > 0 )  top = NULL; for (y = 0; y < pict->height; y++) if ( ( ff_png_pass_ymask [ pass ] << ( y & 7 ) ) & 0x80 )  crow = png_choose_filter ( s , crow_buf , progressive_buf , top , pass_row_size , s -> bits_per_pixel >> 3 ); static uint8_t *png_choose_filter(PNGEncContext *s, uint8_t uint8_t *src, uint8_t *top, int size, int bpp) int pred = s -> filter_type ; if ( ! top && pred )  pred = PNG_FILTER_VALUE_SUB; if ( pred == PNG_FILTER_VALUE_MIXED )  uint8_t * buf1 = dst , * buf2 = dst + size + 16 ; return buf2 ; dst [ 0 ] = pred; return dst ; png_write_row ( avctx , crow , pass_row_size + 1 ); top = progressive_buf; static int png_write_row(AVCodecContext *avctx, const uint8_t *data, int size) PNGEncContext * s = avctx -> priv_data ; int ret ; s -> zstream . avail_in = size; s -> zstream . next_in = data; while ( s -> zstream . avail_in > 0 )  ret = deflate ( & s -> zstream , Z_NO_FLUSH ); if ( ret != Z_OK )  if ( s -> zstream . avail_out == 0 )  if ( s -> bytestream_end - s -> bytestream > IOBUF_SIZE + 100 )  png_write_image_data ( avctx , s -> buf , IOBUF_SIZE ); s -> zstream . avail_out = IOBUF_SIZE; s -> zstream . next_out = s -> buf; static void png_write_image_data(AVCodecContext const uint8_t *buf, int length) PNGEncContext * s = avctx -> priv_data ; if ( avctx -> codec_id == AV_CODEC_ID_PNG || avctx -> frame_number == 0 )  png_write_chunk ( & s -> bytestream , MKTAG ( 'I' , 'D' , 'A' , 'T' ) , buf , length ); 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 ); 