vf_setfield.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "avfilter.h"
  25. enum SetFieldMode {
  26. MODE_AUTO = -1,
  27. MODE_BFF,
  28. MODE_TFF,
  29. MODE_PROG,
  30. };
  31. typedef struct {
  32. enum SetFieldMode mode;
  33. } SetFieldContext;
  34. static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
  35. {
  36. SetFieldContext *setfield = ctx->priv;
  37. setfield->mode = MODE_AUTO;
  38. if (args) {
  39. char c;
  40. if (sscanf(args, "%d%c", &setfield->mode, &c) != 1) {
  41. if (!strcmp("tff", args)) setfield->mode = MODE_TFF;
  42. else if (!strcmp("bff", args)) setfield->mode = MODE_BFF;
  43. else if (!strcmp("prog", args)) setfield->mode = MODE_PROG;
  44. else if (!strcmp("auto", args)) setfield->mode = MODE_AUTO;
  45. else {
  46. av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
  47. return AVERROR(EINVAL);
  48. }
  49. } else {
  50. if (setfield->mode < -1 || setfield->mode > 1) {
  51. av_log(ctx, AV_LOG_ERROR,
  52. "Provided integer value %d must be included between -1 and +1\n",
  53. setfield->mode);
  54. return AVERROR(EINVAL);
  55. }
  56. av_log(ctx, AV_LOG_WARNING,
  57. "Using -1/0/1 is deprecated, use auto/tff/bff/prog\n");
  58. }
  59. }
  60. return 0;
  61. }
  62. static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
  63. {
  64. SetFieldContext *setfield = inlink->dst->priv;
  65. AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
  66. if (setfield->mode == MODE_PROG) {
  67. outpicref->video->interlaced = 0;
  68. } else if (setfield->mode != MODE_AUTO) {
  69. outpicref->video->interlaced = 1;
  70. outpicref->video->top_field_first = setfield->mode;
  71. }
  72. avfilter_start_frame(inlink->dst->outputs[0], outpicref);
  73. }
  74. AVFilter avfilter_vf_setfield = {
  75. .name = "setfield",
  76. .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
  77. .init = init,
  78. .priv_size = sizeof(SetFieldContext),
  79. .inputs = (const AVFilterPad[]) {
  80. { .name = "default",
  81. .type = AVMEDIA_TYPE_VIDEO,
  82. .get_video_buffer = avfilter_null_get_video_buffer,
  83. .start_frame = start_frame, },
  84. { .name = NULL }
  85. },
  86. .outputs = (const AVFilterPad[]) {
  87. { .name = "default",
  88. .type = AVMEDIA_TYPE_VIDEO, },
  89. { .name = NULL }
  90. },
  91. };