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.

131 lines
3.3KB

  1. /*
  2. * Copyright (c) 2007 Bobby Bingham
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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 <stdio.h>
  25. #include "libavutil/internal.h"
  26. #include "libavutil/mem.h"
  27. #include "avfilter.h"
  28. #include "audio.h"
  29. #include "internal.h"
  30. #include "video.h"
  31. static int split_init(AVFilterContext *ctx, const char *args)
  32. {
  33. int i, nb_outputs = 2;
  34. if (args) {
  35. nb_outputs = strtol(args, NULL, 0);
  36. if (nb_outputs <= 0) {
  37. av_log(ctx, AV_LOG_ERROR, "Invalid number of outputs specified: %d.\n",
  38. nb_outputs);
  39. return AVERROR(EINVAL);
  40. }
  41. }
  42. for (i = 0; i < nb_outputs; i++) {
  43. char name[32];
  44. AVFilterPad pad = { 0 };
  45. snprintf(name, sizeof(name), "output%d", i);
  46. pad.type = ctx->filter->inputs[0].type;
  47. pad.name = av_strdup(name);
  48. ff_insert_outpad(ctx, i, &pad);
  49. }
  50. return 0;
  51. }
  52. static void split_uninit(AVFilterContext *ctx)
  53. {
  54. int i;
  55. for (i = 0; i < ctx->nb_outputs; i++)
  56. av_freep(&ctx->output_pads[i].name);
  57. }
  58. static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
  59. {
  60. AVFilterContext *ctx = inlink->dst;
  61. int i, ret = 0;
  62. for (i = 0; i < ctx->nb_outputs; i++) {
  63. AVFilterBufferRef *buf_out = avfilter_ref_buffer(frame, ~AV_PERM_WRITE);
  64. if (!buf_out) {
  65. ret = AVERROR(ENOMEM);
  66. break;
  67. }
  68. ret = ff_filter_frame(ctx->outputs[i], buf_out);
  69. if (ret < 0)
  70. break;
  71. }
  72. avfilter_unref_bufferp(&frame);
  73. return ret;
  74. }
  75. static const AVFilterPad avfilter_vf_split_inputs[] = {
  76. {
  77. .name = "default",
  78. .type = AVMEDIA_TYPE_VIDEO,
  79. .get_video_buffer = ff_null_get_video_buffer,
  80. .filter_frame = filter_frame,
  81. },
  82. { NULL }
  83. };
  84. AVFilter avfilter_vf_split = {
  85. .name = "split",
  86. .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
  87. .init = split_init,
  88. .uninit = split_uninit,
  89. .inputs = avfilter_vf_split_inputs,
  90. .outputs = NULL,
  91. };
  92. static const AVFilterPad avfilter_af_asplit_inputs[] = {
  93. {
  94. .name = "default",
  95. .type = AVMEDIA_TYPE_AUDIO,
  96. .get_audio_buffer = ff_null_get_audio_buffer,
  97. .filter_frame = filter_frame,
  98. },
  99. { NULL }
  100. };
  101. AVFilter avfilter_af_asplit = {
  102. .name = "asplit",
  103. .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
  104. .init = split_init,
  105. .uninit = split_uninit,
  106. .inputs = avfilter_af_asplit_inputs,
  107. .outputs = NULL,
  108. };