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.

100 lines
2.3KB

  1. /*
  2. * Copyright (c) 2008 Reimar Döffinger
  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. #include "libavutil/common.h"
  21. #include "libavutil/intreadwrite.h"
  22. #include "avcodec.h"
  23. #include "bsf.h"
  24. static int text2movsub(AVBSFContext *ctx, AVPacket *out)
  25. {
  26. AVPacket *in;
  27. int ret = 0;
  28. ret = ff_bsf_get_packet(ctx, &in);
  29. if (ret < 0)
  30. return ret;
  31. if (in->size > 0xffff) {
  32. ret = AVERROR_INVALIDDATA;
  33. goto fail;
  34. }
  35. ret = av_new_packet(out, in->size + 2);
  36. if (ret < 0) {
  37. ret = AVERROR(ENOMEM);
  38. goto fail;
  39. }
  40. ret = av_packet_copy_props(out, in);
  41. if (ret < 0)
  42. goto fail;
  43. AV_WB16(out->data, in->size);
  44. memcpy(out->data + 2, in->data, in->size);
  45. fail:
  46. if (ret < 0)
  47. av_packet_unref(out);
  48. av_packet_free(&in);
  49. return ret;
  50. }
  51. const AVBitStreamFilter ff_text2movsub_bsf = {
  52. .name = "text2movsub",
  53. .filter = text2movsub,
  54. };
  55. static int mov2textsub(AVBSFContext *ctx, AVPacket *out)
  56. {
  57. AVPacket *in;
  58. int ret = 0;
  59. ret = ff_bsf_get_packet(ctx, &in);
  60. if (ret < 0)
  61. return ret;
  62. if (in->size < 2) {
  63. ret = AVERROR_INVALIDDATA;
  64. goto fail;
  65. }
  66. ret = av_new_packet(out, FFMIN(in->size - 2, AV_RB16(in->data)));
  67. if (ret < 0)
  68. goto fail;
  69. ret = av_packet_copy_props(out, in);
  70. if (ret < 0)
  71. goto fail;
  72. memcpy(out->data, in->data + 2, out->size);
  73. fail:
  74. if (ret < 0)
  75. av_packet_unref(out);
  76. av_packet_free(&in);
  77. return ret;
  78. }
  79. const AVBitStreamFilter ff_mov2textsub_bsf = {
  80. .name = "mov2textsub",
  81. .filter = mov2textsub,
  82. };