From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id E89BF420E3 for ; Sat, 28 May 2022 13:26:36 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6E6A968B60F; Sat, 28 May 2022 16:25:41 +0300 (EEST) Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E46A368B5E5 for ; Sat, 28 May 2022 16:25:32 +0300 (EEST) Received: by mail-pf1-f177.google.com with SMTP id c14so6649580pfn.2 for ; Sat, 28 May 2022 06:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=OwAbOvynqRhMS61zCf3wNHPYflVi3DT6Sol+N98Ic8k=; b=GSh7OlKz+WHHdyVoSsgjr0z4vzMkgnHV+CeGf+ova26hw6oQAzrGc13NiGZhFFs5wl ltlcc1IkO5hC4nxkd84G5+JOhB6immY8Bq9CQeugsYtZ9uqmOMthhyNhiZ2D/OPYybt3 wpx+FOBy1te/CdsHTYSBDuZfnVgJj37amMCKNsKaGNhqo0kjJGRtxPAkMKdCZyjlWrie dOEYCZOlQoI0oUB/TnUBYBUhVrfQmu/yl6sWavEvQEbOsG+TQaZyiEUlcnsel0DCx3DH yG/zMD3GkhM0H4n5mYVpIq7y34To7fI5atPyXfQPRASefJtXmK2kwvrAE5WTy0e0BUlm IA8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=OwAbOvynqRhMS61zCf3wNHPYflVi3DT6Sol+N98Ic8k=; b=WqF4WMOh8QzO/Xq51kxhGjQwdZTmbva5NCWrf+0n/HPRbup9iO9d6EDFMDIY2gr4gO 6XYgi18mu2uIme5DAmRHVosZ8sK3FVIxcExjbROTt3B3I0V0Yr2eESq8Ic3pCG5PIIQ+ KVwq80pfcPGkkIF7jFNO7TRsmOPIWbQYxCukqUCHTTwQsIUi1mHkg+JzIGqfZR6OWb4h oAsKlkJ2D+9nKo4hkI4vOZYAdk7cHtQi/x+on7+mvrBqpo29uc7nQOefuMkpfvDEJjOU XrWSvjLdR34VpaScFNFv17K1K7Ziypa9mA9qimVJebVhK8NQtGsCSPa6TAjdiK5rsrnc EiiA== X-Gm-Message-State: AOAM533bK5g78ImFe3xg8jOtiJ4Wg87RrC2Vwa2MglmEprCLZ2g3D+0p wQ+SfcWS+H5iSNAoPOVfiDhdUIHSTW6fig== X-Google-Smtp-Source: ABdhPJzM4kNiI74ruKxUDsuY23NUc2RUV9W59e7qvB8vAsXjHgSPbJQSdmKdVE8kWrcH3pvTq7tOdQ== X-Received: by 2002:a63:4853:0:b0:3fa:dc6:7ac2 with SMTP id x19-20020a634853000000b003fa0dc67ac2mr29673671pgk.298.1653744331333; Sat, 28 May 2022 06:25:31 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id b14-20020aa7810e000000b005183c6a21c8sm5286565pfi.165.2022.05.28.06.25.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 May 2022 06:25:30 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <8faa7a404341796e9497adbd645e20358a06d785.1653744323.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Sat, 28 May 2022 13:25:05 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v4 05/23] 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 , Andriy Gelman , Andreas Rheinhardt Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: softworkz Signed-off-by: softworkz --- libavfilter/vf_subtitles.c | 67 ++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c index 82e140e986..0ae156ad07 100644 --- a/libavfilter/vf_subtitles.c +++ b/libavfilter/vf_subtitles.c @@ -36,14 +36,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; @@ -304,8 +302,42 @@ 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 enum AVSubtitleType get_subtitle_format(const AVCodecDescriptor *codec_descriptor) +{ + if(codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) + return AV_SUBTITLE_FMT_BITMAP; + + if(codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB) + return AV_SUBTITLE_FMT_ASS; + + return AV_SUBTITLE_FMT_UNKNOWN; +} + static av_cold int init_subtitles(AVFilterContext *ctx) { int j, ret, sid; @@ -318,6 +350,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); @@ -398,13 +431,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 = 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); @@ -460,27 +497,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: -- ffmpeg-codebot _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".