|
|
@ -33,8 +33,6 @@ typedef struct { |
|
|
|
AVCodecContext *avctx; |
|
|
|
AVCodecContext *avctx; |
|
|
|
ASSSplitContext *ass_ctx; |
|
|
|
ASSSplitContext *ass_ctx; |
|
|
|
AVBPrint buffer; |
|
|
|
AVBPrint buffer; |
|
|
|
unsigned timestamp_end; |
|
|
|
|
|
|
|
int count; |
|
|
|
|
|
|
|
char stack[SRT_STACK_SIZE]; |
|
|
|
char stack[SRT_STACK_SIZE]; |
|
|
|
int stack_ptr; |
|
|
|
int stack_ptr; |
|
|
|
int alignment_applied; |
|
|
|
int alignment_applied; |
|
|
@ -201,35 +199,13 @@ static void srt_cancel_overrides_cb(void *priv, const char *style) |
|
|
|
static void srt_move_cb(void *priv, int x1, int y1, int x2, int y2, |
|
|
|
static void srt_move_cb(void *priv, int x1, int y1, int x2, int y2, |
|
|
|
int t1, int t2) |
|
|
|
int t1, int t2) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SRTContext *s = priv; |
|
|
|
// TODO: add a AV_PKT_DATA_SUBTITLE_POSITION side data when a new subtitles
|
|
|
|
|
|
|
|
// encoding API passing the AVPacket is available.
|
|
|
|
if (s->avctx->codec->id == AV_CODEC_ID_SRT) { |
|
|
|
|
|
|
|
char buffer[32]; |
|
|
|
|
|
|
|
int len = snprintf(buffer, sizeof(buffer), |
|
|
|
|
|
|
|
" X1:%03u X2:%03u Y1:%03u Y2:%03u", x1, x2, y1, y2); |
|
|
|
|
|
|
|
unsigned char *dummy; |
|
|
|
|
|
|
|
unsigned room; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
av_bprint_get_buffer(&s->buffer, len, &dummy, &room); |
|
|
|
|
|
|
|
if (room >= len) { |
|
|
|
|
|
|
|
memmove(s->buffer.str + s->timestamp_end + len, |
|
|
|
|
|
|
|
s->buffer.str + s->timestamp_end, |
|
|
|
|
|
|
|
s->buffer.len - s->timestamp_end + 1); |
|
|
|
|
|
|
|
memcpy(s->buffer.str + s->timestamp_end, buffer, len); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/* Increment even if av_bprint_get_buffer() did not return enough room:
|
|
|
|
|
|
|
|
the bprint structure will be treated as truncated. */ |
|
|
|
|
|
|
|
s->buffer.len += len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void srt_end_cb(void *priv) |
|
|
|
static void srt_end_cb(void *priv) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SRTContext *s = priv; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
srt_stack_push_pop(priv, 0, 1); |
|
|
|
srt_stack_push_pop(priv, 0, 1); |
|
|
|
if (s->avctx->codec->id == AV_CODEC_ID_SRT) |
|
|
|
|
|
|
|
srt_print(priv, "\r\n\r\n"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static const ASSCodesCallbacks srt_callbacks = { |
|
|
|
static const ASSCodesCallbacks srt_callbacks = { |
|
|
@ -263,19 +239,6 @@ static int srt_encode_frame(AVCodecContext *avctx, |
|
|
|
|
|
|
|
|
|
|
|
dialog = ff_ass_split_dialog(s->ass_ctx, sub->rects[i]->ass, 0, &num); |
|
|
|
dialog = ff_ass_split_dialog(s->ass_ctx, sub->rects[i]->ass, 0, &num); |
|
|
|
for (; dialog && num--; dialog++) { |
|
|
|
for (; dialog && num--; dialog++) { |
|
|
|
if (avctx->codec->id == AV_CODEC_ID_SRT) { |
|
|
|
|
|
|
|
int sh, sm, ss, sc = 10 * dialog->start; |
|
|
|
|
|
|
|
int eh, em, es, ec = 10 * dialog->end; |
|
|
|
|
|
|
|
sh = sc/3600000; sc -= 3600000*sh; |
|
|
|
|
|
|
|
sm = sc/ 60000; sc -= 60000*sm; |
|
|
|
|
|
|
|
ss = sc/ 1000; sc -= 1000*ss; |
|
|
|
|
|
|
|
eh = ec/3600000; ec -= 3600000*eh; |
|
|
|
|
|
|
|
em = ec/ 60000; ec -= 60000*em; |
|
|
|
|
|
|
|
es = ec/ 1000; ec -= 1000*es; |
|
|
|
|
|
|
|
srt_print(s,"%d\r\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n", |
|
|
|
|
|
|
|
++s->count, sh, sm, ss, sc, eh, em, es, ec); |
|
|
|
|
|
|
|
s->timestamp_end = s->buffer.len - 2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
s->alignment_applied = 0; |
|
|
|
s->alignment_applied = 0; |
|
|
|
srt_style_apply(s, dialog->style); |
|
|
|
srt_style_apply(s, dialog->style); |
|
|
|
ff_ass_split_override_codes(&srt_callbacks, s, dialog->text); |
|
|
|
ff_ass_split_override_codes(&srt_callbacks, s, dialog->text); |
|
|
@ -308,9 +271,9 @@ static int srt_encode_close(AVCodecContext *avctx) |
|
|
|
/* deprecated encoder */ |
|
|
|
/* deprecated encoder */ |
|
|
|
AVCodec ff_srt_encoder = { |
|
|
|
AVCodec ff_srt_encoder = { |
|
|
|
.name = "srt", |
|
|
|
.name = "srt", |
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle with embedded timing"), |
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle"), |
|
|
|
.type = AVMEDIA_TYPE_SUBTITLE, |
|
|
|
.type = AVMEDIA_TYPE_SUBTITLE, |
|
|
|
.id = AV_CODEC_ID_SRT, |
|
|
|
.id = AV_CODEC_ID_SUBRIP, |
|
|
|
.priv_data_size = sizeof(SRTContext), |
|
|
|
.priv_data_size = sizeof(SRTContext), |
|
|
|
.init = srt_encode_init, |
|
|
|
.init = srt_encode_init, |
|
|
|
.encode_sub = srt_encode_frame, |
|
|
|
.encode_sub = srt_encode_frame, |
|
|
|