1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

lavc: deprecate decoded ass subtitles with timings

This commit is contained in:
Clément Bœsch 2016-02-21 12:58:36 +01:00
parent fa2df3a401
commit 22ebbda637
8 changed files with 35 additions and 3 deletions

View File

@ -60,6 +60,7 @@ static int ass_encode_frame(AVCodecContext *avctx,
return -1;
}
#if FF_API_ASS_TIMING
if (!strncmp(ass, "Dialogue: ", 10)) {
if (i > 0) {
av_log(avctx, AV_LOG_ERROR, "ASS encoder supports only one "
@ -86,6 +87,7 @@ static int ass_encode_frame(AVCodecContext *avctx,
ass_line[strcspn(ass_line, "\r\n")] = 0;
ass = ass_line;
}
#endif
len = av_strlcpy(buf+total_len, ass, bufsize-total_len);

View File

@ -3291,7 +3291,9 @@ typedef struct AVCodecContext {
int sub_text_format;
#define FF_SUB_TEXT_FMT_ASS 0
#if FF_API_ASS_TIMING
#define FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS 1
#endif
/**
* Skip processing alpha if supported by codec.

View File

@ -324,7 +324,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,
{
MovTextContext *s = avctx->priv_data;
ASSDialog *dialog;
int i, num, length;
int i, length;
size_t j;
s->text_pos = 0;
@ -339,19 +339,24 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,
return AVERROR(ENOSYS);
}
#if FF_API_ASS_TIMING
if (!strncmp(ass, "Dialogue: ", 10)) {
int num;
dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num);
// TODO reindent
for (; dialog && num--; dialog++) {
ff_ass_split_override_codes(&mov_text_callbacks, s, dialog->text);
}
} else {
#endif
dialog = ff_ass_split_dialog2(s->ass_ctx, ass);
if (!dialog)
return AVERROR(ENOMEM);
ff_ass_split_override_codes(&mov_text_callbacks, s, dialog->text);
ff_ass_free_dialog(&dialog);
#if FF_API_ASS_TIMING
}
#endif
for (j = 0; j < box_count; j++) {
box_types[j].encode(s, box_types[j].type);

View File

@ -520,9 +520,15 @@ static const AVOption avcodec_options[] = {
{"do_nothing", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_CHARENC_MODE_DO_NOTHING}, INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
{"auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_CHARENC_MODE_AUTOMATIC}, INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
{"pre_decoder", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_CHARENC_MODE_PRE_DECODER}, INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
#if FF_API_ASS_TIMING
{"sub_text_format", "set decoded text subtitle format", OFFSET(sub_text_format), AV_OPT_TYPE_INT, {.i64 = FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS}, 0, 1, S|D, "sub_text_format"},
#else
{"sub_text_format", "set decoded text subtitle format", OFFSET(sub_text_format), AV_OPT_TYPE_INT, {.i64 = FF_SUB_TEXT_FMT_ASS}, 0, 1, S|D, "sub_text_format"},
#endif
{"ass", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_TEXT_FMT_ASS}, INT_MIN, INT_MAX, S|D, "sub_text_format"},
#if FF_API_ASS_TIMING
{"ass_with_timings", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS}, INT_MIN, INT_MAX, S|D, "sub_text_format"},
#endif
{"refcounted_frames", NULL, OFFSET(refcounted_frames), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A|V|D },
#if FF_API_SIDEDATA_ONLY_PKT
{"side_data_only_packets", NULL, OFFSET(side_data_only_packets), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, A|V|E },

View File

@ -232,7 +232,7 @@ static int encode_frame(AVCodecContext *avctx,
{
SRTContext *s = avctx->priv_data;
ASSDialog *dialog;
int i, num;
int i;
av_bprint_clear(&s->buffer);
@ -244,7 +244,9 @@ static int encode_frame(AVCodecContext *avctx,
return AVERROR(ENOSYS);
}
#if FF_API_ASS_TIMING
if (!strncmp(ass, "Dialogue: ", 10)) {
int num;
dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num);
// TODO reindent
for (; dialog && num--; dialog++) {
@ -253,6 +255,7 @@ static int encode_frame(AVCodecContext *avctx,
ff_ass_split_override_codes(cb, s, dialog->text);
}
} else {
#endif
dialog = ff_ass_split_dialog2(s->ass_ctx, ass);
if (!dialog)
return AVERROR(ENOMEM);
@ -260,7 +263,9 @@ static int encode_frame(AVCodecContext *avctx,
srt_style_apply(s, dialog->style);
ff_ass_split_override_codes(cb, s, dialog->text);
ff_ass_free_dialog(&dialog);
#if FF_API_ASS_TIMING
}
#endif
}
if (!av_bprint_is_complete(&s->buffer))

View File

@ -2426,6 +2426,7 @@ static int utf8_check(const uint8_t *str)
return 1;
}
#if FF_API_ASS_TIMING
static void insert_ts(AVBPrint *buf, int ts)
{
if (ts == -1) {
@ -2495,6 +2496,7 @@ static int convert_sub_to_old_ass_form(AVSubtitle *sub, const AVPacket *pkt, AVR
av_bprint_finalize(&buf, NULL);
return 0;
}
#endif
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
int *got_sub_ptr,
@ -2546,9 +2548,11 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
av_assert1((ret >= 0) >= !!*got_sub_ptr &&
!!*got_sub_ptr >= !!sub->num_rects);
#if FF_API_ASS_TIMING
if (avctx->sub_text_format == FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS
&& *got_sub_ptr && sub->num_rects)
ret = convert_sub_to_old_ass_form(sub, avpkt, avctx->time_base);
#endif
if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
avctx->pkt_timebase.num) {

View File

@ -211,5 +211,8 @@
#ifndef FF_API_PRIVATE_OPT
#define FF_API_PRIVATE_OPT (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#ifndef FF_API_ASS_TIMING
#define FF_API_ASS_TIMING (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#endif /* AVCODEC_VERSION_H */

View File

@ -159,7 +159,7 @@ static int webvtt_encode_frame(AVCodecContext *avctx,
{
WebVTTContext *s = avctx->priv_data;
ASSDialog *dialog;
int i, num;
int i;
av_bprint_clear(&s->buffer);
@ -171,7 +171,9 @@ static int webvtt_encode_frame(AVCodecContext *avctx,
return AVERROR(ENOSYS);
}
#if FF_API_ASS_TIMING
if (!strncmp(ass, "Dialogue: ", 10)) {
int num;
dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num);
// TODO reindent
for (; dialog && num--; dialog++) {
@ -179,13 +181,16 @@ static int webvtt_encode_frame(AVCodecContext *avctx,
ff_ass_split_override_codes(&webvtt_callbacks, s, dialog->text);
}
} else {
#endif
dialog = ff_ass_split_dialog2(s->ass_ctx, ass);
if (!dialog)
return AVERROR(ENOMEM);
webvtt_style_apply(s, dialog->style);
ff_ass_split_override_codes(&webvtt_callbacks, s, dialog->text);
ff_ass_free_dialog(&dialog);
#if FF_API_ASS_TIMING
}
#endif
}
if (!av_bprint_is_complete(&s->buffer))