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);
105 const AVFrame *frame,
int *got_packet)
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,
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
This structure describes decoded (raw) audio or video data.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int libwebp_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static const AVCodecDefault libwebp_defaults[]
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
int flags
A combination of AV_PKT_FLAG values.
reference-counted frame API
int width
picture width / height.
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
static av_cold int libwebp_encode_init(AVCodecContext *avctx)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static const AVOption options[]
main external API structure.
Describe the class of an AVClass context structure.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
int global_quality
Global quality for codecs which cannot change it per frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int libwebp_error_to_averror(int err)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
common internal and external API header
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static av_cold int init(AVCodecParserContext *s)
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
AVPixelFormat
Pixel format.
This structure stores compressed data.
AVCodec ff_libwebp_encoder