示例#1
0
文件: test.c 项目: banketree/faplayer
int main(int argc, char *argv[])
{
    const int frame_w = 640;
    const int frame_h = 480;

    if (argc < 4) {
        printf("usage: %s <image file> <subtitle file> <time>\n", argv[0]);
        exit(1);
    }
    char *imgfile = argv[1];
    char *subfile = argv[2];
    double tm = strtod(argv[3], 0);

    init(frame_w, frame_h);
    ASS_Track *track = ass_read_file(ass_library, subfile, NULL);
    if (!track) {
        printf("track init failed!\n");
        return 1;
    }

    ASS_Image *img =
        ass_render_frame(ass_renderer, track, (int) (tm * 1000), NULL);
    image_t *frame = gen_image(frame_w, frame_h);
    blend(frame, img);

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

    write_png(imgfile, frame);

    return 0;
}
示例#2
0
ASS_Track *libass_load_subtitles(LibassConfiguration *libass_conf,
                                    char *subtitles_path)
{
    ASS_Track *subtitles = NULL;
    subtitles = ass_read_file(libass_conf->library, subtitles_path, "utf-8");
    if (subtitles == NULL){
        printf("Couldn't load the subtitles : %s\n",subtitles_path);
        exit(EXIT_FAILURE);
    }
}
示例#3
0
bool BigPotSubtitleAss::openSubtitle(const string& filename)
{
	//函数的参数是char*,为免意外复制一份
	auto s = filename;
	//if (checkFileExt(filename))
		_track = ass_read_file(_lib, (char*)s.c_str(), NULL);
	haveSubtitle_ = (_track != nullptr);
	if (haveSubtitle_) subfilename_ = filename;
	return 	haveSubtitle_;
}
示例#4
0
文件: gencmd.c 项目: whhone/jeetou
int main(int argc, char *argv[]) {
  if (argc < 5) {
    printf("usage: %s <video_file> <subtitle_file>\n", argv[0]);
    exit(1);
  }
  char *videofile = argv[1];
  char *subfile = argv[2];
  const int frame_w = atoi(argv[3]);
  const int frame_h = atoi(argv[4]);

  init(frame_w, frame_h);
  ASS_Track *track = ass_read_file(ass_library, subfile, NULL);
  if (!track) {
    printf("track init failed!\n");
    return 1;
  }

  char file[1000];
  sprintf(file, "gen_%s_%s.sh", videofile, subfile);
  FILE *p;
  p = fopen(file, "w");

  int i = 0;
  double prevous_time = 0;
  double this_time = 0;

  for (i = 0; i < track->n_events; ++i) {
    ASS_Event *event = track->events + i;

    char s[1000];
    int j = 0;
    int ok = 0;
    while (!ok) {
      ok = 1;
      if (event->Text[j] == '{') {
        while (event->Text[j] && event->Text[j] != '}') {
          ++j;
        }
        ++j;
        ok = 0;
      }
    }
    this_time = (event->Start + event->Duration / 2) * 1.0 / 1000.0;
    prevous_time = this_time - 20;
    if (prevous_time <= 0) prevous_time = 0;

    fprintf(p, "./merge.sh %s %s %010.2lf %010.2lf %010.2lf \"%s\" %d %d\n",
            videofile, subfile, prevous_time, this_time - prevous_time,
            this_time, event->Text + j, frame_w, frame_h);
  }

  fclose(p);

  return 0;
}
示例#5
0
文件: test_sdl.c 项目: dead/libass.js
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;
}
示例#6
0
bool SubtitleProcessorLibASS::process(const QString &path)
{
    if (!ass::api::loaded())
        return false;
    if (m_track) {
        ass_free_track(m_track);
        m_track = 0;
    }
    m_track = ass_read_file(m_ass, (char*)path.toUtf8().constData(), NULL);
    if (!m_track) {
        qWarning("ass_read_file error, ass track init failed!");
        return false;
    }
    processTrack(m_track);
    return true;
}
示例#7
0
static av_cold int init_ass(AVFilterContext *ctx)
{
    AssContext *ass = ctx->priv;
    int ret = init(ctx);

    if (ret < 0)
        return ret;

    /* Initialize fonts */
    ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);

    ass->track = ass_read_file(ass->library, ass->filename, NULL);
    if (!ass->track) {
        av_log(ctx, AV_LOG_ERROR,
               "Could not create a libass track when reading file '%s'\n",
               ass->filename);
        return AVERROR(EINVAL);
    }
    return 0;
}
示例#8
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;
    }
}