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.

161 lines
4.6KB

  1. /*
  2. * Copyright (c) 2007 Bobby Bingham
  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. * audio and video splitter
  23. */
  24. #include "avfilter.h"
  25. #include "audio.h"
  26. #include "internal.h"
  27. #include "video.h"
  28. static int split_init(AVFilterContext *ctx, const char *args)
  29. {
  30. int i, nb_outputs = 2;
  31. if (args) {
  32. nb_outputs = strtol(args, NULL, 0);
  33. if (nb_outputs <= 0) {
  34. av_log(ctx, AV_LOG_ERROR, "Invalid number of outputs specified: %d.\n",
  35. nb_outputs);
  36. return AVERROR(EINVAL);
  37. }
  38. }
  39. for (i = 0; i < nb_outputs; i++) {
  40. char name[32];
  41. AVFilterPad pad = { 0 };
  42. snprintf(name, sizeof(name), "output%d", i);
  43. pad.type = ctx->filter->inputs[0].type;
  44. pad.name = av_strdup(name);
  45. ff_insert_outpad(ctx, i, &pad);
  46. }
  47. return 0;
  48. }
  49. static void split_uninit(AVFilterContext *ctx)
  50. {
  51. int i;
  52. for (i = 0; i < ctx->nb_outputs; i++)
  53. av_freep(&ctx->output_pads[i].name);
  54. }
  55. static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
  56. {
  57. AVFilterContext *ctx = inlink->dst;
  58. int i, ret = 0;
  59. for (i = 0; i < ctx->nb_outputs; i++) {
  60. AVFilterBufferRef *buf_out = avfilter_ref_buffer(picref, ~AV_PERM_WRITE);
  61. if (!buf_out)
  62. return AVERROR(ENOMEM);
  63. ret = ff_start_frame(ctx->outputs[i], buf_out);
  64. if (ret < 0)
  65. break;
  66. }
  67. return ret;
  68. }
  69. static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
  70. {
  71. AVFilterContext *ctx = inlink->dst;
  72. int i, ret = 0;
  73. for (i = 0; i < ctx->nb_outputs; i++) {
  74. ret = ff_draw_slice(ctx->outputs[i], y, h, slice_dir);
  75. if (ret < 0)
  76. break;
  77. }
  78. return ret;
  79. }
  80. static int end_frame(AVFilterLink *inlink)
  81. {
  82. AVFilterContext *ctx = inlink->dst;
  83. int i, ret = 0;
  84. for (i = 0; i < ctx->nb_outputs; i++) {
  85. ret = ff_end_frame(ctx->outputs[i]);
  86. if (ret < 0)
  87. break;
  88. }
  89. return ret;
  90. }
  91. AVFilter avfilter_vf_split = {
  92. .name = "split",
  93. .description = NULL_IF_CONFIG_SMALL("Pass on the input video to N outputs."),
  94. .init = split_init,
  95. .uninit = split_uninit,
  96. .inputs = (const AVFilterPad[]) {{ .name = "default",
  97. .type = AVMEDIA_TYPE_VIDEO,
  98. .get_video_buffer= ff_null_get_video_buffer,
  99. .start_frame = start_frame,
  100. .draw_slice = draw_slice,
  101. .end_frame = end_frame, },
  102. { .name = NULL}},
  103. .outputs = (const AVFilterPad[]) {{ .name = NULL}},
  104. };
  105. static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
  106. {
  107. AVFilterContext *ctx = inlink->dst;
  108. int i, ret = 0;
  109. for (i = 0; i < ctx->nb_outputs; i++) {
  110. AVFilterBufferRef *buf_out = avfilter_ref_buffer(samplesref,
  111. ~AV_PERM_WRITE);
  112. if (!buf_out) {
  113. ret = AVERROR(ENOMEM);
  114. break;
  115. }
  116. ret = ff_filter_samples(inlink->dst->outputs[i], buf_out);
  117. if (ret < 0)
  118. break;
  119. }
  120. avfilter_unref_buffer(samplesref);
  121. return ret;
  122. }
  123. AVFilter avfilter_af_asplit = {
  124. .name = "asplit",
  125. .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
  126. .init = split_init,
  127. .uninit = split_uninit,
  128. .inputs = (const AVFilterPad[]) {{ .name = "default",
  129. .type = AVMEDIA_TYPE_AUDIO,
  130. .get_audio_buffer = ff_null_get_audio_buffer,
  131. .filter_samples = filter_samples },
  132. { .name = NULL }},
  133. .outputs = (const AVFilterPad[]) {{ .name = NULL }},
  134. };