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.

73 lines
2.3KB

  1. /*
  2. * SSA/ASS decoder
  3. * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avcodec.h"
  22. #include "ass.h"
  23. #include "ass_split.h"
  24. static av_cold int ass_decode_init(AVCodecContext *avctx)
  25. {
  26. avctx->subtitle_header = av_malloc(avctx->extradata_size);
  27. if (!avctx->extradata)
  28. return AVERROR(ENOMEM);
  29. memcpy(avctx->subtitle_header, avctx->extradata, avctx->extradata_size);
  30. avctx->subtitle_header_size = avctx->extradata_size;
  31. avctx->priv_data = ff_ass_split(avctx->extradata);
  32. return 0;
  33. }
  34. static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
  35. AVPacket *avpkt)
  36. {
  37. const char *ptr = avpkt->data;
  38. int len, size = avpkt->size;
  39. while (size > 0) {
  40. ASSDialog *dialog = ff_ass_split_dialog(avctx->priv_data, ptr, 0, NULL);
  41. int duration = dialog->end - dialog->start;
  42. len = ff_ass_add_rect(data, ptr, 0, duration, 1);
  43. if (len < 0)
  44. return len;
  45. ptr += len;
  46. size -= len;
  47. }
  48. *got_sub_ptr = avpkt->size > 0;
  49. return avpkt->size;
  50. }
  51. static int ass_decode_close(AVCodecContext *avctx)
  52. {
  53. ff_ass_split_free(avctx->priv_data);
  54. avctx->priv_data = NULL;
  55. return 0;
  56. }
  57. AVCodec ff_ass_decoder = {
  58. .name = "ass",
  59. .long_name = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle"),
  60. .type = AVMEDIA_TYPE_SUBTITLE,
  61. .id = CODEC_ID_SSA,
  62. .init = ass_decode_init,
  63. .decode = ass_decode_frame,
  64. .close = ass_decode_close,
  65. };