mirror of
https://github.com/mpv-player/mpv
synced 2025-01-11 17:39:38 +00:00
Add subdata to ass_track conversion for external subtitles.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@19407 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
37790bdbc4
commit
e3bf2d7343
@ -1,3 +1,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ass.h"
|
||||
#include "ass_mp.h"
|
||||
|
||||
// libass-related command line options
|
||||
@ -8,3 +12,98 @@ int ass_top_margin = 0;
|
||||
int ass_bottom_margin = 0;
|
||||
int extract_embedded_fonts = 0;
|
||||
|
||||
extern int font_fontconfig;
|
||||
extern char* font_name;
|
||||
extern float text_font_scale_factor;
|
||||
extern int subtitle_autoscale;
|
||||
|
||||
extern double ass_internal_font_size_coeff;
|
||||
|
||||
/**
|
||||
* \brief Convert subdata to ass_track
|
||||
* \param subdata subtitles struct from subreader
|
||||
* \param fps video framerate
|
||||
* \return newly allocated ass_track, filled with subtitles from subdata
|
||||
*/
|
||||
ass_track_t* ass_read_subdata(sub_data* subdata, double fps) {
|
||||
ass_track_t* track = ass_new_track();
|
||||
ass_style_t* style;
|
||||
ass_event_t* event;
|
||||
subtitle* sub;
|
||||
int sid, eid;
|
||||
int i;
|
||||
double fs;
|
||||
|
||||
track->track_type = TRACK_TYPE_ASS;
|
||||
track->name = subdata->filename ? strdup(subdata->filename) : 0;
|
||||
track->Timer = 100.;
|
||||
track->PlayResX = 384;
|
||||
track->PlayResY = 288;
|
||||
track->WrapStyle = 0;
|
||||
|
||||
sid = ass_alloc_style(track);
|
||||
style = track->styles + sid;
|
||||
style->Name = strdup("Default");
|
||||
style->FontName = font_fontconfig ? strdup(font_name) : strdup("Tahoma");
|
||||
|
||||
fs = track->PlayResY * text_font_scale_factor / 100. / ass_internal_font_size_coeff;
|
||||
// approximate autoscale coefficients
|
||||
if (subtitle_autoscale == 2)
|
||||
fs *= 1.3;
|
||||
else if (subtitle_autoscale == 3)
|
||||
fs *= 1.4;
|
||||
style->FontSize = fs;
|
||||
|
||||
style->PrimaryColour = 0xC0E9FE00;
|
||||
style->SecondaryColour = 0x1B429E00;
|
||||
style->OutlineColour = 0x1B429E00;
|
||||
style->BackColour = 0x00000000;
|
||||
style->BorderStyle = 1;
|
||||
style->Alignment = 2;
|
||||
style->Outline = 2;
|
||||
style->MarginL = 30;
|
||||
style->MarginR = 30;
|
||||
style->MarginV = 20;
|
||||
style->ScaleX = 1.;
|
||||
style->ScaleY = 1.;
|
||||
|
||||
for (i = 0; i < subdata->sub_num; ++i) {
|
||||
int len = 0, j;
|
||||
char* p;
|
||||
char* end;
|
||||
sub = subdata->subtitles + i;
|
||||
eid = ass_alloc_event(track);
|
||||
event = track->events + eid;
|
||||
|
||||
event->Start = sub->start * 10;
|
||||
event->Duration = (sub->end - sub->start) * 10;
|
||||
if (!subdata->sub_uses_time) {
|
||||
event->Start *= 100. / fps;
|
||||
event->Duration *= 100. / fps;
|
||||
}
|
||||
|
||||
event->Style = sid;
|
||||
|
||||
for (j = 0; j < sub->lines; ++j)
|
||||
len += sub->text[j] ? strlen(sub->text[j]) : 0;
|
||||
|
||||
len += 2 * sub->lines; // '\N', including the one after the last line
|
||||
len += 6; // {\anX}
|
||||
len += 1; // '\0'
|
||||
|
||||
event->Text = malloc(len);
|
||||
end = event->Text + len;
|
||||
p = event->Text;
|
||||
|
||||
if (sub->alignment)
|
||||
p += snprintf(p, end - p, "{\\an%d}", sub->alignment);
|
||||
|
||||
for (j = 0; j < sub->lines; ++j)
|
||||
p += snprintf(p, end - p, "%s ", sub->text[j]);
|
||||
|
||||
p--; // remove last ' '
|
||||
*p = 0;
|
||||
}
|
||||
return track;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef __ASS_OPTIONS_H__
|
||||
#define __ASS_OPTIONS_H__
|
||||
|
||||
#include "subreader.h"
|
||||
|
||||
extern int ass_enabled;
|
||||
extern float ass_font_scale;
|
||||
extern float ass_line_spacing;
|
||||
@ -8,5 +10,7 @@ extern int ass_top_margin;
|
||||
extern int ass_bottom_margin;
|
||||
extern int extract_embedded_fonts;
|
||||
|
||||
ass_track_t* ass_read_subdata(sub_data* subdata, double fps);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -479,9 +479,11 @@ static inline int mystrcmp(char** p, const char* sample) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double ass_internal_font_size_coeff = 0.8;
|
||||
|
||||
static void change_font_size(int sz)
|
||||
{
|
||||
double size = (double)sz * global_settings->font_size_coeff * 0.8;
|
||||
double size = (double)sz * global_settings->font_size_coeff * ass_internal_font_size_coeff;
|
||||
size *= frame_context.height;
|
||||
size /= frame_context.track->PlayResY;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user