Beispiel #1
0
static av_cold int init(AVFilterContext *ctx)
{
    AssContext *ass = ctx->priv;

    if (!ass->filename) {
        av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
        return AVERROR(EINVAL);
    }

    ass->library = ass_library_init();
    if (!ass->library) {
        av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n");
        return AVERROR(EINVAL);
    }
    ass_set_message_cb(ass->library, ass_log, ctx);

    ass_set_fonts_dir(ass->library, ass->fontsdir);

    ass->renderer = ass_renderer_init(ass->library);
    if (!ass->renderer) {
        av_log(ctx, AV_LOG_ERROR, "Could not initialize libass renderer.\n");
        return AVERROR(EINVAL);
    }

    return 0;
}
Beispiel #2
0
static void
_init()
{
	static bool init_done = false;

	void ass_init()
	{
#ifdef USE_LIBASS
		ass_library = ass_library_init();
		if (!ass_library) {
			printf("ass_library_init failed!\n");
			exit(EXIT_FAILURE);
		}

#ifdef DEBUG
		ass_set_message_cb(ass_library, msg_callback, NULL);
#endif

		ass_renderer = ass_renderer_init(ass_library);
		if (!ass_renderer) {
			printf("ass_renderer_init failed!\n");
			exit(EXIT_FAILURE);
		}

		ass_set_fonts(ass_renderer, NULL, "Sans", 1, NULL, 1);
#endif
	}
SubtitleProcessorLibASS::SubtitleProcessorLibASS()
    : m_ass(0)
    , m_renderer(0)
    , m_track(0)
{
    if (!ass::api::loaded())
        return;
    m_ass = ass_library_init();
    if (!m_ass) {
        qWarning("ass_library_init failed!");
        return;
    }
    ass_set_message_cb(m_ass, msg_callback, NULL);
    m_renderer = ass_renderer_init(m_ass);
    if (!m_renderer) {
        qWarning("ass_renderer_init failed!");
        return;
    }
#if LIBASS_VERSION >= 0x01000000
    ass_set_shaper(m_renderer, ASS_SHAPING_SIMPLE);
#endif
    //ass_set_frame_size(m_renderer, frame_w, frame_h);
    //ass_set_fonts(m_renderer, NULL, "Sans", 1, NULL, 1); //must set!
    ass_set_fonts(m_renderer, NULL, NULL, 1, NULL, 1);
}
Beispiel #4
0
ASS_Library* ass_init(void) {
	ASS_Library* priv;
	char* path = get_path("fonts");
	priv = ass_library_init();
	ass_set_message_cb(priv, message_callback, NULL);
	ass_set_fonts_dir(priv, path);
	ass_mp_reset_config(priv);
	free(path);
	return priv;
}
Beispiel #5
0
ASS_Library* ass_init(void) {
	ASS_Library* priv;
	char* path = get_path("fonts");
	priv = ass_library_init();
	ass_set_message_cb(priv, message_callback, NULL);
	ass_set_fonts_dir(priv, path);
	ass_set_extract_fonts(priv, extract_embedded_fonts);
	ass_set_style_overrides(priv, ass_force_style_list);
	free(path);
	return priv;
}
Beispiel #6
0
int main(int argc, char *argv[])
{
    /*if (argc < 3) {
        printf("usage: %s <image file> <subtitle file> <time>\n", argv[0]);
        exit(1);
    }*/

    char *subfile = "in.ass";
    double tm = 10;

    ass_library = ass_library_init();
    if (!ass_library) {
        printf("ass_library_init failed!\n");
        exit(1);
    }

    ass_set_message_cb(ass_library, msg_callback, NULL);

    ass_renderer = ass_renderer_init(ass_library);
    if (!ass_renderer) {
        printf("ass_renderer_init failed!\n");
        exit(1);
    }
    
    track = ass_read_file(ass_library, subfile, NULL);
    if (!track) {
        printf("track init failed!\n");
        return 1;
    }

    int frame_w = track->PlayResX;
    int frame_h = track->PlayResY;

    ass_set_frame_size(ass_renderer, frame_w, frame_h);
    ass_set_fonts(ass_renderer, "font.ttf", "Sans", 1, NULL, 1);
    ass_set_cache_limits(ass_renderer, 100, 1);

    SDL_Init(SDL_INIT_VIDEO);
    SDL_CreateWindowAndRenderer(frame_w, frame_h, 0, &window, &renderer);
    SDL_SetRenderDrawColor(renderer, 47, 163, 254, 255);
    
    emscripten_set_main_loop(loop, 0, 1);

    //SDL_Quit();

    //ass_free_track(track);
    //ass_renderer_done(ass_renderer);
    //ass_library_done(ass_library);

    return 0;
}
void CacheFonts() {
	// Initialize the cache worker thread
	cache_queue = agi::dispatch::Create();

	// Initialize libass
	library = ass_library_init();
	ass_set_message_cb(library, msg_callback, nullptr);

	// Initialize a renderer to force fontconfig to update its cache
	cache_queue->Async([]{
		auto ass_renderer = ass_renderer_init(library);
		ass_set_fonts(ass_renderer, nullptr, "Sans", 1, CONFIG_PATH, true);
		ass_renderer_done(ass_renderer);
	});
}
Beispiel #8
0
static void init(int frame_w, int frame_h) {
  ass_library = ass_library_init();
  if (!ass_library) {
    printf("ass_library_init failed!\n");
    exit(1);
  }

  ass_set_message_cb(ass_library, msg_callback, NULL);

  ass_renderer = ass_renderer_init(ass_library);
  if (!ass_renderer) {
    printf("ass_renderer_init failed!\n");
    exit(1);
  }

  ass_set_frame_size(ass_renderer, frame_w, frame_h);
  ass_set_fonts(ass_renderer, NULL, "Sans", 1, NULL, 1);
}
Beispiel #9
0
CDVDSubtitlesLibass::CDVDSubtitlesLibass()
{
  //Setting the font directory to the temp dir(where mkv fonts are extracted to)
  std::string strPath = "special://temp/fonts/";

  CLog::Log(LOGINFO, "CDVDSubtitlesLibass: Creating ASS library structure");
  m_library = ass_library_init();
  if(!m_library)
    return;

  ass_set_message_cb(m_library, libass_log, this);

  CLog::Log(LOGINFO, "CDVDSubtitlesLibass: Initializing ASS library font settings");
  // libass uses fontconfig (system lib) which is not wrapped
  //  so translate the path before calling into libass
  ass_set_fonts_dir(m_library,  CSpecialProtocol::TranslatePath(strPath).c_str());
  ass_set_extract_fonts(m_library, 1);
  ass_set_style_overrides(m_library, NULL);

  CLog::Log(LOGINFO, "CDVDSubtitlesLibass: Initializing ASS Renderer");

  m_renderer = ass_renderer_init(m_library);

  if(!m_renderer)
    return;

  //Setting default font to the Arial in \media\fonts (used if FontConfig fails)
  const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  strPath = URIUtils::AddFileToFolder("special://home/media/Fonts/", settings->GetString(CSettings::SETTING_SUBTITLES_FONT));
  if (!XFILE::CFile::Exists(strPath))
    strPath = URIUtils::AddFileToFolder("special://xbmc/media/Fonts/", settings->GetString(CSettings::SETTING_SUBTITLES_FONT));
  int fc = !settings->GetBool(CSettings::SETTING_SUBTITLES_OVERRIDEASSFONTS);

  ass_set_margins(m_renderer, 0, 0, 0, 0);
  ass_set_use_margins(m_renderer, 0);
  ass_set_font_scale(m_renderer, 1);

  // libass uses fontconfig (system lib) which is not wrapped
  //  so translate the path before calling into libass
  ass_set_fonts(m_renderer, CSpecialProtocol::TranslatePath(strPath).c_str(), "Arial", fc, NULL, 1);
}
Beispiel #10
0
static void
_init()
{
    static bool init_done = false;

    void ass_init()
    {
#ifdef DEBUG
        void msg_callback(int level, const char* fmt, va_list va, void* data)
        {
            if (wf_debug < 2 || level > 6) return;
            printf("libass: ");
            vprintf(fmt, va);
            printf("\n");
        }
#endif

#ifdef USE_LIBASS
        ass_library = ass_library_init();
        if (!ass_library) {
            printf("ass_library_init failed!\n");
            exit(EXIT_FAILURE);
        }

#ifdef DEBUG
        ass_set_message_cb(ass_library, msg_callback, NULL);
#endif

        ass_renderer = ass_renderer_init(ass_library);
        if (!ass_renderer) {
            printf("ass_renderer_init failed!\n");
            exit(EXIT_FAILURE);
        }

        ass_set_fonts(ass_renderer, NULL, "Sans", 1, NULL, 1);
#endif
    }
Beispiel #11
0
static void VS_CC assInit(VSMap *in, VSMap *out, void **instanceData,
                          VSNode *node, VSCore *core, const VSAPI *vsapi)
{
    AssData *d = (AssData *) * instanceData;
    vsapi->setVideoInfo(d->vi, 2, node);

    d->ass_library = ass_library_init();

    if(!d->ass_library) {
        vsapi->setError(out, "failed to initialize ASS library");
        return;
    }

    ass_set_message_cb(d->ass_library, assDebugCallback, (void *)d->debuglevel);
    ass_set_extract_fonts(d->ass_library, 0);
    ass_set_style_overrides(d->ass_library, 0);

    d->ass_renderer = ass_renderer_init(d->ass_library);

    if(!d->ass_renderer) {
        vsapi->setError(out, "failed to initialize ASS renderer");
        return;
    }

    ass_set_font_scale(d->ass_renderer, d->scale);
    ass_set_frame_size(d->ass_renderer, d->vi[0].width, d->vi[0].height);
    ass_set_margins(d->ass_renderer,
                    d->margins[0], d->margins[1], d->margins[2], d->margins[3]);
    ass_set_use_margins(d->ass_renderer, 1);

    if(d->linespacing)
        ass_set_line_spacing(d->ass_renderer, d->linespacing);

    if(d->sar) {
        ass_set_aspect_ratio(d->ass_renderer,
                             (double)d->vi[0].width /
                             d->vi[0].height * d->sar, 1);
    }

    if(d->fontdir)
        ass_set_fonts_dir(d->ass_library, d->fontdir);

    ass_set_fonts(d->ass_renderer, NULL, NULL, 1, NULL, 1);

    if(d->file == NULL) {
        char *str, *text, x[16], y[16];
        size_t siz;
        const char *fmt = "[Script Info]\n"
                          "ScriptType: v4.00+\n"
                          "PlayResX: %s\n"
                          "PlayResY: %s\n"
                          "[V4+ Styles]\n"
                          "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n"
                          "Style: Default,%s\n"
                          "[Events]\n"
                          "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n"
                          "Dialogue: 0,0:00:00.00,0:00:10.00,Default,,0,0,0,,%s\n";

        sprintf(x, "%d", d->vi[0].width);
        sprintf(y, "%d", d->vi[0].height);

        text = strrepl(d->text, "\n", "\\N");

        siz = (strlen(fmt) + strlen(x) + strlen(y) + strlen(d->style) +
               strlen(text)) * sizeof(char);

        str = malloc(siz);
        sprintf(str, fmt, x, y, d->style, text);

        free(text);

        d->ass = ass_new_track(d->ass_library);
        ass_process_data(d->ass, str, strlen(str));

        free(str);
    } else {
        d->ass = ass_read_file(d->ass_library, (char *)d->file, (char *)d->charset);
    }

    if(!d->ass) {
        vsapi->setError(out, "unable to parse input file");
        return;
    }
}
void LibassSubtitlesProvider::CacheFonts() {
	ass_library = ass_library_init();
	ass_set_message_cb(ass_library, msg_callback, NULL);
	new FontConfigCacheThread(ass_library, &cache_worker);
}