You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.2KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "libavutil/pixfmt.h"
  19. #include "libavutil/opt.h"
  20. #include "avfilter.h"
  21. #include "internal.h"
  22. #include "video.h"
  23. typedef struct SetParamsContext {
  24. const AVClass *class;
  25. int color_range;
  26. } SetParamsContext;
  27. #define OFFSET(x) offsetof(SetParamsContext, x)
  28. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  29. static const AVOption setrange_options[] = {
  30. {"range", "select color range", OFFSET(color_range), AV_OPT_TYPE_INT, {.i64=-1},-1, AVCOL_RANGE_NB-1, FLAGS, "range"},
  31. {"auto", "keep the same color range", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, FLAGS, "range"},
  32. {"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, FLAGS, "range"},
  33. {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, FLAGS, "range"},
  34. {"limited", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
  35. {"tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
  36. {"mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
  37. {"full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
  38. {"pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
  39. {"jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
  40. {NULL}
  41. };
  42. AVFILTER_DEFINE_CLASS(setrange);
  43. static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
  44. {
  45. AVFilterContext *ctx = inlink->dst;
  46. SetParamsContext *s = ctx->priv;
  47. if (s->color_range >= 0)
  48. frame->color_range = s->color_range;
  49. return ff_filter_frame(ctx->outputs[0], frame);
  50. }
  51. static const AVFilterPad inputs[] = {
  52. {
  53. .name = "default",
  54. .type = AVMEDIA_TYPE_VIDEO,
  55. .filter_frame = filter_frame,
  56. },
  57. { NULL }
  58. };
  59. static const AVFilterPad outputs[] = {
  60. {
  61. .name = "default",
  62. .type = AVMEDIA_TYPE_VIDEO,
  63. },
  64. { NULL }
  65. };
  66. AVFilter ff_vf_setrange = {
  67. .name = "setrange",
  68. .description = NULL_IF_CONFIG_SMALL("Force color range for the output video frame."),
  69. .priv_size = sizeof(SetParamsContext),
  70. .priv_class = &setrange_class,
  71. .inputs = inputs,
  72. .outputs = outputs,
  73. };