]> granicus.if.org Git - libass/blob - profile/profile.c
Added profile program and corresponding configure options
[libass] / profile / profile.c
1 /*
2  * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
3  * Copyright (C) 2009 Grigori Goronzy <greg@geekmind.org>
4  * Copyright (C) 2013 Rodger Combs <rcombs@rcombs.me>
5  *
6  * This file is part of libass.
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdarg.h>
24 #include <ass.h>
25
26 typedef struct image_s {
27     int width, height, stride;
28     unsigned char *buffer;      // RGB24
29 } image_t;
30
31 ASS_Library *ass_library;
32 ASS_Renderer *ass_renderer;
33
34 void msg_callback(int level, const char *fmt, va_list va, void *data)
35 {
36     if (level > 6)
37         return;
38     printf("libass: ");
39     vprintf(fmt, va);
40     printf("\n");
41 }
42
43 static void init(int frame_w, int frame_h)
44 {
45     ass_library = ass_library_init();
46     if (!ass_library) {
47         printf("ass_library_init failed!\n");
48         exit(1);
49     }
50
51     ass_set_message_cb(ass_library, msg_callback, NULL);
52
53     ass_renderer = ass_renderer_init(ass_library);
54     if (!ass_renderer) {
55         printf("ass_renderer_init failed!\n");
56         exit(1);
57     }
58
59     ass_set_frame_size(ass_renderer, frame_w, frame_h);
60     ass_set_fonts(ass_renderer, NULL, "Sans", 1, NULL, 1);
61 }
62
63 int main(int argc, char *argv[])
64 {
65     const int frame_w = 1280;
66     const int frame_h = 720;
67
68     if (argc < 5) {
69         printf("usage: %s <subtitle file> <start time> <fps> <time to render>\n", argv[0]);
70         exit(1);
71     }
72     char *subfile = argv[1];
73     double tm = strtod(argv[2], 0);
74     double fps = strtod(argv[3], 0);
75     double time = strtod(argv[4], 0);
76     
77     if(fps == 0){
78         printf("fps cannot equal 0\n");
79         exit(1);
80     }
81
82     init(frame_w, frame_h);
83     ASS_Track *track = ass_read_file(ass_library, subfile, NULL);
84     if (!track) {
85         printf("track init failed!\n");
86         exit(1);
87     }
88
89     while(tm < time){
90         ass_render_frame(ass_renderer, track, (int) (tm * 1000), NULL);
91         tm += 1 / fps;
92     }
93
94     ass_free_track(track);
95     ass_renderer_done(ass_renderer);
96     ass_library_done(ass_library);
97
98     return 0;
99 }