Debian Codegraph @

lib/subtitle/subtest.c

raw
1 #include "subtitle.h"
2 #include <stdio.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6
7
8 static void subtitle_print(const subtitles_t* l)
9 {
10 if (l != NULL)
11 {
12 int i;
13
14 printf("Subtitles: %d line(s)\n", l->count);
15 for (i = 0; i < l->count; i++)
16 {
17 subtitle_line_t* sl = &l->subtitle[i];
18 int j;
19 //break;
20 printf("Start: %d End: %d (%d)\n", sl->start, sl->end, sl->lines);
21 for (j = 0; j < sl->lines; j++)
22 printf(" %d: >%s<\n", j, sl->line[j]);
23 }
24 }
25 }
26
27
28 int main(int argc, char **argv)
29 { // for testing
30 int i;
31 subtitles_t *subs;
32 subtitle_line_t sl;
33 //unsigned int ar[] = { 1165, 1493, 0 };
34 //double ar[] = { 42.874, 47.1, 0 };
35 double ar[] = { 22.14, 53.1, 0 };
36 int fd;
37
38 if (argc<2)
39 {
40 printf("\nUsage: subtitle filename.sub write.{sub|srt}\n\n");
41 exit(1);
42 }
43
44 fd = open(argv[1], O_RDONLY);
45 if (fd < 0)
46 {
47 fprintf(stderr, "can't open: %s\n", argv[1]);
48 exit(1);
49 }
50
51 subs = subtitle_open(fd, 23.976, NULL);
52 if (!subs)
53 {
54 printf("Couldn't load file: %s\n", argv[1]);
55 exit(1);
56 }
57
58 subtitle_print(subs);
59 #if 0
60 for (i = 0; ar[i]; i++)
61 {
62 if (subtitle_get(&sl, subs, ar[i]))
63 {
64 int j;
65 printf("%f: Start: %d End: %d\n", ar[i], sl.start, sl.end);
66 for (j = 0; j < sl.lines; j++)
67 printf(" %d: %s\n", j, sl.line[j]);
68 }
69 else
70 printf("Not found: %f\n", ar[i]);
71 }
72 #endif
73
74 if (argc >= 2)
75 {
76 subs->fps = 23.976;
77 subtitle_write(subs, argv[2], SUBTITLE_MICRODVD);
78 }
79
80
81 subtitle_close(subs);
82
83 //printf ("Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use");
84 //printf ("Read %i subtitles, %i errors.\n", sub_num, sub_errs);
85 return 0;
86 }