srtdump.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include "avc.h"
  29. // #include "sei.h"
  30. #define MAX_SRT_SIZE (10*1024*1024)
  31. #define MAX_READ_SIZE 4096
  32. size_t read_file (FILE* file, utf8_char_t* data, size_t size)
  33. {
  34. size_t read, totl = 0;
  35. while (0 < (read = fread (data,1,MAX_READ_SIZE<size?MAX_READ_SIZE:size,file))) {
  36. totl += read; data += read; size -= read;
  37. }
  38. return totl;
  39. }
  40. int main (int argc, char** argv)
  41. {
  42. srt_t* srt;
  43. caption_frame_t frame;
  44. if (argc < 2) {
  45. return 0;
  46. }
  47. FILE* file = fopen (argv[1],"r");
  48. if (! file) {
  49. return 0;
  50. }
  51. utf8_char_t* data = (utf8_char_t*) malloc (MAX_SRT_SIZE);
  52. size_t size = read_file (file,data,MAX_SRT_SIZE);
  53. srt_t* head = srt_parse (data,size);
  54. for (srt = head ; srt ; srt = srt->next) {
  55. caption_frame_init (&frame);
  56. srt_to_caption_frame (srt,&frame);
  57. caption_frame_dump (&frame);
  58. }
  59. srt_free (head);
  60. }