vf_setfield.c 3.2 KB

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