libwebpenc_common.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * WebP encoding support via libwebp
  3. * Copyright (c) 2013 Justin Ruggles <justin.ruggles@gmail.com>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * WebP encoder using libwebp: common structs and methods.
  24. */
  25. #ifndef AVCODEC_LIBWEBPENC_COMMON_H
  26. #define AVCODEC_LIBWEBPENC_COMMON_H
  27. #include <webp/encode.h>
  28. #include "libavutil/common.h"
  29. #include "libavutil/frame.h"
  30. #include "libavutil/imgutils.h"
  31. #include "libavutil/opt.h"
  32. #include "avcodec.h"
  33. #include "internal.h"
  34. typedef struct LibWebPContextCommon {
  35. AVClass *class; // class for AVOptions
  36. float quality; // lossy quality 0 - 100
  37. int lossless; // use lossless encoding
  38. int preset; // configuration preset
  39. int chroma_warning; // chroma linesize mismatch warning has been printed
  40. int conversion_warning; // pixel format conversion warning has been printed
  41. WebPConfig config; // libwebp configuration
  42. AVFrame *ref;
  43. int cr_size;
  44. int cr_threshold;
  45. } LibWebPContextCommon;
  46. int ff_libwebp_error_to_averror(int err);
  47. av_cold int ff_libwebp_encode_init_common(AVCodecContext *avctx);
  48. int ff_libwebp_get_frame(AVCodecContext *avctx, LibWebPContextCommon *s,
  49. const AVFrame *frame, AVFrame **alt_frame_ptr,
  50. WebPPicture **pic_ptr);
  51. #define OFFSET(x) offsetof(LibWebPContextCommon, x)
  52. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  53. static const AVOption options[] = {
  54. { "lossless", "Use lossless mode", OFFSET(lossless), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
  55. { "preset", "Configuration preset", OFFSET(preset), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, WEBP_PRESET_TEXT, VE, "preset" },
  56. { "none", "do not use a preset", 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0, VE, "preset" },
  57. { "default", "default preset", 0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_DEFAULT }, 0, 0, VE, "preset" },
  58. { "picture", "digital picture, like portrait, inner shot", 0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_PICTURE }, 0, 0, VE, "preset" },
  59. { "photo", "outdoor photograph, with natural lighting", 0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_PHOTO }, 0, 0, VE, "preset" },
  60. { "drawing", "hand or line drawing, with high-contrast details", 0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_DRAWING }, 0, 0, VE, "preset" },
  61. { "icon", "small-sized colorful images", 0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_ICON }, 0, 0, VE, "preset" },
  62. { "text", "text-like", 0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_TEXT }, 0, 0, VE, "preset" },
  63. { "cr_threshold","Conditional replenishment threshold", OFFSET(cr_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
  64. { "cr_size" ,"Conditional replenishment block size", OFFSET(cr_size) , AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 256, VE },
  65. { "quality" ,"Quality", OFFSET(quality), AV_OPT_TYPE_FLOAT, { .dbl = 75 }, 0, 100, VE },
  66. { NULL },
  67. };
  68. static const AVCodecDefault libwebp_defaults[] = {
  69. { "compression_level", "4" },
  70. { "global_quality", "-1" },
  71. { NULL },
  72. };
  73. #endif /* AVCODEC_LIBWEBPENC_COMMON_H */