27 #include <webp/encode.h>
49 case VP8_ENC_ERROR_OUT_OF_MEMORY:
50 case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY:
52 case VP8_ENC_ERROR_NULL_PARAMETER:
53 case VP8_ENC_ERROR_INVALID_CONFIGURATION:
54 case VP8_ENC_ERROR_BAD_DIMENSION:
76 if (s->
preset >= WEBP_PRESET_DEFAULT) {
84 ret = WebPConfigInit(&s->
config);
92 ret = WebPValidateConfig(&s->
config);
109 WebPPicture *pic = NULL;
110 WebPMemoryWriter mw = { 0 };
113 if (avctx->
width > WEBP_MAX_DIMENSION || avctx->
height > WEBP_MAX_DIMENSION) {
115 WEBP_MAX_DIMENSION, WEBP_MAX_DIMENSION);
123 ret = WebPPictureInit(pic);
128 pic->width = avctx->
width;
129 pic->height = avctx->
height;
137 "Using libwebp for RGB-to-YUV conversion. You may want "
138 "to consider passing in YUV instead for lossy "
144 pic->argb = (uint32_t *)frame->
data[0];
145 pic->argb_stride = frame->
linesize[0] / 4;
150 "Copying frame due to differing chroma linesizes.\n");
168 pic->y = frame->
data[0];
169 pic->u = frame->
data[1];
170 pic->v = frame->
data[2];
172 pic->uv_stride = frame->
linesize[1];
174 pic->colorspace = WEBP_YUV420A;
175 pic->a = frame->
data[3];
178 pic->colorspace = WEBP_YUV420;
188 "Using libwebp for YUV-to-RGB conversion. You may want "
189 "to consider passing in RGB instead for lossless "
194 #if (WEBP_ENCODER_ABI_VERSION <= 0x201)
199 pic->memory_ = (
void*)1;
200 ret = WebPPictureYUVAToARGB(pic);
203 "WebPPictureYUVAToARGB() failed with error: %d\n",
213 WebPMemoryWriterInit(&mw);
214 pic->custom_ptr = &mw;
215 pic->writer = WebPMemoryWrite;
217 ret = WebPEncode(&s->
config, pic);
228 memcpy(pkt->
data, mw.mem, mw.size);
235 WebPPictureFree(pic);
242 #define OFFSET(x) offsetof(LibWebPContext, x)
243 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
247 {
"none",
"do not use a preset", 0,
AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0,
VE,
"preset" },
248 {
"default",
"default preset", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_DEFAULT }, 0, 0,
VE,
"preset" },
249 {
"picture",
"digital picture, like portrait, inner shot", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_PICTURE }, 0, 0,
VE,
"preset" },
250 {
"photo",
"outdoor photograph, with natural lighting", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_PHOTO }, 0, 0,
VE,
"preset" },
251 {
"drawing",
"hand or line drawing, with high-contrast details", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_DRAWING }, 0, 0,
VE,
"preset" },
252 {
"icon",
"small-sized colorful images", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_ICON }, 0, 0,
VE,
"preset" },
253 {
"text",
"text-like", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_TEXT }, 0, 0,
VE,
"preset" },
265 {
"compression_level",
"4" },
266 {
"global_quality",
"-1" },
283 .priv_class = &
class,