Unified · Split
| @@ -43,6 +43,7 @@ · 42 unmodified lines | ||
| 43 | 43 | |
| 44 | 44 | #include "avcodec.h" |
| 45 | 45 | #include "bytestream.h" |
| 46 | +#include "internal.h" | |
| 46 | 47 | #include "lzw.h" |
| 47 | 48 | |
| 48 | 49 | /* The GIF format uses reversed order for bitstreams... */ |
| @@ -141,20 +142,32 @@ static av_cold int gif_encode_init(AVCodecContext *avctx) · 92 unmodified lines | ||
| 141 | 142 | } |
| 142 | 143 | |
| 143 | 144 | /* better than nothing gif encoder */ |
| 144 | −static int gif_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data) | |
| 145 | +static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt, | |
| 146 | + const AVFrame *pict, int *got_packet) | |
| 145 | 147 | { |
| 146 | 148 | GIFContext *s = avctx->priv_data; |
| 147 | − AVFrame *pict = data; | |
| 148 | 149 | AVFrame *const p = (AVFrame *)&s->picture; |
| 149 | − uint8_t *outbuf_ptr = outbuf; | |
| 150 | − uint8_t *end = outbuf + buf_size; | |
| 150 | + uint8_t *outbuf_ptr, *end; | |
| 151 | + int ret; | |
| 152 | + | |
| 153 | + if ((ret = ff_alloc_packet(pkt, avctx->width*avctx->height*7/5 + FF_MIN_BUFFER_SIZE)) < 0) { | |
| 154 | + av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); | |
| 155 | + return ret; | |
| 156 | + } | |
| 157 | + outbuf_ptr = pkt->data; | |
| 158 | + end = pkt->data + pkt->size; | |
| 151 | 159 | |
| 152 | 160 | *p = *pict; |
| 153 | 161 | p->pict_type = AV_PICTURE_TYPE_I; |
| 154 | 162 | p->key_frame = 1; |
| 155 | 163 | gif_image_write_header(avctx, &outbuf_ptr, (uint32_t *)pict->data[1]); |
| 156 | 164 | gif_image_write_image(avctx, &outbuf_ptr, end, pict->data[0], pict->linesize[0]); |
| 157 | − return outbuf_ptr - outbuf; | |
| 165 | + | |
| 166 | + pkt->size = outbuf_ptr - pkt->data; | |
| 167 | + pkt->flags |= AV_PKT_FLAG_KEY; | |
| 168 | + *got_packet = 1; | |
| 169 | + | |
| 170 | + return 0; | |
| 158 | 171 | } |
| 159 | 172 | |
| 160 | 173 | static int gif_encode_close(AVCodecContext *avctx) |
| @@ -172,7 +185,7 @@ AVCodec ff_gif_encoder = { · 11 unmodified lines | ||
| 172 | 185 | .id = CODEC_ID_GIF, |
| 173 | 186 | .priv_data_size = sizeof(GIFContext), |
| 174 | 187 | .init = gif_encode_init, |
| 175 | − .encode = gif_encode_frame, | |
| 188 | + .encode2 = gif_encode_frame, | |
| 176 | 189 | .close = gif_encode_close, |
| 177 | 190 | .pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8, PIX_FMT_NONE}, |
| 178 | 191 | .long_name= NULL_IF_CONFIG_SMALL("GIF (Graphics Interchange Format)"), |