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.

177 lines
7.3KB

  1. /*
  2. * Copyright (c) 2012 Stefano Sabatini
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/pixfmt.h"
  21. #include "libavutil/opt.h"
  22. #include "avfilter.h"
  23. #include "internal.h"
  24. #include "video.h"
  25. enum SetFieldMode {
  26. MODE_AUTO = -1,
  27. MODE_BFF,
  28. MODE_TFF,
  29. MODE_PROG,
  30. };
  31. typedef struct SetParamsContext {
  32. const AVClass *class;
  33. int field_mode;
  34. int color_range;
  35. } SetParamsContext;
  36. #define OFFSET(x) offsetof(SetParamsContext, x)
  37. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  38. static const AVOption setparams_options[] = {
  39. {"field_mode", "select interlace mode", OFFSET(field_mode), AV_OPT_TYPE_INT, {.i64=MODE_AUTO}, -1, MODE_PROG, FLAGS, "mode"},
  40. {"auto", "keep the same input field", 0, AV_OPT_TYPE_CONST, {.i64=MODE_AUTO}, INT_MIN, INT_MAX, FLAGS, "mode"},
  41. {"bff", "mark as bottom-field-first", 0, AV_OPT_TYPE_CONST, {.i64=MODE_BFF}, INT_MIN, INT_MAX, FLAGS, "mode"},
  42. {"tff", "mark as top-field-first", 0, AV_OPT_TYPE_CONST, {.i64=MODE_TFF}, INT_MIN, INT_MAX, FLAGS, "mode"},
  43. {"prog", "mark as progressive", 0, AV_OPT_TYPE_CONST, {.i64=MODE_PROG}, INT_MIN, INT_MAX, FLAGS, "mode"},
  44. {"range", "select color range", OFFSET(color_range), AV_OPT_TYPE_INT, {.i64=-1},-1, AVCOL_RANGE_NB-1, FLAGS, "range"},
  45. {"auto", "keep the same color range", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, FLAGS, "range"},
  46. {"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, FLAGS, "range"},
  47. {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, FLAGS, "range"},
  48. {"limited", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
  49. {"tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
  50. {"mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
  51. {"full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
  52. {"pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
  53. {"jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
  54. {NULL}
  55. };
  56. AVFILTER_DEFINE_CLASS(setparams);
  57. static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
  58. {
  59. AVFilterContext *ctx = inlink->dst;
  60. SetParamsContext *s = ctx->priv;
  61. /* set field */
  62. if (s->field_mode == MODE_PROG) {
  63. frame->interlaced_frame = 0;
  64. } else if (s->field_mode != MODE_AUTO) {
  65. frame->interlaced_frame = 1;
  66. frame->top_field_first = s->field_mode;
  67. }
  68. /* set range */
  69. if (s->color_range >= 0)
  70. frame->color_range = s->color_range;
  71. return ff_filter_frame(ctx->outputs[0], frame);
  72. }
  73. static const AVFilterPad inputs[] = {
  74. {
  75. .name = "default",
  76. .type = AVMEDIA_TYPE_VIDEO,
  77. .filter_frame = filter_frame,
  78. },
  79. { NULL }
  80. };
  81. static const AVFilterPad outputs[] = {
  82. {
  83. .name = "default",
  84. .type = AVMEDIA_TYPE_VIDEO,
  85. },
  86. { NULL }
  87. };
  88. AVFilter ff_vf_setparams = {
  89. .name = "setparams",
  90. .description = NULL_IF_CONFIG_SMALL("Force field, or color range for the output video frame."),
  91. .priv_size = sizeof(SetParamsContext),
  92. .priv_class = &setparams_class,
  93. .inputs = inputs,
  94. .outputs = outputs,
  95. };
  96. #if CONFIG_SETRANGE_FILTER
  97. static const AVOption setrange_options[] = {
  98. {"range", "select color range", OFFSET(color_range), AV_OPT_TYPE_INT, {.i64=-1},-1, AVCOL_RANGE_NB-1, FLAGS, "range"},
  99. {"auto", "keep the same color range", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, FLAGS, "range"},
  100. {"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, FLAGS, "range"},
  101. {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, FLAGS, "range"},
  102. {"limited", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
  103. {"tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
  104. {"mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range"},
  105. {"full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
  106. {"pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
  107. {"jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range"},
  108. {NULL}
  109. };
  110. AVFILTER_DEFINE_CLASS(setrange);
  111. static av_cold int init_setrange(AVFilterContext *ctx)
  112. {
  113. SetParamsContext *s = ctx->priv;
  114. s->field_mode = MODE_AUTO;/* set field mode to auto */
  115. return 0;
  116. }
  117. AVFilter ff_vf_setrange = {
  118. .name = "setrange",
  119. .description = NULL_IF_CONFIG_SMALL("Force color range for the output video frame."),
  120. .priv_size = sizeof(SetParamsContext),
  121. .init = init_setrange,
  122. .priv_class = &setrange_class,
  123. .inputs = inputs,
  124. .outputs = outputs,
  125. };
  126. #endif /* CONFIG_SETRANGE_FILTER */
  127. #if CONFIG_SETFIELD_FILTER
  128. static const AVOption setfield_options[] = {
  129. {"mode", "select interlace mode", OFFSET(field_mode), AV_OPT_TYPE_INT, {.i64=MODE_AUTO}, -1, MODE_PROG, FLAGS, "mode"},
  130. {"auto", "keep the same input field", 0, AV_OPT_TYPE_CONST, {.i64=MODE_AUTO}, INT_MIN, INT_MAX, FLAGS, "mode"},
  131. {"bff", "mark as bottom-field-first", 0, AV_OPT_TYPE_CONST, {.i64=MODE_BFF}, INT_MIN, INT_MAX, FLAGS, "mode"},
  132. {"tff", "mark as top-field-first", 0, AV_OPT_TYPE_CONST, {.i64=MODE_TFF}, INT_MIN, INT_MAX, FLAGS, "mode"},
  133. {"prog", "mark as progressive", 0, AV_OPT_TYPE_CONST, {.i64=MODE_PROG}, INT_MIN, INT_MAX, FLAGS, "mode"},
  134. {NULL}
  135. };
  136. AVFILTER_DEFINE_CLASS(setfield);
  137. static av_cold int init_setfield(AVFilterContext *ctx)
  138. {
  139. SetParamsContext *s = ctx->priv;
  140. s->color_range = -1;/* set range mode to auto */
  141. return 0;
  142. }
  143. AVFilter ff_vf_setfield = {
  144. .name = "setfield",
  145. .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
  146. .priv_size = sizeof(SetParamsContext),
  147. .init = init_setfield,
  148. .priv_class = &setfield_class,
  149. .inputs = inputs,
  150. .outputs = outputs,
  151. };
  152. #endif /* CONFIG_SETFIELD_FILTER */