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.

157 lines
3.9KB

  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 "libavutil/opt.h"
  28. #include "avfilter.h"
  29. #include "audio.h"
  30. #include "internal.h"
  31. #include "video.h"
  32. typedef struct SplitContext {
  33. const AVClass *class;
  34. int nb_outputs;
  35. } SplitContext;
  36. static int split_init(AVFilterContext *ctx)
  37. {
  38. SplitContext *s = ctx->priv;
  39. int i;
  40. for (i = 0; i < s->nb_outputs; i++) {
  41. char name[32];
  42. AVFilterPad pad = { 0 };
  43. snprintf(name, sizeof(name), "output%d", i);
  44. pad.type = ctx->filter->inputs[0].type;
  45. pad.name = av_strdup(name);
  46. ff_insert_outpad(ctx, i, &pad);
  47. }
  48. return 0;
  49. }
  50. static void split_uninit(AVFilterContext *ctx)
  51. {
  52. int i;
  53. for (i = 0; i < ctx->nb_outputs; i++)
  54. av_freep(&ctx->output_pads[i].name);
  55. }
  56. static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
  57. {
  58. AVFilterContext *ctx = inlink->dst;
  59. int i, ret = 0;
  60. for (i = 0; i < ctx->nb_outputs; i++) {
  61. AVFrame *buf_out = av_frame_clone(frame);
  62. if (!buf_out) {
  63. ret = AVERROR(ENOMEM);
  64. break;
  65. }
  66. ret = ff_filter_frame(ctx->outputs[i], buf_out);
  67. if (ret < 0)
  68. break;
  69. }
  70. av_frame_free(&frame);
  71. return ret;
  72. }
  73. #define OFFSET(x) offsetof(SplitContext, x)
  74. #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
  75. static const AVOption options[] = {
  76. { "outputs", "Number of outputs", OFFSET(nb_outputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, FLAGS },
  77. { NULL },
  78. };
  79. static const AVClass split_class = {
  80. .class_name = "split",
  81. .item_name = av_default_item_name,
  82. .option = options,
  83. .version = LIBAVUTIL_VERSION_INT,
  84. };
  85. static const AVClass asplit_class = {
  86. .class_name = "asplit",
  87. .item_name = av_default_item_name,
  88. .option = options,
  89. .version = LIBAVUTIL_VERSION_INT,
  90. };
  91. static const AVFilterPad avfilter_vf_split_inputs[] = {
  92. {
  93. .name = "default",
  94. .type = AVMEDIA_TYPE_VIDEO,
  95. .get_video_buffer = ff_null_get_video_buffer,
  96. .filter_frame = filter_frame,
  97. },
  98. { NULL }
  99. };
  100. AVFilter avfilter_vf_split = {
  101. .name = "split",
  102. .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."),
  103. .priv_size = sizeof(SplitContext),
  104. .priv_class = &split_class,
  105. .init = split_init,
  106. .uninit = split_uninit,
  107. .inputs = avfilter_vf_split_inputs,
  108. .outputs = NULL,
  109. };
  110. static const AVFilterPad avfilter_af_asplit_inputs[] = {
  111. {
  112. .name = "default",
  113. .type = AVMEDIA_TYPE_AUDIO,
  114. .get_audio_buffer = ff_null_get_audio_buffer,
  115. .filter_frame = filter_frame,
  116. },
  117. { NULL }
  118. };
  119. AVFilter avfilter_af_asplit = {
  120. .name = "asplit",
  121. .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to N audio outputs."),
  122. .priv_size = sizeof(SplitContext),
  123. .priv_class = &asplit_class,
  124. .init = split_init,
  125. .uninit = split_uninit,
  126. .inputs = avfilter_af_asplit_inputs,
  127. .outputs = NULL,
  128. };