func: static int gif_encode_frame(AVCodecContext *avctx, AVPacket const AVFrame *pict, int *got_packet) GIFContext * s = avctx -> priv_data ; uint8_t * outbuf_ptr , * end ; const uint32_t * palette = NULL ; int ret ; if ( ( ret = ff_alloc_packet2 ( avctx , pkt , avctx -> width * avctx -> height * 7 / 5 + AV_INPUT_BUFFER_MIN_SIZE , 0 ) ) < 0 )  outbuf_ptr = pkt -> data; end = pkt -> data + pkt -> size; if ( avctx -> pix_fmt == AV_PIX_FMT_PAL8 )  uint8_t * pal_exdata = av_packet_new_side_data ( pkt , AV_PKT_DATA_PALETTE , AVPALETTE_SIZE ) ; if ( ! pal_exdata )  memcpy ( pal_exdata , pict -> data [ 1 ] , AVPALETTE_SIZE ); palette = ( uint32_t * ) pict -> data [ 1 ]; s -> pal_exdata = pal_exdata; if ( ! s -> palette_loaded )  palette = NULL; if ( ! memcmp ( s -> palette , palette , AVPALETTE_SIZE ) )  palette = NULL; gif_image_write_image ( avctx , & outbuf_ptr , end , palette , pict -> data [ 0 ] , pict -> linesize [ 0 ] , pkt ); static int gif_image_write_image(AVCodecContext uint8_t **bytestream, uint8_t const uint32_t const uint8_t *buf, const int AVPacket *pkt) GIFContext * s = avctx -> priv_data ; int len = 0 , height = avctx -> height , width = avctx -> width , x , y ; int x_start = 0 , y_start = 0 , trans = s -> transparent_index ; if ( ( s -> flags & GF_OFFSETTING ) && s -> last_frame && ! palette )  const uint8_t * ref = s -> last_frame -> data [ 0 ] ; const int ref_linesize = s -> last_frame -> linesize [ 0 ] ; int x_end = avctx -> width - 1 , y_end = avctx -> height - 1 ; while ( y_start < y_end )  if ( memcmp ( ref + y_start * ref_linesize , buf + y_start * linesize , width ) )  y_start ++; while ( y_end > y_start )  if ( memcmp ( ref + y_end * ref_linesize , buf + y_end * linesize , width ) )  y_end --; 