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.

93 lines
2.9KB

  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("auto", args)) setfield->top_field_first = -1;
  38. else {
  39. av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", args);
  40. return AVERROR(EINVAL);
  41. }
  42. }
  43. }
  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. return 0;
  51. }
  52. static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
  53. {
  54. SetFieldContext *setfield = inlink->dst->priv;
  55. AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
  56. if (setfield->top_field_first != -1) {
  57. outpicref->video->interlaced = 1;
  58. outpicref->video->top_field_first = setfield->top_field_first;
  59. }
  60. avfilter_start_frame(inlink->dst->outputs[0], outpicref);
  61. }
  62. AVFilter avfilter_vf_setfield = {
  63. .name = "setfield",
  64. .description = NULL_IF_CONFIG_SMALL("Force field for the output video frame."),
  65. .init = init,
  66. .priv_size = sizeof(SetFieldContext),
  67. .inputs = (const AVFilterPad[]) {
  68. { .name = "default",
  69. .type = AVMEDIA_TYPE_VIDEO,
  70. .get_video_buffer = avfilter_null_get_video_buffer,
  71. .start_frame = start_frame, },
  72. { .name = NULL }
  73. },
  74. .outputs = (const AVFilterPad[]) {
  75. { .name = "default",
  76. .type = AVMEDIA_TYPE_VIDEO, },
  77. { .name = NULL }
  78. },
  79. };