Example #1
0
ASS_Track* ass_default_track(ASS_Library* library) {
	ASS_Track* track = ass_new_track(library);

	track->track_type = TRACK_TYPE_ASS;
	track->Timer = 100.;
	track->PlayResY = 360;
	track->WrapStyle = 0;

	if (track->n_styles == 0) {
		// stupid hack to stop libass to add a default track
		// in front in ass_read_styles - this makes it impossible
		// to completely override the "Default" track.
		int sid = ass_alloc_style(track);
		init_style(track->styles + sid, "MPlayerDummy", track->PlayResY);
	}

	if (ass_styles_file)
		ass_read_styles(track, ass_styles_file, sub_cp);


	if (track->default_style <= 0) {
		int sid = ass_alloc_style(track);
		init_style(track->styles + sid, "Default", track->PlayResY);
		track->default_style = sid;
		if(fake_video) {
			track->PlayResX = 480;
			track->PlayResY = 270;
		}
	}

	ass_process_force_style(track);
	return track;
}
Example #2
0
File: ass_mp.c Project: kax4/mpv
ASS_Track *mp_ass_default_track(ASS_Library *library, struct MPOpts *opts)
{
    ASS_Track *track = ass_new_track(library);

    track->track_type = TRACK_TYPE_ASS;
    track->Timer = 100.;
    track->PlayResY = MP_ASS_FONT_PLAYRESY;
    track->WrapStyle = 0;

    if (opts->ass_styles_file && opts->ass_style_override)
        ass_read_styles(track, opts->ass_styles_file, sub_cp);

    if (track->n_styles == 0) {
        track->Kerning = true;
        int sid = ass_alloc_style(track);
        track->default_style = sid;
        ASS_Style *style = track->styles + sid;
        style->Name = strdup("Default");
        style->Alignment = 2;
        mp_ass_set_style(style, opts->sub_text_style);
    }

    if (opts->ass_style_override)
        ass_process_force_style(track);

    return track;
}
Example #3
0
/**
 * \brief Parse the tail of Dialogue line
 * \param track track
 * \param event parsed data goes here
 * \param str string to parse, zero-terminated
 * \param n_ignored number of format options to skip at the beginning
*/
static int process_event_tail(ASS_Track *track, ASS_Event *event,
                              char *str, int n_ignored)
{
    char *token;
    char *tname;
    char *p = str;
    int i;
    ASS_Event *target = event;

    char *format = strdup(track->event_format);
    char *q = format;           // format scanning pointer

    if (track->n_styles == 0) {
        // add "Default" style to the end
        // will be used if track does not contain a default style (or even does not contain styles at all)
        int sid = ass_alloc_style(track);
        set_default_style(&track->styles[sid]);
        track->default_style = sid;
    }

    for (i = 0; i < n_ignored; ++i) {
        NEXT(q, tname);
    }

    while (1) {
        NEXT(q, tname);
        if (strcasecmp(tname, "Text") == 0) {
            char *last;
            event->Text = strdup(p);
            if (*event->Text != 0) {
                last = event->Text + strlen(event->Text) - 1;
                if (last >= event->Text && *last == '\r')
                    *last = 0;
            }
            ass_msg(track->library, MSGL_DBG2, "Text = %s", event->Text);
            event->Duration -= event->Start;
            free(format);
            return 0;           // "Text" is always the last
        }
        NEXT(p, token);

        ALIAS(End, Duration)    // temporarily store end timecode in event->Duration
        if (0) {            // cool ;)
            INTVAL(Layer)
            STYLEVAL(Style)
            STRVAL(Name)
            STRVAL(Effect)
            INTVAL(MarginL)
            INTVAL(MarginR)
            INTVAL(MarginV)
            TIMEVAL(Start)
            TIMEVAL(Duration)
        }
    }
    free(format);
    return 1;
}
Example #4
0
ASS_Track* ass_default_track(ASS_Library* library) {
	ASS_Track* track = ass_new_track(library);

	track->track_type = TRACK_TYPE_ASS;
	track->Timer = 100.;
	track->PlayResY = 288;
	track->WrapStyle = 0;

	if (ass_styles_file)
		ass_read_styles(track, ass_styles_file, sub_cp);

	if (track->n_styles == 0) {
		ASS_Style* style;
		int sid;
		double fs;
		uint32_t c1, c2;

		sid = ass_alloc_style(track);
		style = track->styles + sid;
		style->Name = strdup("Default");
		style->FontName = (font_fontconfig >= 0 && sub_font_name) ? strdup(sub_font_name) : (font_fontconfig >= 0 && font_name) ? strdup(font_name) : strdup("Sans");
		style->treat_fontname_as_pattern = 1;

		fs = track->PlayResY * text_font_scale_factor / 100.;
		// approximate autoscale coefficients
		if (subtitle_autoscale == 2)
			fs *= 1.3;
		else if (subtitle_autoscale == 3)
			fs *= 1.4;
		style->FontSize = fs;

		if (ass_color) c1 = strtoll(ass_color, NULL, 16);
		else c1 = 0xFFFF0000;
		if (ass_border_color) c2 = strtoll(ass_border_color, NULL, 16);
		else c2 = 0x00000000;

		style->PrimaryColour = c1;
		style->SecondaryColour = c1;
		style->OutlineColour = c2;
		style->BackColour = 0x00000000;
		style->BorderStyle = 1;
		style->Alignment = 2;
		style->Outline = 2;
		style->MarginL = 10;
		style->MarginR = 10;
		style->MarginV = 5;
		style->ScaleX = 1.;
		style->ScaleY = 1.;
	}

	ass_process_force_style(track);
	return track;
}
Example #5
0
void LibASS::initOSD()
{
	if (osd_track && osd_style && osd_event && osd_renderer)
		return;

	osd_track = ass_new_track(ass);

	int styleID = ass_alloc_style(osd_track);
	osd_style = &osd_track->styles[styleID];
	setOSDStyle();

	int eventID = ass_alloc_event(osd_track);
	osd_event = &osd_track->events[eventID];
	osd_event->Start = 0;
	osd_event->Duration = 1;
	osd_event->Style = styleID;
	osd_event->ReadOrder = eventID;

	osd_renderer = ass_renderer_init(ass);
	ass_set_fonts(osd_renderer, NULL, NULL, 1, NULL, 1);
}
Example #6
0
// Add default styles, if the track does not have any styles yet.
// Apply style overrides if the user provides any.
static void mp_ass_add_default_styles(ASS_Track *track, struct MPOpts *opts)
{
    if (opts->ass_styles_file && opts->ass_style_override)
        ass_read_styles(track, opts->ass_styles_file, NULL);

    if (track->n_styles == 0) {
        if (!track->PlayResY) {
            track->PlayResY = MP_ASS_FONT_PLAYRESY;
            track->PlayResX = track->PlayResY * 4 / 3;
        }
        track->Kerning = true;
        int sid = ass_alloc_style(track);
        track->default_style = sid;
        ASS_Style *style = track->styles + sid;
        style->Name = strdup("Default");
        mp_ass_set_style(style, track->PlayResY, opts->sub_text_style);
    }

    if (opts->ass_style_override)
        ass_process_force_style(track);
}
Example #7
0
void LibASS::initASS(const QByteArray &ass_data)
{
	if (ass_sub_track && ass_sub_renderer)
		return;

	ass_sub_track = ass_new_track(ass);
	if (!ass_data.isEmpty())
	{
		ass_process_data(ass_sub_track, (char *)ass_data.data(), ass_data.size());
		hasASSData = true;
		setASSStyle();
	}
	else
	{
		ass_alloc_style(ass_sub_track);
		ass_sub_track->styles[0].ScaleX = ass_sub_track->styles[0].ScaleY = 1;
		overridePlayRes = true;
		hasASSData = false;
		setASSStyle();
	}

	ass_sub_renderer = ass_renderer_init(ass);
	ass_set_fonts(ass_sub_renderer, NULL, NULL, true, NULL, true);
}
Example #8
0
ASS_Track *mp_ass_default_track(ASS_Library *library)
{
    ASS_Track *track = ass_new_track(library);

    track->track_type = TRACK_TYPE_ASS;
    track->Timer = 100.;
    track->PlayResY = 288;
    track->WrapStyle = 0;

    if (ass_styles_file)
        ass_read_styles(track, ass_styles_file, sub_cp);

    if (track->n_styles == 0) {
        track->Kerning = true;
        int sid = ass_alloc_style(track);
        ASS_Style *style = track->styles + sid;
        style->Name = strdup("Default");
        style->FontName = (font_fontconfig >= 0
                           && sub_font_name) ? strdup(sub_font_name)
            : (font_fontconfig >= 0
               && font_name) ? strdup(font_name) : strdup("Sans");
        style->treat_fontname_as_pattern = 1;

        double fs = track->PlayResY * text_font_scale_factor / 100.;
        /* The font size is always proportional to video height only;
         * real -subfont-autoscale behavior is not implemented.
         * Apply a correction that corresponds to about 4:3 aspect ratio
         * video to get a size somewhat closer to what non-libass rendering
         * would produce with the same text_font_scale_factor
         * and subtitle_autoscale.
         */
        if (subtitle_autoscale == 2)
            fs *= 1.3;
        else if (subtitle_autoscale == 3)
            fs *= 1.7;

        uint32_t c1 = 0xFFFFFF00;
        uint32_t c2 = 0x00000000;
        if (ass_color)
            c1 = strtoll(ass_color, NULL, 16);
        if (ass_border_color)
            c2 = strtoll(ass_border_color, NULL, 16);

        style->FontSize = fs;
        style->PrimaryColour = c1;
        style->SecondaryColour = c1;
        style->OutlineColour = c2;
        style->BackColour = 0x00000000;
        style->BorderStyle = 1;
        style->Alignment = 2;
        style->Outline = fs / 16;
        style->MarginL = 10;
        style->MarginR = 10;
        style->MarginV = 5;
        style->ScaleX = 1.;
        style->ScaleY = 1.;
    }

    ass_process_force_style(track);
    return track;
}