Commit 22ebbda6 authored by Clément Bœsch's avatar Clément Bœsch

lavc: deprecate decoded ass subtitles with timings

parent fa2df3a4
...@@ -60,6 +60,7 @@ static int ass_encode_frame(AVCodecContext *avctx, ...@@ -60,6 +60,7 @@ static int ass_encode_frame(AVCodecContext *avctx,
return -1; return -1;
} }
#if FF_API_ASS_TIMING
if (!strncmp(ass, "Dialogue: ", 10)) { if (!strncmp(ass, "Dialogue: ", 10)) {
if (i > 0) { if (i > 0) {
av_log(avctx, AV_LOG_ERROR, "ASS encoder supports only one " av_log(avctx, AV_LOG_ERROR, "ASS encoder supports only one "
...@@ -86,6 +87,7 @@ static int ass_encode_frame(AVCodecContext *avctx, ...@@ -86,6 +87,7 @@ static int ass_encode_frame(AVCodecContext *avctx,
ass_line[strcspn(ass_line, "\r\n")] = 0; ass_line[strcspn(ass_line, "\r\n")] = 0;
ass = ass_line; ass = ass_line;
} }
#endif
len = av_strlcpy(buf+total_len, ass, bufsize-total_len); len = av_strlcpy(buf+total_len, ass, bufsize-total_len);
......
...@@ -3291,7 +3291,9 @@ typedef struct AVCodecContext { ...@@ -3291,7 +3291,9 @@ typedef struct AVCodecContext {
int sub_text_format; int sub_text_format;
#define FF_SUB_TEXT_FMT_ASS 0 #define FF_SUB_TEXT_FMT_ASS 0
#if FF_API_ASS_TIMING
#define FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS 1 #define FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS 1
#endif
/** /**
* Skip processing alpha if supported by codec. * Skip processing alpha if supported by codec.
......
...@@ -324,7 +324,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, ...@@ -324,7 +324,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,
{ {
MovTextContext *s = avctx->priv_data; MovTextContext *s = avctx->priv_data;
ASSDialog *dialog; ASSDialog *dialog;
int i, num, length; int i, length;
size_t j; size_t j;
s->text_pos = 0; s->text_pos = 0;
...@@ -339,19 +339,24 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, ...@@ -339,19 +339,24 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
} }
#if FF_API_ASS_TIMING
if (!strncmp(ass, "Dialogue: ", 10)) { if (!strncmp(ass, "Dialogue: ", 10)) {
int num;
dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num); dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num);
// TODO reindent // TODO reindent
for (; dialog && num--; dialog++) { for (; dialog && num--; dialog++) {
ff_ass_split_override_codes(&mov_text_callbacks, s, dialog->text); ff_ass_split_override_codes(&mov_text_callbacks, s, dialog->text);
} }
} else { } else {
#endif
dialog = ff_ass_split_dialog2(s->ass_ctx, ass); dialog = ff_ass_split_dialog2(s->ass_ctx, ass);
if (!dialog) if (!dialog)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
ff_ass_split_override_codes(&mov_text_callbacks, s, dialog->text); ff_ass_split_override_codes(&mov_text_callbacks, s, dialog->text);
ff_ass_free_dialog(&dialog); ff_ass_free_dialog(&dialog);
#if FF_API_ASS_TIMING
} }
#endif
for (j = 0; j < box_count; j++) { for (j = 0; j < box_count; j++) {
box_types[j].encode(s, box_types[j].type); box_types[j].encode(s, box_types[j].type);
......
...@@ -520,9 +520,15 @@ static const AVOption avcodec_options[] = { ...@@ -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"}, {"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"}, {"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"}, {"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"}, {"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"}, {"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"}, {"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 }, {"refcounted_frames", NULL, OFFSET(refcounted_frames), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A|V|D },
#if FF_API_SIDEDATA_ONLY_PKT #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 }, {"side_data_only_packets", NULL, OFFSET(side_data_only_packets), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, A|V|E },
......
...@@ -232,7 +232,7 @@ static int encode_frame(AVCodecContext *avctx, ...@@ -232,7 +232,7 @@ static int encode_frame(AVCodecContext *avctx,
{ {
SRTContext *s = avctx->priv_data; SRTContext *s = avctx->priv_data;
ASSDialog *dialog; ASSDialog *dialog;
int i, num; int i;
av_bprint_clear(&s->buffer); av_bprint_clear(&s->buffer);
...@@ -244,7 +244,9 @@ static int encode_frame(AVCodecContext *avctx, ...@@ -244,7 +244,9 @@ static int encode_frame(AVCodecContext *avctx,
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
} }
#if FF_API_ASS_TIMING
if (!strncmp(ass, "Dialogue: ", 10)) { if (!strncmp(ass, "Dialogue: ", 10)) {
int num;
dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num); dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num);
// TODO reindent // TODO reindent
for (; dialog && num--; dialog++) { for (; dialog && num--; dialog++) {
...@@ -253,6 +255,7 @@ static int encode_frame(AVCodecContext *avctx, ...@@ -253,6 +255,7 @@ static int encode_frame(AVCodecContext *avctx,
ff_ass_split_override_codes(cb, s, dialog->text); ff_ass_split_override_codes(cb, s, dialog->text);
} }
} else { } else {
#endif
dialog = ff_ass_split_dialog2(s->ass_ctx, ass); dialog = ff_ass_split_dialog2(s->ass_ctx, ass);
if (!dialog) if (!dialog)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
...@@ -260,7 +263,9 @@ static int encode_frame(AVCodecContext *avctx, ...@@ -260,7 +263,9 @@ static int encode_frame(AVCodecContext *avctx,
srt_style_apply(s, dialog->style); srt_style_apply(s, dialog->style);
ff_ass_split_override_codes(cb, s, dialog->text); ff_ass_split_override_codes(cb, s, dialog->text);
ff_ass_free_dialog(&dialog); ff_ass_free_dialog(&dialog);
#if FF_API_ASS_TIMING
} }
#endif
} }
if (!av_bprint_is_complete(&s->buffer)) if (!av_bprint_is_complete(&s->buffer))
......
...@@ -2426,6 +2426,7 @@ static int utf8_check(const uint8_t *str) ...@@ -2426,6 +2426,7 @@ static int utf8_check(const uint8_t *str)
return 1; return 1;
} }
#if FF_API_ASS_TIMING
static void insert_ts(AVBPrint *buf, int ts) static void insert_ts(AVBPrint *buf, int ts)
{ {
if (ts == -1) { if (ts == -1) {
...@@ -2495,6 +2496,7 @@ static int convert_sub_to_old_ass_form(AVSubtitle *sub, const AVPacket *pkt, AVR ...@@ -2495,6 +2496,7 @@ static int convert_sub_to_old_ass_form(AVSubtitle *sub, const AVPacket *pkt, AVR
av_bprint_finalize(&buf, NULL); av_bprint_finalize(&buf, NULL);
return 0; return 0;
} }
#endif
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
int *got_sub_ptr, int *got_sub_ptr,
...@@ -2546,9 +2548,11 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, ...@@ -2546,9 +2548,11 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
av_assert1((ret >= 0) >= !!*got_sub_ptr && av_assert1((ret >= 0) >= !!*got_sub_ptr &&
!!*got_sub_ptr >= !!sub->num_rects); !!*got_sub_ptr >= !!sub->num_rects);
#if FF_API_ASS_TIMING
if (avctx->sub_text_format == FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS if (avctx->sub_text_format == FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS
&& *got_sub_ptr && sub->num_rects) && *got_sub_ptr && sub->num_rects)
ret = convert_sub_to_old_ass_form(sub, avpkt, avctx->time_base); ret = convert_sub_to_old_ass_form(sub, avpkt, avctx->time_base);
#endif
if (sub->num_rects && !sub->end_display_time && avpkt->duration && if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
avctx->pkt_timebase.num) { avctx->pkt_timebase.num) {
......
...@@ -211,5 +211,8 @@ ...@@ -211,5 +211,8 @@
#ifndef FF_API_PRIVATE_OPT #ifndef FF_API_PRIVATE_OPT
#define FF_API_PRIVATE_OPT (LIBAVCODEC_VERSION_MAJOR < 59) #define FF_API_PRIVATE_OPT (LIBAVCODEC_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_ASS_TIMING
#define FF_API_ASS_TIMING (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#endif /* AVCODEC_VERSION_H */ #endif /* AVCODEC_VERSION_H */
...@@ -159,7 +159,7 @@ static int webvtt_encode_frame(AVCodecContext *avctx, ...@@ -159,7 +159,7 @@ static int webvtt_encode_frame(AVCodecContext *avctx,
{ {
WebVTTContext *s = avctx->priv_data; WebVTTContext *s = avctx->priv_data;
ASSDialog *dialog; ASSDialog *dialog;
int i, num; int i;
av_bprint_clear(&s->buffer); av_bprint_clear(&s->buffer);
...@@ -171,7 +171,9 @@ static int webvtt_encode_frame(AVCodecContext *avctx, ...@@ -171,7 +171,9 @@ static int webvtt_encode_frame(AVCodecContext *avctx,
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
} }
#if FF_API_ASS_TIMING
if (!strncmp(ass, "Dialogue: ", 10)) { if (!strncmp(ass, "Dialogue: ", 10)) {
int num;
dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num); dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num);
// TODO reindent // TODO reindent
for (; dialog && num--; dialog++) { for (; dialog && num--; dialog++) {
...@@ -179,13 +181,16 @@ static int webvtt_encode_frame(AVCodecContext *avctx, ...@@ -179,13 +181,16 @@ static int webvtt_encode_frame(AVCodecContext *avctx,
ff_ass_split_override_codes(&webvtt_callbacks, s, dialog->text); ff_ass_split_override_codes(&webvtt_callbacks, s, dialog->text);
} }
} else { } else {
#endif
dialog = ff_ass_split_dialog2(s->ass_ctx, ass); dialog = ff_ass_split_dialog2(s->ass_ctx, ass);
if (!dialog) if (!dialog)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
webvtt_style_apply(s, dialog->style); webvtt_style_apply(s, dialog->style);
ff_ass_split_override_codes(&webvtt_callbacks, s, dialog->text); ff_ass_split_override_codes(&webvtt_callbacks, s, dialog->text);
ff_ass_free_dialog(&dialog); ff_ass_free_dialog(&dialog);
#if FF_API_ASS_TIMING
} }
#endif
} }
if (!av_bprint_is_complete(&s->buffer)) if (!av_bprint_is_complete(&s->buffer))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment