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>
6 * This file is part of libass.
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.
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.
26 typedef struct image_s {
27 int width, height, stride;
28 unsigned char *buffer; // RGB24
31 ASS_Library *ass_library;
32 ASS_Renderer *ass_renderer;
34 void msg_callback(int level, const char *fmt, va_list va, void *data)
43 static void init(int frame_w, int frame_h)
45 ass_library = ass_library_init();
47 printf("ass_library_init failed!\n");
51 ass_set_message_cb(ass_library, msg_callback, NULL);
53 ass_renderer = ass_renderer_init(ass_library);
55 printf("ass_renderer_init failed!\n");
59 ass_set_frame_size(ass_renderer, frame_w, frame_h);
60 ass_set_fonts(ass_renderer, NULL, "Sans", 1, NULL, 1);
63 int main(int argc, char *argv[])
65 const int frame_w = 1280;
66 const int frame_h = 720;
69 printf("usage: %s <subtitle file> <start time> <fps> <time to render>\n", argv[0]);
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);
78 printf("fps cannot equal 0\n");
82 init(frame_w, frame_h);
83 ASS_Track *track = ass_read_file(ass_library, subfile, NULL);
85 printf("track init failed!\n");
90 ass_render_frame(ass_renderer, track, (int) (tm * 1000), NULL);
94 ass_free_track(track);
95 ass_renderer_done(ass_renderer);
96 ass_library_done(ass_library);