mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
player/command: add sub-text/ass-full sub-property
This is like sub-text/ass, but it returns a full ASS line, making it suitable for some more advanced scripting use-cases.
This commit is contained in:
1
DOCS/interface-changes/sub-text-ass-full.txt
Normal file
1
DOCS/interface-changes/sub-text-ass-full.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
add `sub-text/ass-full` sub-property
|
||||||
@@ -2833,8 +2833,11 @@ Property list
|
|||||||
with line breaks. Contains only the "Text" part of the events.
|
with line breaks. Contains only the "Text" part of the events.
|
||||||
|
|
||||||
This property is not enough to render ASS subtitles correctly, because ASS
|
This property is not enough to render ASS subtitles correctly, because ASS
|
||||||
header and per-event metadata are not returned. You likely need to do
|
header and per-event metadata are not returned. Use ``/ass-full`` for that.
|
||||||
further filtering on the returned string to make it useful.
|
|
||||||
|
``sub-text/ass-full``
|
||||||
|
Like ``sub-text-ass``, but return the full event with all fields, formatted as
|
||||||
|
lines in a .ass text file. Use with ``sub-ass-extradata`` for style information.
|
||||||
|
|
||||||
``sub-text-ass`` (deprecated)
|
``sub-text-ass`` (deprecated)
|
||||||
Deprecated alias for ``sub-text/ass``.
|
Deprecated alias for ``sub-text/ass``.
|
||||||
|
|||||||
@@ -3026,6 +3026,8 @@ static int mp_property_sub_text(void *ctx, struct m_property *prop,
|
|||||||
|
|
||||||
if (!strcmp(ka->key, "ass"))
|
if (!strcmp(ka->key, "ass"))
|
||||||
type = SD_TEXT_TYPE_ASS;
|
type = SD_TEXT_TYPE_ASS;
|
||||||
|
else if (!strcmp(ka->key, "ass-full"))
|
||||||
|
type = SD_TEXT_TYPE_ASS_FULL;
|
||||||
else
|
else
|
||||||
return M_PROPERTY_UNKNOWN;
|
return M_PROPERTY_UNKNOWN;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ enum sd_ctrl {
|
|||||||
enum sd_text_type {
|
enum sd_text_type {
|
||||||
SD_TEXT_TYPE_PLAIN,
|
SD_TEXT_TYPE_PLAIN,
|
||||||
SD_TEXT_TYPE_ASS,
|
SD_TEXT_TYPE_ASS,
|
||||||
|
SD_TEXT_TYPE_ASS_FULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sd_times {
|
struct sd_times {
|
||||||
|
|||||||
22
sub/sd_ass.c
22
sub/sd_ass.c
@@ -795,6 +795,28 @@ static bstr get_text_buf(struct sd *sd, double pts, enum sd_text_type type)
|
|||||||
int start = b->len;
|
int start = b->len;
|
||||||
if (type == SD_TEXT_TYPE_PLAIN) {
|
if (type == SD_TEXT_TYPE_PLAIN) {
|
||||||
ass_to_plaintext(b, event->Text);
|
ass_to_plaintext(b, event->Text);
|
||||||
|
} else if (type == SD_TEXT_TYPE_ASS_FULL) {
|
||||||
|
long long s = event->Start;
|
||||||
|
long long e = s + event->Duration;
|
||||||
|
|
||||||
|
ASS_Style *style = (event->Style < 0 || event->Style >= track->n_styles) ? NULL : &track->styles[event->Style];
|
||||||
|
|
||||||
|
int sh = (s / 60 / 60 / 1000);
|
||||||
|
int sm = (s / 60 / 1000) % 60;
|
||||||
|
int ss = (s / 1000) % 60;
|
||||||
|
int sc = (s / 10) % 100;
|
||||||
|
int eh = (e / 60 / 60 / 1000);
|
||||||
|
int em = (e / 60 / 1000) % 60;
|
||||||
|
int es = (e / 1000) % 60;
|
||||||
|
int ec = (e / 10) % 100;
|
||||||
|
|
||||||
|
bstr_xappend_asprintf(NULL, b, "Dialogue: %d,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,%s,%s,%04d,%04d,%04d,%s,%s",
|
||||||
|
event->Layer,
|
||||||
|
sh, sm, ss, sc,
|
||||||
|
eh, em, es, ec,
|
||||||
|
(style && style->Name) ? style->Name : "", event->Name,
|
||||||
|
event->MarginL, event->MarginR, event->MarginV,
|
||||||
|
event->Effect, event->Text);
|
||||||
} else {
|
} else {
|
||||||
bstr_xappend(NULL, b, bstr0(event->Text));
|
bstr_xappend(NULL, b, bstr0(event->Text));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user