srt2vtt.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**********************************************************************************************/
  2. /* The MIT License */
  3. /* */
  4. /* Copyright 2016-2016 Twitch Interactive, Inc. or its affiliates. All Rights Reserved. */
  5. /* */
  6. /* Permission is hereby granted, free of charge, to any person obtaining a copy */
  7. /* of this software and associated documentation files (the "Software"), to deal */
  8. /* in the Software without restriction, including without limitation the rights */
  9. /* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
  10. /* copies of the Software, and to permit persons to whom the Software is */
  11. /* furnished to do so, subject to the following conditions: */
  12. /* */
  13. /* The above copyright notice and this permission notice shall be included in */
  14. /* all copies or substantial portions of the Software. */
  15. /* */
  16. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
  17. /* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
  18. /* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
  19. /* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
  20. /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
  21. /* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN */
  22. /* THE SOFTWARE. */
  23. /**********************************************************************************************/
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include "srt.h"
  28. #define MAX_SRT_SIZE (10*1024*1024)
  29. #define MAX_READ_SIZE 4096
  30. size_t read_file (FILE* file, utf8_char_t* data, size_t size)
  31. {
  32. size_t read, totl = 0;
  33. while (0 < (read = fread (data,1,MAX_READ_SIZE<size?MAX_READ_SIZE:size,file))) {
  34. totl += read; data += read; size -= read;
  35. }
  36. return totl;
  37. }
  38. int main (int argc, char** argv)
  39. {
  40. srt_t* srt;
  41. caption_frame_t frame;
  42. char frame_buf[CAPTION_FRAME_DUMP_BUF_SIZE];
  43. if (argc < 2) {
  44. return 0;
  45. }
  46. FILE* file = fopen (argv[1],"r");
  47. if (! file) {
  48. return 0;
  49. }
  50. utf8_char_t* data = malloc (MAX_SRT_SIZE);
  51. size_t size = read_file (file,data,MAX_SRT_SIZE);
  52. srt_t* head = srt_parse (data,size);
  53. vtt_dump (head);
  54. srt_free (head);
  55. }