32 {
"compression_level",
"4" },
33 {
"global_quality",
"-1" },
37#define OFFSET(x) offsetof(LibWebPContextCommon, x)
38#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
42 {
"none",
"do not use a preset", 0,
AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0,
VE, .unit =
"preset" },
43 {
"default",
"default preset", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_DEFAULT }, 0, 0,
VE, .unit =
"preset" },
44 {
"picture",
"digital picture, like portrait, inner shot", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_PICTURE }, 0, 0,
VE, .unit =
"preset" },
45 {
"photo",
"outdoor photograph, with natural lighting", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_PHOTO }, 0, 0,
VE, .unit =
"preset" },
46 {
"drawing",
"hand or line drawing, with high-contrast details", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_DRAWING }, 0, 0,
VE, .unit =
"preset" },
47 {
"icon",
"small-sized colorful images", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_ICON }, 0, 0,
VE, .unit =
"preset" },
48 {
"text",
"text-like", 0,
AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_TEXT }, 0, 0,
VE, .unit =
"preset" },
49 {
"cr_threshold",
"Conditional replenishment threshold",
OFFSET(cr_threshold),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
VE },
50 {
"cr_size" ,
"Conditional replenishment block size",
OFFSET(cr_size) ,
AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 256,
VE },
56 .class_name =
"libwebp encoder",
71 case VP8_ENC_ERROR_OUT_OF_MEMORY:
72 case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY:
74 case VP8_ENC_ERROR_NULL_PARAMETER:
75 case VP8_ENC_ERROR_INVALID_CONFIGURATION:
76 case VP8_ENC_ERROR_BAD_DIMENSION:
97 if (
s->preset >= WEBP_PRESET_DEFAULT) {
98 ret = WebPConfigPreset(&
s->config,
s->preset,
s->quality);
101 s->lossless =
s->config.lossless;
102 s->quality =
s->config.quality;
105 ret = WebPConfigInit(&
s->config);
109 s->config.lossless =
s->lossless;
110 s->config.quality =
s->quality;
113 ret = WebPValidateConfig(&
s->config);
119 s->lossless ?
"Lossless" :
"Lossy",
s->quality,
127 WebPPicture **pic_ptr) {
129 WebPPicture *pic =
NULL;
132 if (avctx->
width > WEBP_MAX_DIMENSION || avctx->
height > WEBP_MAX_DIMENSION) {
134 WEBP_MAX_DIMENSION, WEBP_MAX_DIMENSION);
143 ret = WebPPictureInit(pic);
148 pic->width = avctx->
width;
149 pic->height = avctx->
height;
155 if (!
s->conversion_warning) {
157 "Using libwebp for RGB-to-YUV conversion. You may want "
158 "to consider passing in YUV instead for lossy "
160 s->conversion_warning = 1;
164 pic->argb = (uint32_t *)
frame->data[0];
165 pic->argb_stride =
frame->linesize[0] / 4;
167 if (
frame->linesize[1] !=
frame->linesize[2] ||
s->cr_threshold) {
168 if (!
s->chroma_warning && !
s->cr_threshold) {
170 "Copying frame due to differing chroma linesizes.\n");
171 s->chroma_warning = 1;
174 alt_frame = *alt_frame_ptr;
190 if (
s->cr_threshold) {
203 for (y = 0; y <
frame->height; y+= bs) {
204 for (x = 0; x <
frame->width; x+= bs) {
207 for (p = 0; p < 3; p++) {
213 for (y2 = ys; y2 <
FFMIN(ys + bs2,
h); y2++) {
214 for (x2 =
xs; x2 <
FFMIN(
xs + bs2,
w); x2++) {
216 -
s->ref->data[p][
frame->linesize[p] * y2 + x2];
221 skip =
sse <
s->cr_threshold &&
frame->data[3] !=
s->ref->data[3];
223 for (p = 0; p < 3; p++) {
229 for (y2 = ys; y2 <
FFMIN(ys + bs2,
h); y2++) {
230 memcpy(&
s->ref->data[p][
frame->linesize[p] * y2 +
xs],
234 for (y2 = y; y2 <
FFMIN(y+bs,
frame->height); y2++) {
235 memset(&
frame->data[3][
frame->linesize[3] * y2 + x],
245 pic->y =
frame->data[0];
246 pic->u =
frame->data[1];
247 pic->v =
frame->data[2];
248 pic->y_stride =
frame->linesize[0];
249 pic->uv_stride =
frame->linesize[1];
251 pic->colorspace = WEBP_YUV420A;
252 pic->a =
frame->data[3];
253 pic->a_stride =
frame->linesize[3];
255 WebPCleanupTransparentArea(pic);
257 pic->colorspace = WEBP_YUV420;
265 if (!
s->conversion_warning) {
267 "Using libwebp for YUV-to-RGB conversion. You may want "
268 "to consider passing in RGB instead for lossless "
270 s->conversion_warning = 1;
273#if (WEBP_ENCODER_ABI_VERSION <= 0x201)
278 pic->memory_ = (
void*)1;
279 ret = WebPPictureYUVAToARGB(pic);
282 "WebPPictureYUVAToARGB() failed with error: %d\n",
284 ret = libwebp_error_to_averror(pic->error_code);
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
#define xs(width, name, var, subs,...)
#define AV_CEIL_RSHIFT(a, b)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
#define LIBAVUTIL_VERSION_INT
int ff_libwebp_get_frame(AVCodecContext *avctx, LibWebPContextCommon *s, const AVFrame *frame, AVFrame **alt_frame_ptr, WebPPicture **pic_ptr)
const AVClass ff_libwebpenc_class
enum AVPixelFormat ff_libwebpenc_pix_fmts[]
av_cold int ff_libwebp_encode_init_common(AVCodecContext *avctx)
int ff_libwebp_error_to_averror(int err)
const FFCodecDefault ff_libwebp_defaults[]
WebP encoder using libwebp: common structs and methods.
Memory handling functions.
static int sse(const MPVEncContext *const s, const uint8_t *src1, const uint8_t *src2, int w, int h, int stride)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int global_quality
Global quality for codecs which cannot change it per frame.
This structure describes decoded (raw) audio or video data.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static const uint8_t quality[]