27 #include <webp/encode.h>
52 case VP8_ENC_ERROR_OUT_OF_MEMORY:
53 case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY:
55 case VP8_ENC_ERROR_NULL_PARAMETER:
56 case VP8_ENC_ERROR_INVALID_CONFIGURATION:
57 case VP8_ENC_ERROR_BAD_DIMENSION:
78 if (s->
preset >= WEBP_PRESET_DEFAULT) {
86 ret = WebPConfigInit(&s->
config);
94 ret = WebPValidateConfig(&s->
config);
111 WebPPicture *pic =
NULL;
112 WebPMemoryWriter mw = { 0 };
115 if (avctx->
width > WEBP_MAX_DIMENSION || avctx->
height > WEBP_MAX_DIMENSION) {
117 WEBP_MAX_DIMENSION, WEBP_MAX_DIMENSION);
125 ret = WebPPictureInit(pic);
130 pic->width = avctx->
width;
131 pic->height = avctx->
height;
139 "Using libwebp for RGB-to-YUV conversion. You may want "
140 "to consider passing in YUV instead for lossy "
146 pic->argb = (uint32_t *)frame->
data[0];
147 pic->argb_stride = frame->
linesize[0] / 4;
152 "Copying frame due to differing chroma linesizes.\n");
184 for (y = 0; y < frame->
height; y+= bs) {
185 for (x = 0; x < frame->
width; x+= bs) {
188 for (p = 0; p < 3; p++) {
194 for (y2 = ys; y2 <
FFMIN(ys + bs2, h); y2++) {
195 for (x2 = xs; x2 <
FFMIN(xs + bs2, w); x2++) {
204 for (p = 0; p < 3; p++) {
210 for (y2 = ys; y2 <
FFMIN(ys + bs2, h); y2++) {
212 & frame->
data[p][frame->
linesize[p] * y2 + xs], FFMIN(bs2, w-xs));
215 for (y2 = y; y2 <
FFMIN(y+bs, frame->
height); y2++) {
218 FFMIN(bs, frame->
width-x));
226 pic->y = frame->
data[0];
227 pic->u = frame->
data[1];
228 pic->v = frame->
data[2];
230 pic->uv_stride = frame->
linesize[1];
232 pic->colorspace = WEBP_YUV420A;
233 pic->a = frame->
data[3];
236 WebPCleanupTransparentArea(pic);
238 pic->colorspace = WEBP_YUV420;
248 "Using libwebp for YUV-to-RGB conversion. You may want "
249 "to consider passing in RGB instead for lossless "
254 #if (WEBP_ENCODER_ABI_VERSION <= 0x201)
259 pic->memory_ = (
void*)1;
260 ret = WebPPictureYUVAToARGB(pic);
263 "WebPPictureYUVAToARGB() failed with error: %d\n",
273 WebPMemoryWriterInit(&mw);
274 pic->custom_ptr = &mw;
275 pic->writer = WebPMemoryWrite;
277 ret = WebPEncode(&s->
config, pic);
288 memcpy(pkt->
data, mw.mem, mw.size);
294 #if (WEBP_ENCODER_ABI_VERSION > 0x0203)
295 WebPMemoryWriterClear(&mw);
299 WebPPictureFree(pic);
315 #define OFFSET(x) offsetof(LibWebPContext, x)
316 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
320 {
"none",
"do not use a preset", 0,
AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0,
VE,
"preset" },
321 {
"default",
"default preset", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_DEFAULT }, 0, 0,
VE,
"preset" },
322 {
"picture",
"digital picture, like portrait, inner shot", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_PICTURE }, 0, 0,
VE,
"preset" },
323 {
"photo",
"outdoor photograph, with natural lighting", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_PHOTO }, 0, 0,
VE,
"preset" },
324 {
"drawing",
"hand or line drawing, with high-contrast details", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_DRAWING }, 0, 0,
VE,
"preset" },
325 {
"icon",
"small-sized colorful images", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_ICON }, 0, 0,
VE,
"preset" },
326 {
"text",
"text-like", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_TEXT }, 0, 0,
VE,
"preset" },
327 {
"cr_threshold",
"Conditional replenishment threshold",
OFFSET(cr_threshold),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
VE },
328 {
"cr_size" ,
"Conditional replenishment block size",
OFFSET(cr_size) ,
AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 256,
VE },
342 {
"compression_level",
"4" },
343 {
"global_quality",
"-1" },
361 .priv_class = &
class,