|
|
@ -23,6 +23,7 @@ |
|
|
|
#include "ass.h" |
|
|
|
#include "ass.h" |
|
|
|
#include "libavutil/avassert.h" |
|
|
|
#include "libavutil/avassert.h" |
|
|
|
#include "libavutil/avstring.h" |
|
|
|
#include "libavutil/avstring.h" |
|
|
|
|
|
|
|
#include "libavutil/bprint.h" |
|
|
|
#include "libavutil/common.h" |
|
|
|
#include "libavutil/common.h" |
|
|
|
|
|
|
|
|
|
|
|
int ff_ass_subtitle_header(AVCodecContext *avctx, |
|
|
|
int ff_ass_subtitle_header(AVCodecContext *avctx, |
|
|
@ -62,36 +63,42 @@ int ff_ass_subtitle_header_default(AVCodecContext *avctx) |
|
|
|
ASS_DEFAULT_ALIGNMENT); |
|
|
|
ASS_DEFAULT_ALIGNMENT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int ts_to_string(char *str, int strlen, int ts) |
|
|
|
static void insert_ts(AVBPrint *buf, int ts) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int h, m, s; |
|
|
|
if (ts == -1) { |
|
|
|
h = ts/360000; ts -= 360000*h; |
|
|
|
av_bprintf(buf, "9:59:59.99,"); |
|
|
|
m = ts/ 6000; ts -= 6000*m; |
|
|
|
} else { |
|
|
|
s = ts/ 100; ts -= 100*s; |
|
|
|
int h, m, s; |
|
|
|
return snprintf(str, strlen, "%d:%02d:%02d.%02d", h, m, s, ts); |
|
|
|
|
|
|
|
|
|
|
|
h = ts/360000; ts -= 360000*h; |
|
|
|
|
|
|
|
m = ts/ 6000; ts -= 6000*m; |
|
|
|
|
|
|
|
s = ts/ 100; ts -= 100*s; |
|
|
|
|
|
|
|
av_bprintf(buf, "%d:%02d:%02d.%02d,", h, m, s, ts); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, |
|
|
|
int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, |
|
|
|
int ts_start, int duration, int raw) |
|
|
|
int ts_start, int duration, int raw) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int len = 0, dlen; |
|
|
|
AVBPrint buf; |
|
|
|
char s_start[16], s_end[16], header[48] = {0}; |
|
|
|
int ret, dlen; |
|
|
|
AVSubtitleRect **rects; |
|
|
|
AVSubtitleRect **rects; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); |
|
|
|
if (!raw) { |
|
|
|
if (!raw) { |
|
|
|
ts_to_string(s_start, sizeof(s_start), ts_start); |
|
|
|
av_bprintf(&buf, "Dialogue: 0,"); |
|
|
|
if (duration == -1) |
|
|
|
insert_ts(&buf, ts_start); |
|
|
|
snprintf(s_end, sizeof(s_end), "9:59:59.99"); |
|
|
|
insert_ts(&buf, duration == -1 ? -1 : ts_start + duration); |
|
|
|
else |
|
|
|
av_bprintf(&buf, "Default,"); |
|
|
|
ts_to_string(s_end, sizeof(s_end), ts_start + duration); |
|
|
|
|
|
|
|
len = snprintf(header, sizeof(header), "Dialogue: 0,%s,%s,Default,", |
|
|
|
|
|
|
|
s_start, s_end); |
|
|
|
|
|
|
|
av_assert0(len < sizeof(header)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dlen = strcspn(dialog, "\n"); |
|
|
|
dlen = strcspn(dialog, "\n"); |
|
|
|
dlen += dialog[dlen] == '\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)); |
|
|
|
rects = av_realloc(sub->rects, (sub->num_rects+1) * sizeof(*sub->rects)); |
|
|
|
if (!rects) |
|
|
|
if (!rects) |
|
|
|
return AVERROR(ENOMEM); |
|
|
|
return AVERROR(ENOMEM); |
|
|
@ -99,9 +106,9 @@ int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, |
|
|
|
sub->end_display_time = FFMAX(sub->end_display_time, 10 * duration); |
|
|
|
sub->end_display_time = FFMAX(sub->end_display_time, 10 * duration); |
|
|
|
rects[sub->num_rects] = av_mallocz(sizeof(*rects[0])); |
|
|
|
rects[sub->num_rects] = av_mallocz(sizeof(*rects[0])); |
|
|
|
rects[sub->num_rects]->type = SUBTITLE_ASS; |
|
|
|
rects[sub->num_rects]->type = SUBTITLE_ASS; |
|
|
|
rects[sub->num_rects]->ass = av_malloc(len + dlen + 1); |
|
|
|
ret = av_bprint_finalize(&buf, &rects[sub->num_rects]->ass); |
|
|
|
strcpy (rects[sub->num_rects]->ass , header); |
|
|
|
if (ret < 0) |
|
|
|
av_strlcpy(rects[sub->num_rects]->ass + len, dialog, dlen + 1); |
|
|
|
return ret; |
|
|
|
sub->num_rects++; |
|
|
|
sub->num_rects++; |
|
|
|
return dlen; |
|
|
|
return dlen; |
|
|
|
} |
|
|
|
} |
|
|
|