int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, int ts_start, int duration, int raw) { AVBPrint buf; int ret, dlen; AVSubtitleRect **rects; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); if (!raw) { av_bprintf(&buf, "Dialogue: 0,"); insert_ts(&buf, ts_start); insert_ts(&buf, duration == -1 ? -1 : ts_start + duration); av_bprintf(&buf, "Default,"); } dlen = strcspn(dialog, "\n"); dlen += dialog[dlen] == '\n'; av_bprintf(&buf, "%.*s", dlen, dialog); if (!av_bprint_is_complete(&buf)) return AVERROR(ENOMEM); rects = av_realloc(sub->rects, (sub->num_rects+1) * sizeof(*sub->rects)); if (!rects) return AVERROR(ENOMEM); sub->rects = rects; sub->end_display_time = FFMAX(sub->end_display_time, 10 * duration); rects[sub->num_rects] = av_mallocz(sizeof(*rects[0])); rects[sub->num_rects]->type = SUBTITLE_ASS; ret = av_bprint_finalize(&buf, &rects[sub->num_rects]->ass); if (ret < 0) return ret; sub->num_rects++; return dlen; }
int ff_ass_bprint_dialog(AVBPrint *buf, const char *dialog, int ts_start, int duration, int raw) { int dlen; if (!raw || raw == 2) { long int layer = 0; if (raw == 2) { /* skip ReadOrder */ dialog = strchr(dialog, ','); if (!dialog) return AVERROR_INVALIDDATA; dialog++; /* extract Layer or Marked */ layer = strtol(dialog, (char**)&dialog, 10); if (*dialog != ',') return AVERROR_INVALIDDATA; dialog++; } av_bprintf(buf, "Dialogue: %ld,", layer); insert_ts(buf, ts_start); insert_ts(buf, duration == -1 ? -1 : ts_start + duration); if (raw != 2) av_bprintf(buf, "Default,,0,0,0,,"); } dlen = strcspn(dialog, "\n"); dlen += dialog[dlen] == '\n'; av_bprintf(buf, "%.*s", dlen, dialog); if (raw == 2) av_bprintf(buf, "\r\n"); return dlen; }