MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / gif_encode_frame

Function gif_encode_frame

libavcodec/gif.c:475–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

473}
474
475static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
476 const AVFrame *pict, int *got_packet)
477{
478 GIFContext *s = avctx->priv_data;
479 uint8_t *outbuf_ptr, *end;
480 const uint32_t *palette = NULL;
481 int ret;
482
483 if ((ret = ff_alloc_packet(avctx, pkt, avctx->width*avctx->height*7/5 + FF_INPUT_BUFFER_MIN_SIZE)) < 0)
484 return ret;
485 outbuf_ptr = pkt->data;
486 end = pkt->data + pkt->size;
487
488 if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
489 palette = (uint32_t*)pict->data[1];
490
491 if (!s->palette_loaded) {
492 memcpy(s->palette, palette, AVPALETTE_SIZE);
493 s->transparent_index = get_palette_transparency_index(palette);
494 s->palette_loaded = 1;
495 if (s->use_global_palette)
496 palette = NULL;
497 } else if (!memcmp(s->palette, palette, AVPALETTE_SIZE)) {
498 palette = NULL;
499 }
500 }
501
502 gif_image_write_image(avctx, &outbuf_ptr, end, palette,
503 pict->data[0], pict->linesize[0], pkt);
504 if (!s->last_frame && !s->image) {
505 s->last_frame = av_frame_alloc();
506 if (!s->last_frame)
507 return AVERROR(ENOMEM);
508 }
509
510 if (!s->image) {
511 ret = av_frame_replace(s->last_frame, pict);
512 if (ret < 0)
513 return ret;
514 }
515
516 pkt->size = outbuf_ptr - pkt->data;
517 if (s->image || !avctx->frame_num)
518 pkt->flags |= AV_PKT_FLAG_KEY;
519 *got_packet = 1;
520
521 return 0;
522}
523
524static av_cold int gif_encode_close(AVCodecContext *avctx)
525{

Callers

nothing calls this directly

Calls 5

ff_alloc_packetFunction · 0.85
gif_image_write_imageFunction · 0.85
av_frame_allocFunction · 0.85
av_frame_replaceFunction · 0.85

Tested by

no test coverage detected