/* better than nothing gif encoder */ static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { GIFContext *s = avctx->priv_data; AVFrame *const p = &s->picture; uint8_t *outbuf_ptr, *end; int ret; if ((ret = ff_alloc_packet(pkt, avctx->width*avctx->height*7/5 + FF_MIN_BUFFER_SIZE)) < 0) { av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); return ret; } outbuf_ptr = pkt->data; end = pkt->data + pkt->size; *p = *pict; p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; gif_image_write_header(avctx, &outbuf_ptr, (uint32_t *)pict->data[1]); gif_image_write_image(avctx, &outbuf_ptr, end, pict->data[0], pict->linesize[0]); pkt->size = outbuf_ptr - pkt->data; pkt->flags |= AV_PKT_FLAG_KEY; *got_packet = 1; return 0; }
static int gif_write_video(AVFormatContext *s, AVCodecContext *enc, const uint8_t *buf, int size) { ByteIOContext *pb = s->pb; GIFContext *gif = s->priv_data; int jiffies; int64_t delay; /* graphic control extension block */ put_byte(pb, 0x21); put_byte(pb, 0xf9); put_byte(pb, 0x04); /* block size */ put_byte(pb, 0x04); /* flags */ /* 1 jiffy is 1/70 s */ /* the delay_time field indicates the number of jiffies - 1 */ delay = gif->file_time - gif->time; /* XXX: should use delay, in order to be more accurate */ /* instead of using the same rounded value each time */ /* XXX: don't even remember if I really use it for now */ jiffies = (70*enc->time_base.num/enc->time_base.den) - 1; put_le16(pb, jiffies); put_byte(pb, 0x1f); /* transparent color index */ put_byte(pb, 0x00); gif_image_write_image(pb, 0, 0, enc->width, enc->height, buf, enc->width * 3, PIX_FMT_RGB24); put_flush_packet(s->pb); return 0; }
/* better than nothing gif image writer */ int gif_write(ByteIOContext *pb, AVImageInfo *info) { gif_image_write_header(pb, info->width, info->height, (uint32_t *)info->pict.data[1]); gif_image_write_image(pb, 0, 0, info->width, info->height, info->pict.data[0], info->pict.linesize[0], PIX_FMT_PAL8); put_byte(pb, 0x3b); put_flush_packet(pb); return 0; }
/* better than nothing gif encoder */ static int gif_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data) { GIFContext *s = avctx->priv_data; AVFrame *pict = data; AVFrame *const p = (AVFrame *)&s->picture; uint8_t *outbuf_ptr = outbuf; *p = *pict; p->pict_type = FF_I_TYPE; p->key_frame = 1; gif_image_write_header(&outbuf_ptr, avctx->width, avctx->height, -1, (uint32_t *)pict->data[1]); gif_image_write_image(&outbuf_ptr, 0, 0, avctx->width, avctx->height, pict->data[0], pict->linesize[0], PIX_FMT_PAL8); return outbuf_ptr - outbuf; }
/* better than nothing gif encoder */ static int gif_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data) { GIFContext *s = avctx->priv_data; AVFrame *pict = data; AVFrame *const p = (AVFrame *)&s->picture; uint8_t *outbuf_ptr = outbuf; uint8_t *end = outbuf + buf_size; *p = *pict; p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; gif_image_write_header(avctx, &outbuf_ptr, (uint32_t *)pict->data[1]); gif_image_write_image(avctx, &outbuf_ptr, end, pict->data[0], pict->linesize[0]); return outbuf_ptr - outbuf; }