From patchwork Thu Jan 20 02:48:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 33675 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5408744iog; Wed, 19 Jan 2022 18:49:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFQ8d2f57LErJbpdBzLzq0bsffZtaPRWkC6h9XsEnWVLRL3kmrbflDjweP/BkqDvgkPXJb X-Received: by 2002:a17:906:a21a:: with SMTP id r26mr14926071ejy.174.1642646978760; Wed, 19 Jan 2022 18:49:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642646978; cv=none; d=google.com; s=arc-20160816; b=wFOxrXTvOZ+1MWaFix0RnpQqESDkRCDaTSIRypCRfdf5UYdFeuXF7qCtSzWHrbsTu5 kNhlKrV5wQ4cnxK7LBeJqYxWojXJHW0yTL+X5wIc8amgEI5gT2ueGVkVuHqWIe8MvHxq 5TfF/evFXv4GygG8JI3VpJZvZJMVXZeHywyBy9N7a41sI6Zs3MPkWTjwNpzib/LJIogu S+oSQTyvBPppgQeg0LMG20rNarWGooue7EROoxGvYPTd1qM6NHALoaLeV9sLTUZnq6WA 8iijufFln6enHCtejD4qyWmM+rqPl+HsoD0wNR5nle6EOFz1wmepNO9JycaAgjK0/d+8 fxzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:from:references :in-reply-to:message-id:dkim-signature:delivered-to; bh=Gz/Qn0ewDhpg00ofGNme9RfvJONnDA1Xg0V9usnPau0=; b=A2nofFQuPDTBAEo5kP7xqVcF+ndFbT1+qM6wEcSB1I75WaDdwTQZAM5dna39x4R9YR RXZ/yl9S3PCWMyMkYsP4ekMJwEsg0RhEuzuFsnnZmsNn8qpAGJZCLnmb+Dmzt5kbqqWR pWNdeElzhBvLUfNmnd4PerrljN0McqPe01UsiFw4bYKjLC05X/0Ev4oFJRmw7CljLcrA kZ2A17GX4udQHsTVQzkD3pskWxEFhHAG/eKsM3X91YoWiZpXsrskBxOs/QWTqnyYDiyc WFMs3c+tGWpST5MCG5kJxPvbAJljJWgs7a0L0iuoGfPyn6gdADgwb48ESdfSXA7EImBP D8Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=pTrCGhCB; 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 x4si1080250edl.501.2022.01.19.18.49.38; Wed, 19 Jan 2022 18:49:38 -0800 (PST) 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=20210112 header.b=pTrCGhCB; 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 1E9CF68B1FF; Thu, 20 Jan 2022 04:48:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 65CD168B1D8 for ; Thu, 20 Jan 2022 04:48:44 +0200 (EET) Received: by mail-pj1-f50.google.com with SMTP id v11-20020a17090a520b00b001b512482f36so1654021pjh.3 for ; Wed, 19 Jan 2022 18:48:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=5bf17VR0/ZJjwZK6zV/qDNkrzv1wJQUHu4/lfHYjj/M=; b=pTrCGhCBl2qbZ5o53eCnLV/4mACa4OzIbSv6LqwM+JXnC4WBExbQJypKOPTGfEddsv v2/diCo/9UbatQkvYHVMCgw0Mpmr4jhQmIIwkwlfkQLoe/7L6JOPeVfJiw6HzBneKCwM CYJlyX9Pp9J7sZ82l9/i3wcrUYG9OqKfJ+EOZ5OZVJMQImffNCEJIiKX5RNYHWcfvXJ5 3/BNvdgELvxfvUFkVdHD9xNh8xNkqvT+yDjxml7Oh8dKejIdbetbaiUhQU/Y30SO9Dkn LmQEjEXhW8xDMSvAY6raEPfcRJogW5Nd4wtFGfkJoFr4UhPSdZualcKYT9fQdwIOGEeA 7OLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=5bf17VR0/ZJjwZK6zV/qDNkrzv1wJQUHu4/lfHYjj/M=; b=D7mdZ5AHmsDN4uO5TCLligesA+zQD7hJtqwIaUgQzoNHQXUo1HEJet+vTNmQls+zHZ VfxusSQnlU3c7GYm7t72VZQWCowy+dVc/p/cbTUfO5KPnQDSVWu30ELBzxMlOxGfbo5h j9kc20Zw4RLGsiZRgbSj0cruVJhmc6YnZ8X1vO5eptsmRYV+IXmfmEsyfdpyI2HCfafq 4fLYS5j8ihYHMtj8AkEMf5bwBcVm+0J31KYAG+wysvT83Y4EAo9azMlSHeOZO7OtiR40 KSOF6JWExqSPMSAOerWyLo/9u0pfM/h0jy9ofocesLrUM6byjZ0tJferT4fVTLeBSW4+ 4/AA== X-Gm-Message-State: AOAM530j0klkCibYcDOeiek4PwhSNR57vBTxP1ne5Qe481ubc9vo+c5m nhtLiMTrjO5uBettE11G0xIFf2ONRuA= X-Received: by 2002:a17:903:32c2:b0:14a:2099:eb38 with SMTP id i2-20020a17090332c200b0014a2099eb38mr36178393plr.58.1642646922730; Wed, 19 Jan 2022 18:48:42 -0800 (PST) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id f13sm912668pfn.141.2022.01.19.18.48.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jan 2022 18:48:42 -0800 (PST) Message-Id: In-Reply-To: References: From: ffmpegagent Date: Thu, 20 Jan 2022 02:48:14 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 04/26] avfilter/subtitles: Update vf_subtitles to use new decoding api 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 Cc: Michael Niedermayer , softworkz , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: gfVcIVcx/MB9 From: softworkz Signed-off-by: softworkz --- libavfilter/vf_subtitles.c | 56 +++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c index 3fc4eeb63d..25e217e845 100644 --- a/libavfilter/vf_subtitles.c +++ b/libavfilter/vf_subtitles.c @@ -35,14 +35,12 @@ # include "libavformat/avformat.h" #endif #include "libavutil/avstring.h" -#include "libavutil/imgutils.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "drawutils.h" #include "avfilter.h" #include "internal.h" #include "formats.h" -#include "video.h" typedef struct AssContext { const AVClass *class; @@ -292,6 +290,29 @@ static int attachment_is_font(AVStream * st) return 0; } +static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt) +{ + int ret; + + *got_frame = 0; + + if (pkt) { + ret = avcodec_send_packet(avctx, pkt); + // In particular, we don't expect AVERROR(EAGAIN), because we read all + // decoded frames with avcodec_receive_frame() until done. + if (ret < 0 && ret != AVERROR_EOF) + return ret; + } + + ret = avcodec_receive_frame(avctx, frame); + if (ret < 0 && ret != AVERROR(EAGAIN)) + return ret; + if (ret >= 0) + *got_frame = 1; + + return 0; +} + AVFILTER_DEFINE_CLASS(subtitles); static av_cold int init_subtitles(AVFilterContext *ctx) @@ -306,6 +327,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx) AVStream *st; AVPacket pkt; AssContext *ass = ctx->priv; + enum AVSubtitleType subtitle_format; /* Init libass */ ret = init(ctx); @@ -386,13 +408,17 @@ static av_cold int init_subtitles(AVFilterContext *ctx) ret = AVERROR_DECODER_NOT_FOUND; goto end; } + dec_desc = avcodec_descriptor_get(st->codecpar->codec_id); - if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) { + subtitle_format = avcodec_descriptor_get_subtitle_format(dec_desc); + + if (subtitle_format != AV_SUBTITLE_FMT_ASS) { av_log(ctx, AV_LOG_ERROR, - "Only text based subtitles are currently supported\n"); - ret = AVERROR_PATCHWELCOME; + "Only text based subtitles are supported by this filter\n"); + ret = AVERROR_INVALIDDATA; goto end; } + if (ass->charenc) av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0); @@ -448,27 +474,31 @@ static av_cold int init_subtitles(AVFilterContext *ctx) dec_ctx->subtitle_header_size); while (av_read_frame(fmt, &pkt) >= 0) { int i, got_subtitle; - AVSubtitle sub = {0}; + AVFrame *sub = av_frame_alloc(); + if (!sub) { + ret = AVERROR(ENOMEM); + goto end; + } if (pkt.stream_index == sid) { - ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_subtitle, &pkt); + ret = decode(dec_ctx, sub, &got_subtitle, &pkt); if (ret < 0) { av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n", av_err2str(ret)); } else if (got_subtitle) { - const int64_t start_time = av_rescale_q(sub.pts, AV_TIME_BASE_Q, av_make_q(1, 1000)); - const int64_t duration = sub.end_display_time; - for (i = 0; i < sub.num_rects; i++) { - char *ass_line = sub.rects[i]->ass; + const int64_t start_time = av_rescale_q(sub->subtitle_timing.start_pts, AV_TIME_BASE_Q, av_make_q(1, 1000)); + const int64_t duration = av_rescale_q(sub->subtitle_timing.duration, AV_TIME_BASE_Q, av_make_q(1, 1000)); + for (i = 0; i < sub->num_subtitle_areas; i++) { + char *ass_line = sub->subtitle_areas[i]->ass; if (!ass_line) - break; + continue; ass_process_chunk(ass->track, ass_line, strlen(ass_line), start_time, duration); } } } av_packet_unref(&pkt); - avsubtitle_free(&sub); + av_frame_free(&sub); } end: