From patchwork Mon Apr 19 14:09:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 27022 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp556470iob; Mon, 19 Apr 2021 07:12:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxomZNHkwXplui0iN1boLRRiFChwEkbGghdXSN2736NFMDxU3U7jlMKTpxGImf4W/SAtbCx X-Received: by 2002:a17:906:af5a:: with SMTP id ly26mr21807989ejb.372.1618841560093; Mon, 19 Apr 2021 07:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618841560; cv=none; d=google.com; s=arc-20160816; b=eulvs6CBz3FGL396VLJm2DYoSGafom/cM8Q5XPttdNTI+EP4FtXifd0Bqjl8C2EMnm TEIgmIETgBX0S0x+74zqzlgYDmAmSQlLFSQIrL1aHW0LTFGHBYXZGq+hoEMOuCCHUp8+ Qbs2eIVxHlmRlnGnbuZSmbV/hBpD+3QZET+fDViaCSOHj6xIgLYXh4mWv+NHj3DNvmV4 DwdYSd/XaHAj4oYv4qd2G8TKRdGTscKFD0wAAHU5PCpXMAKWvxzjiV6y5CaKYTQEk3xv ZQ0g0yV+lpQU/zcxtfhef0ZGV9eqyCaZlkeHliL0aipgyWBm3AWQ76BUE2WwYYu8/DFj BQAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=4s2HxEt/Rd7pZcd1Eicgi5XvwUKjawWKJXCMJ3LPmMw=; b=hrzsdIxcRXpzhCBHJY4gfbvhgDzQMuE+WnZ7oDtU+r3sSVcfuFPxBV/un1H3vlCc1x pdQI/mrvLPlHD92jKA6tgx9RJHNvkeWFtQOORVrYhWAkUwTvxH1GL2XYldY2e9x97TuH Hxgj4B8i7khV0JokKD8ZuKQnaupB9Lmo58YmtrCixaQPHMQC5SpW88ELH0XVcArNUJl/ 3pI6ouiN53ND0KW84lnwOaBYxdeZBEN3tY8Z274n8MFLrmoAr2d5KZrxRJ337x7lIVCC N9JZcVCBUI6lVzgtuKV4OdE6HmXrRRiWEHkp47F2Vpm3Dko2XAL6aQUmD9hVETwKeqz9 p7kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=sq+tVH7U; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w2si14021736edi.199.2021.04.19.07.12.39; Mon, 19 Apr 2021 07:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=sq+tVH7U; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E6610680A25; Mon, 19 Apr 2021 17:11:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E93416809C9 for ; Mon, 19 Apr 2021 17:11:27 +0300 (EEST) Received: by mail-qk1-f170.google.com with SMTP id e13so26001152qkl.6 for ; Mon, 19 Apr 2021 07:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zez1wkLNX9pnYMscrjNyptBi67kEQ2/+NwFCsWVPgLc=; b=sq+tVH7UhI6oNqgqmzsMFqchbs060+tHsyeLEhLN9f6bubvYn813WJBsSLfkqhuthS WXBqdyF2lDIhMDx/ZWI+D5DFRhQEr5bLbnAL69N2ZueZOV+j48nC1HIiQfNOgJE5YNfE oQ/hj4/BmNqW9GNouo3s2RY/TMshRHC27iVkaqP1x4t/dxMt9yYBCWznVLDrhIL5kzsv 38AFXMpC/ER+Gsd8O0T3dCn4JcH2DIy2WyFd/lE2rrsijYAWEW3VzUqO8ukuyltNYoru Tg34LQLiFfmCVv095kVM5kwKHEAHeVbmahd2/IYrErL6rWq9mTtMUajfe8uCGP0Cq2Mg QopQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zez1wkLNX9pnYMscrjNyptBi67kEQ2/+NwFCsWVPgLc=; b=T3OyOFR1BFuOQrOf0i38kz0e/TRc1mkas3hLA9KfS+FkbVKWe3VXsBbN+AjMiswK5F eIy2z3lXM1p75t1Ozos3OOSZIaI3KapdXm/m2smLcilAGO5G5JabSy1mtA1BNgRZARJh NNtlQTcTrfOja8h4kWs8WljuG/IXM4mXmwTvuALNbSGYxcCRUuehrMl4ztsdWgIYqlnK TgNbXFsHjhaM5qnb3oNKS7qsFePjaRzNiAJW9RAhH0Ghkh357VM7btfyTRclGJ+E3aB7 xX137/ktS7NVMe54OQaYKky3Ab9XydNYQcQUyFEI6WQoVd32B61HlDoY7SwjWSW6Byed H8Ag== X-Gm-Message-State: AOAM531dQUFj/JVnxX9xBBXKOAHLPHBnFyez/v5aQ/23C5TV/Q0Wjwlb TDQ29K6wX1CYlkB0RgCPlkaMh4cgr2k= X-Received: by 2002:a05:620a:1522:: with SMTP id n2mr6458194qkk.298.1618841486102; Mon, 19 Apr 2021 07:11:26 -0700 (PDT) Received: from localhost.localdomain ([191.83.209.133]) by smtp.gmail.com with ESMTPSA id f7sm2049494qtv.53.2021.04.19.07.11.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 07:11:25 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Apr 2021 11:09:17 -0300 Message-Id: <20210419141024.8174-21-jamrial@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419141024.8174-1-jamrial@gmail.com> References: <20210419141024.8174-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/87] avcodec: Remove deprecated ASS with inline timing X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cpfKYE5/WJvl From: Andreas Rheinhardt Deprecated in 22ebbda637257a432c99330ca4c6024665418f0e. Signed-off-by: Andreas Rheinhardt --- libavcodec/assenc.c | 39 ------------------ libavcodec/avcodec.h | 3 -- libavcodec/decode.c | 84 -------------------------------------- libavcodec/movtextenc.c | 13 ------ libavcodec/options_table.h | 7 ---- libavcodec/srtenc.c | 15 ------- libavcodec/ttmlenc.c | 26 ------------ libavcodec/version.h | 3 -- libavcodec/webvttenc.c | 14 ------- 9 files changed, 204 deletions(-) diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c index a6e1d5d8b9..3decf670d7 100644 --- a/libavcodec/assenc.c +++ b/libavcodec/assenc.c @@ -27,10 +27,6 @@ #include "libavutil/internal.h" #include "libavutil/mem.h" -typedef struct { - int id; ///< current event id, ReadOrder field -} ASSEncodeContext; - static av_cold int ass_encode_init(AVCodecContext *avctx) { avctx->extradata = av_malloc(avctx->subtitle_header_size + 1); @@ -46,49 +42,16 @@ static int ass_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub) { - ASSEncodeContext *s = avctx->priv_data; int i, len, total_len = 0; for (i=0; inum_rects; i++) { - char ass_line[2048]; const char *ass = sub->rects[i]->ass; - long int layer; - char *p; if (sub->rects[i]->type != SUBTITLE_ASS) { av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n"); return AVERROR(EINVAL); } -#if FF_API_ASS_TIMING - if (!strncmp(ass, "Dialogue: ", 10)) { - if (i > 0) { - av_log(avctx, AV_LOG_ERROR, "ASS encoder supports only one " - "ASS rectangle field.\n"); - return AVERROR_INVALIDDATA; - } - - ass += 10; // skip "Dialogue: " - /* parse Layer field. If it's a Marked field, the content - * will be "Marked=N" instead of the layer num, so we will - * have layer=0, which is fine. */ - layer = strtol(ass, &p, 10); - -#define SKIP_ENTRY(ptr) do { \ - char *sep = strchr(ptr, ','); \ - if (sep) \ - ptr = sep + 1; \ -} while (0) - - SKIP_ENTRY(p); // skip layer or marked - SKIP_ENTRY(p); // skip start timestamp - SKIP_ENTRY(p); // skip end timestamp - snprintf(ass_line, sizeof(ass_line), "%d,%ld,%s", ++s->id, layer, p); - ass_line[strcspn(ass_line, "\r\n")] = 0; - ass = ass_line; - } -#endif - len = av_strlcpy(buf+total_len, ass, bufsize-total_len); if (len > bufsize-total_len-1) { @@ -110,7 +73,6 @@ AVCodec ff_ssa_encoder = { .id = AV_CODEC_ID_ASS, .init = ass_encode_init, .encode_sub = ass_encode_frame, - .priv_data_size = sizeof(ASSEncodeContext), }; #endif @@ -122,6 +84,5 @@ AVCodec ff_ass_encoder = { .id = AV_CODEC_ID_ASS, .init = ass_encode_init, .encode_sub = ass_encode_frame, - .priv_data_size = sizeof(ASSEncodeContext), }; #endif diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 064af12f31..a3c8c425cb 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2047,9 +2047,6 @@ 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 /** * Audio only. The amount of padding (in samples) appended by the encoder to diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 0956a6ac6f..0078f00607 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -949,79 +949,6 @@ 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) { - av_bprintf(buf, "9:59:59.99,"); - } else { - int h, m, s; - - 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); - } -} - -static int convert_sub_to_old_ass_form(AVSubtitle *sub, const AVPacket *pkt, AVRational tb) -{ - int i; - AVBPrint buf; - - av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); - - for (i = 0; i < sub->num_rects; i++) { - char *final_dialog; - const char *dialog; - AVSubtitleRect *rect = sub->rects[i]; - int ts_start, ts_duration = -1; - long int layer; - - if (rect->type != SUBTITLE_ASS || !strncmp(rect->ass, "Dialogue: ", 10)) - continue; - - av_bprint_clear(&buf); - - /* skip ReadOrder */ - dialog = strchr(rect->ass, ','); - if (!dialog) - continue; - dialog++; - - /* extract Layer or Marked */ - layer = strtol(dialog, (char**)&dialog, 10); - if (*dialog != ',') - continue; - dialog++; - - /* rescale timing to ASS time base (ms) */ - ts_start = av_rescale_q(pkt->pts, tb, av_make_q(1, 100)); - if (pkt->duration != -1) - ts_duration = av_rescale_q(pkt->duration, tb, av_make_q(1, 100)); - sub->end_display_time = FFMAX(sub->end_display_time, 10 * ts_duration); - - /* construct ASS (standalone file form with timestamps) string */ - av_bprintf(&buf, "Dialogue: %ld,", layer); - insert_ts(&buf, ts_start); - insert_ts(&buf, ts_duration == -1 ? -1 : ts_start + ts_duration); - av_bprintf(&buf, "%s\r\n", dialog); - - final_dialog = av_strdup(buf.str); - if (!av_bprint_is_complete(&buf) || !final_dialog) { - av_freep(&final_dialog); - av_bprint_finalize(&buf, NULL); - return AVERROR(ENOMEM); - } - av_freep(&rect->ass); - rect->ass = final_dialog; - } - - av_bprint_finalize(&buf, NULL); - return 0; -} -#endif - int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt) @@ -1057,17 +984,6 @@ 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) { - const AVRational tb = avctx->pkt_timebase.num ? avctx->pkt_timebase - : avctx->time_base; - int err = convert_sub_to_old_ass_form(sub, avpkt, tb); - if (err < 0) - ret = err; - } -#endif - if (sub->num_rects && !sub->end_display_time && avpkt->duration && avctx->pkt_timebase.num) { AVRational ms = { 1, 1000 }; diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index cf30adbd0a..1b37d135e1 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -655,25 +655,12 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, return AVERROR(EINVAL); } -#if FF_API_ASS_TIMING - if (!strncmp(ass, "Dialogue: ", 10)) { - int num; - dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num); - for (; dialog && num--; dialog++) { - mov_text_dialog(s, 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); mov_text_dialog(s, dialog); 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); diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index 313150eb73..6ad54c2d67 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -366,15 +366,8 @@ static const AVOption avcodec_options[] = { {"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"}, {"ignore", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_CHARENC_MODE_IGNORE}, 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 #if FF_API_OLD_ENCDEC {"refcounted_frames", NULL, OFFSET(refcounted_frames), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A|V|D }, #endif diff --git a/libavcodec/srtenc.c b/libavcodec/srtenc.c index 655b65679e..160f3bbf3a 100644 --- a/libavcodec/srtenc.c +++ b/libavcodec/srtenc.c @@ -244,18 +244,6 @@ static int encode_frame(AVCodecContext *avctx, return AVERROR(EINVAL); } -#if FF_API_ASS_TIMING - if (!strncmp(ass, "Dialogue: ", 10)) { - int num; - dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num); - for (; dialog && num--; dialog++) { - s->alignment_applied = 0; - if (avctx->codec_id == AV_CODEC_ID_SUBRIP) - srt_style_apply(s, dialog->style); - 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); @@ -264,9 +252,6 @@ 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)) diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c index 3972b4368c..c4964572f9 100644 --- a/libavcodec/ttmlenc.c +++ b/libavcodec/ttmlenc.c @@ -94,29 +94,6 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t *buf, return AVERROR(EINVAL); } -#if FF_API_ASS_TIMING - if (!strncmp(ass, "Dialogue: ", 10)) { - int num; - dialog = ff_ass_split_dialog(s->ass_ctx, ass, 0, &num); - - for (; dialog && num--; dialog++) { - int ret = ff_ass_split_override_codes(&ttml_callbacks, s, - dialog->text); - int log_level = (ret != AVERROR_INVALIDDATA || - avctx->err_recognition & AV_EF_EXPLODE) ? - AV_LOG_ERROR : AV_LOG_WARNING; - - if (ret < 0) { - av_log(avctx, log_level, - "Splitting received ASS dialog failed: %s\n", - av_err2str(ret)); - - if (log_level == AV_LOG_ERROR) - return ret; - } - } - } else { -#endif dialog = ff_ass_split_dialog2(s->ass_ctx, ass); if (!dialog) return AVERROR(ENOMEM); @@ -142,9 +119,6 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t *buf, ff_ass_free_dialog(&dialog); } -#if FF_API_ASS_TIMING - } -#endif } if (!av_bprint_is_complete(&s->buffer)) diff --git a/libavcodec/version.h b/libavcodec/version.h index 0e20d5c2e2..af737afce1 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -63,9 +63,6 @@ #ifndef FF_API_VBV_DELAY #define FF_API_VBV_DELAY (LIBAVCODEC_VERSION_MAJOR < 59) #endif -#ifndef FF_API_ASS_TIMING -#define FF_API_ASS_TIMING (LIBAVCODEC_VERSION_MAJOR < 59) -#endif #ifndef FF_API_COPY_CONTEXT #define FF_API_COPY_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 59) #endif diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c index febf6ee370..2419dd3d07 100644 --- a/libavcodec/webvttenc.c +++ b/libavcodec/webvttenc.c @@ -171,26 +171,12 @@ static int webvtt_encode_frame(AVCodecContext *avctx, return AVERROR(EINVAL); } -#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++) { - webvtt_style_apply(s, dialog->style); - 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))