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.

98 lines
3.2KB

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