Mercurial > mplayer.hg
annotate libass/ass_mp.c @ 20146:cfbb283087f0
Change == to = in test comparisons for better portability.
patch from NetBSD pkgsrc
author | diego |
---|---|
date | Tue, 10 Oct 2006 23:14:40 +0000 |
parents | f753fbd5ae66 |
children | e8adc3778348 |
rev | line source |
---|---|
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*- |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
2 // vim:ts=8:sw=8:noet:ai: |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
3 /* |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
4 Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
5 |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
6 This program is free software; you can redistribute it and/or modify |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
7 it under the terms of the GNU General Public License as published by |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
8 the Free Software Foundation; either version 2 of the License, or |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
9 (at your option) any later version. |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
10 |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
11 This program is distributed in the hope that it will be useful, |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
14 GNU General Public License for more details. |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
15 |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
17 along with this program; if not, write to the Free Software |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
19 */ |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
20 |
19405 | 21 #include <inttypes.h> |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
22 #include <string.h> |
19484
6eb79b2384f8
use of malloc without prototype.. very bad on 64bit archs
rfelker
parents:
19405
diff
changeset
|
23 #include <stdlib.h> |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
24 |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
25 #include "mp_msg.h" |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
26 |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
27 #include "ass.h" |
19646 | 28 #include "ass_utils.h" |
18937 | 29 #include "ass_mp.h" |
30 | |
31 // libass-related command line options | |
32 int ass_enabled = 0; | |
33 float ass_font_scale = 1.; | |
34 float ass_line_spacing = 0.; | |
35 int ass_top_margin = 0; | |
36 int ass_bottom_margin = 0; | |
37 int extract_embedded_fonts = 0; | |
19495 | 38 char **ass_force_style_list = NULL; |
19563 | 39 int ass_use_margins = 0; |
19646 | 40 char* ass_color = NULL; |
41 char* ass_border_color = NULL; | |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
42 char* ass_styles_file = NULL; |
18937 | 43 |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
44 extern int font_fontconfig; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
45 extern char* font_name; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
46 extern float text_font_scale_factor; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
47 extern int subtitle_autoscale; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
48 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
49 extern double ass_internal_font_size_coeff; |
19584
586e7d259d05
Apply -ass-force-style also to tracks generated from subdata.
eugeni
parents:
19563
diff
changeset
|
50 extern void process_force_style(ass_track_t* track); |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
51 |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
52 ass_track_t* ass_default_track() { |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
53 ass_track_t* track = ass_new_track(); |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
54 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
55 track->track_type = TRACK_TYPE_ASS; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
56 track->Timer = 100.; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
57 track->PlayResX = 384; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
58 track->PlayResY = 288; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
59 track->WrapStyle = 0; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
60 |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
61 if (ass_styles_file) |
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
62 ass_read_styles(track, ass_styles_file); |
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
63 |
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
64 if (track->n_styles == 0) { |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
65 ass_style_t* style; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
66 int sid; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
67 double fs; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
68 uint32_t c1, c2; |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
69 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
70 sid = ass_alloc_style(track); |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
71 style = track->styles + sid; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
72 style->Name = strdup("Default"); |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
73 style->FontName = (font_fontconfig && font_name) ? strdup(font_name) : strdup("Sans"); |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
74 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
75 fs = track->PlayResY * text_font_scale_factor / 100. / ass_internal_font_size_coeff; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
76 // approximate autoscale coefficients |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
77 if (subtitle_autoscale == 2) |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
78 fs *= 1.3; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
79 else if (subtitle_autoscale == 3) |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
80 fs *= 1.4; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
81 style->FontSize = fs; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
82 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
83 if (ass_color) c1 = strtoll(ass_color, NULL, 16); |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
84 else c1 = 0xFFFF0000; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
85 if (ass_border_color) c2 = strtoll(ass_border_color, NULL, 16); |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
86 else c2 = 0x00000000; |
19646 | 87 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
88 style->PrimaryColour = c1; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
89 style->SecondaryColour = c1; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
90 style->OutlineColour = c2; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
91 style->BackColour = 0x00000000; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
92 style->BorderStyle = 1; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
93 style->Alignment = 2; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
94 style->Outline = 2; |
20138 | 95 style->MarginL = 10; |
96 style->MarginR = 10; | |
97 style->MarginV = 5; | |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
98 style->ScaleX = 1.; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
99 style->ScaleY = 1.; |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
100 } |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
101 |
19654
ae983f0a1cac
Apply -ass-force-style also to matroska plaintext subs.
eugeni
parents:
19653
diff
changeset
|
102 process_force_style(track); |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
103 return track; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
104 } |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
105 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
106 static int check_duplicate_plaintext_event(ass_track_t* track) |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
107 { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
108 int i; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
109 ass_event_t* evt = track->events + track->n_events - 1; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
110 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
111 for (i = 0; i<track->n_events - 1; ++i) // ignoring last event, it is the one we are comparing with |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
112 if (track->events[i].Start == evt->Start && |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
113 track->events[i].Duration == evt->Duration && |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
114 strcmp(track->events[i].Text, evt->Text) == 0) |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
115 return 1; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
116 return 0; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
117 } |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
118 |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
119 /** |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
120 * \brief Convert subtitle to ass_event_t for the given track |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
121 * \param ass_track_t track |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
122 * \param sub subtitle to convert |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
123 * \return event id |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
124 * note: assumes that subtitle is _not_ fps-based; caller must manually correct |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
125 * Start and Duration in other case. |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
126 **/ |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
127 int ass_process_subtitle(ass_track_t* track, subtitle* sub) |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
128 { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
129 int eid; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
130 ass_event_t* event; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
131 int len = 0, j; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
132 char* p; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
133 char* end; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
134 |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
135 eid = ass_alloc_event(track); |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
136 event = track->events + eid; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
137 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
138 event->Start = sub->start * 10; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
139 event->Duration = (sub->end - sub->start) * 10; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
140 event->Style = 0; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
141 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
142 for (j = 0; j < sub->lines; ++j) |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
143 len += sub->text[j] ? strlen(sub->text[j]) : 0; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
144 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
145 len += 2 * sub->lines; // '\N', including the one after the last line |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
146 len += 6; // {\anX} |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
147 len += 1; // '\0' |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
148 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
149 event->Text = malloc(len); |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
150 end = event->Text + len; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
151 p = event->Text; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
152 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
153 if (sub->alignment) |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
154 p += snprintf(p, end - p, "{\\an%d}", sub->alignment); |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
155 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
156 for (j = 0; j < sub->lines; ++j) |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
157 p += snprintf(p, end - p, "%s ", sub->text[j]); |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
158 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
159 p--; // remove last ' ' |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
160 *p = 0; |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
161 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
162 if (check_duplicate_plaintext_event(track)) { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
163 ass_free_event(track, eid); |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
164 track->n_events--; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
165 return -1; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
166 } |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
167 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
168 mp_msg(MSGT_GLOBAL, MSGL_V, "plaintext event at %" PRId64 ", +%" PRId64 ": %s \n", |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
169 (int64_t)event->Start, (int64_t)event->Duration, event->Text); |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
170 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
171 return eid; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
172 } |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
173 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
174 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
175 /** |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
176 * \brief Convert subdata to ass_track |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
177 * \param subdata subtitles struct from subreader |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
178 * \param fps video framerate |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
179 * \return newly allocated ass_track, filled with subtitles from subdata |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
180 */ |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
181 ass_track_t* ass_read_subdata(sub_data* subdata, double fps) { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
182 ass_track_t* track; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
183 int i; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
184 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
185 track = ass_default_track(); |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
186 track->name = subdata->filename ? strdup(subdata->filename) : 0; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
187 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
188 for (i = 0; i < subdata->sub_num; ++i) { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
189 int eid = ass_process_subtitle(track, subdata->subtitles + i); |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
190 if (eid < 0) |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
191 continue; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
192 if (!subdata->sub_uses_time) { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
193 track->events[eid].Start *= 100. / fps; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
194 track->events[eid].Duration *= 100. / fps; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
195 } |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
196 } |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
197 return track; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
198 } |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
199 |