vf_setfield.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /**
  21. * @file
  22. * set field order
  23. */
  24. #include "libavutil/opt.h"
  25. #include "avfilter.h"
  26. #include "internal.h"
  27. #include "video.h"
  28. enum SetFieldMode {
  29. MODE_AUTO = -1,
  30. MODE_BFF,
  31. MODE_TFF,
  32. MODE_PROG,
  33. };
  34. typedef struct {
  35. const AVClass *class;
  36. enum SetFieldMode mode;
  37. } SetFieldContext;
  38. #define OFFSET(x) offsetof(SetFieldContext, x)
  39. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  40. static const AVOption setfield_options[] = {
  41. {"mode", "select interlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_AUTO}, -1, MODE_PROG, FLAGS, "mode"},
  42. {"auto", "keep the same input field", 0, AV_OPT_TYPE_CONST, {.i64=MODE_AUTO}, INT_MIN, INT_MAX, FLAGS, "mode"},
  43. {"bff", "mark as bottom-field-first", 0, AV_OPT_TYPE_CONST, {.i64=MODE_BFF}, INT_MIN, INT_MAX, FLAGS, "mode"},
  44. {"tff", "mark as top-field-first", 0, AV_OPT_TYPE_CONST, {.i64=MODE_TFF}, INT_MIN, INT_MAX, FLAGS, "mode"},
  45. {"prog", "mark as progressive", 0, AV_OPT_TYPE_CONST, {.i64=MODE_PROG}, INT_MIN, INT_MAX, FLAGS, "mode"},
  46. {NULL}
  47. };
  48. AVFILTER_DEFINE_CLASS(setfield);
  49. static av_cold int init(AVFilterContext *ctx, const char *args)
  50. {
  51. SetFieldContext *setfield = ctx->priv;
  52. static const char *shorthand[] = { "mode", NULL };
  53. setfield->class = &setfield_class;
  54. av_opt_set_defaults(setfield);
  55. return av_opt_set_from_string(setfield, args, shorthand, "=", ":");
  56. }
  57. static av_cold void uninit(AVFilterContext *ctx)
  58. {
  59. SetFieldContext *setfield = ctx->priv;
  60. av_opt_free(setfield);
  61. }
  62. static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
  63. {
  64. SetFieldContext *setfield = inlink->dst->priv;
  65. if (setfield->mode == MODE_PROG) {
  66. picref->video->interlaced = 0;
  67. } else if (setfield->mode != MODE_AUTO) {
  68. picref->video->interlaced = 1;
  69. picref->video->top_field_first = setfield->mode;
  70. }
  71. return ff_filter_frame(inlink->dst->outputs[0], picref);
  72. }
  73. static const AVFilterPad setfield_inputs[] = {
  74. {
  75. .name = "default",
  76. .type = AVMEDIA_TYPE_VIDEO,
  77. .get_video_buffer = ff_null_get_video_buffer,
  78. .filter_frame = filter_frame,
  79. },
  80. { NULL }
  81. };
  82. static const AVFilterPad setfield_outputs[] = {
  83. {
  84. .name = "default",
  85. .type = AVMEDIA_TYPE_VIDEO,
  86. },
  87. { NULL }
  88. };
  89. AVFilter avfilter_vf_setfield = {
  90. .name = "setfield",
  91. .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
  92. .init = init,
  93. .uninit = uninit,
  94. .priv_size = sizeof(SetFieldContext),
  95. .inputs = setfield_inputs,
  96. .outputs = setfield_outputs,
  97. .priv_class = &setfield_class,
  98. };