From patchwork Sat Jun 25 09:57:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36432 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp825539pzh; Sat, 25 Jun 2022 02:59:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1undT9wjaj8/1s09pnFqn1gX9TmkjH5rOnTlLGoXFriBsSRPNFDwRC+TtUa0GwUEo4p8xEX X-Received: by 2002:a05:6402:1854:b0:435:7f6e:e553 with SMTP id v20-20020a056402185400b004357f6ee553mr4135614edy.282.1656151158599; Sat, 25 Jun 2022 02:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656151158; cv=none; d=google.com; s=arc-20160816; b=02u11o+ftmwX7dtoI2kigS4CeBuLoS9qiRfmwodFSxWKSStgDR/xwyNTMEM2WxwtHx RvIoIbKGrS7x+rZZkYsjtyMm89SHLXRZr11TGf1iyvFuQvLFQ/mcc1D0ZVAhXf+XWPW/ rCr6nWpmphH1Vtal7nVBmNmfxTz4gNmRzNpa4JlC2PMU/RlR6ZhkADyweY4lerOn4joO HiD5wqII5gz6aCWTbJC5gpPoxQCSUNJYGD8wVPAmtrCa/l72LNnUpmd9/dLrlobnlmue Cpqh/tQvxCeesjN05HxojpyHNys94V8jWSZ5fMhdIeGHYAXkbg5SlvgJTYkN9V+Qo4Oo EC5Q== 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:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=6wqfjOCZN/DLVbp8V9Nqyhg5ilk9fIwTZDNqS60LX8U=; b=sCJZ/qsPjrCahVMVHb+hqHq2dK4nAk5XjQXtNnvRBmyqrDBiJWUJ2+EiD807Ndij3I /WNFHE8eQc9yDtrSv4v5XtXGwlU3XQTpMk+yJi3e1M7EGDwC+1Zq64luBT93E48Zn0uJ 2RJjwWeVEyO/kJpG86z9FLhILbXhTN49J+eShcMXuIID+cHCGT99iCWZwYMtxOtncCCs NtomzhXv/ERjxFWnQjEDfx+Dqf0HAT9tJkNk3UCRC+WusJ+Lo+l3A+3utENDfAJnwkPT B0ff9JqHAwA738b3le2qx9TUr3DGk+weSI+hugNuSDcihJxsYHCQOFM11fYnKaLsDDbI hS1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=huN3PyYP; 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 g23-20020a50d0d7000000b0042bd134b727si7090606edf.129.2022.06.25.02.59.18; Sat, 25 Jun 2022 02:59:18 -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=20210112 header.b=huN3PyYP; 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 35B6D68B83C; Sat, 25 Jun 2022 12:58:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ED47868B812 for ; Sat, 25 Jun 2022 12:58:14 +0300 (EEST) Received: by mail-pl1-f174.google.com with SMTP id m14so4120850plg.5 for ; Sat, 25 Jun 2022 02:58:14 -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=sudeUR61eBYI+Fyp+5hQtywz0i+fvmHVnQPMuFmx5q0=; b=huN3PyYPVQ+8YRYKMg+UyhIy2/EIk7wPfNvwFUgnKQ7t3n2o2hmldxOW4sJtz6RdZB cWyrnh2648Y0Vxgqd9XRXvYIFLd188WneeoDQxYOab/hjEHFXfN3ecADG7yNSbMbvLIJ bLMSRSvKsrPeKhcza8zVaVWEeaqZLMzzjenKAjvNhbCssCH4rY1Mm1RLT4ozScuKDAq5 dNjgk2YmgbbQYT52FG9CvmGNsjPFeqq/fAVj0yTmUTRJclYpUY/vSU3DLyREz5D6tuB5 e6cuJxX/NDQ5O5PjOH4bnz7VIZwop34V7uuRMAFdSbkixsJCmgHaj2XD7bBVkN/0TEss 1IMQ== 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=sudeUR61eBYI+Fyp+5hQtywz0i+fvmHVnQPMuFmx5q0=; b=iW5BFSOWXzimHj3xyjKoriJ61zF4vrMPjmw6YvIvaxHiHvh6YaaVqvtM3mP2VXg3yz 5uKouMS/xMV3o57QX9RzOQ/2txKXJOfGHvTh2vJ/87K42UmGVb3xN6iO3Hh1IYIrqB+f spGhayuKsBK3E73SLW1k/hgMANzdWvsvg1X6qPozFO0bU/Rg0XawkfqZUX3Hb+bC+yFf YI8zrGTxJJPrkUW6JOqWk1FWs0UpooF1FZHUy4pnPDvifjLOd9mZoGLsnwlgG71mTg/w woqzc3vsxt8Ai4g6IQc9ChMsZPzUvFDYjxKg/FqbyunL4c4mMXlstdB2oyLRH/axHe21 QbzQ== X-Gm-Message-State: AJIora+HeynHCnEXVl7dhuBCwKdkakzkjcoM0ATFU6BpI2ByIoG6Qwx0 XazOrsQD4QEK59NZMP5+kxMNYFgpHdvqQw== X-Received: by 2002:a17:90a:e7c7:b0:1ec:99eb:ff3a with SMTP id kb7-20020a17090ae7c700b001ec99ebff3amr8775274pjb.204.1656151093053; Sat, 25 Jun 2022 02:58:13 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id a8-20020a654188000000b003fd4831e6fesm3181732pgq.70.2022.06.25.02.58.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Jun 2022 02:58:12 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Sat, 25 Jun 2022 09:57:42 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v5 10/25] avfilter/avfilter: Handle subtitle frames 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tRSFvVJFn0el From: softworkz Signed-off-by: softworkz --- libavfilter/avfilter.c | 12 +++++++++--- libavfilter/avfilter.h | 11 +++++++++++ libavfilter/avfiltergraph.c | 5 +++++ libavfilter/formats.c | 16 ++++++++++++++++ libavfilter/formats.h | 3 +++ libavfilter/internal.h | 18 +++++++++++++++--- 6 files changed, 59 insertions(+), 6 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 28c5430c3e..30745f41cb 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -52,7 +52,8 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end) ref->linesize[0], ref->linesize[1], ref->linesize[2], ref->linesize[3], ref->pts, ref->pkt_pos); - if (ref->width) { + switch(ref->type) { + case AVMEDIA_TYPE_VIDEO: ff_tlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c", ref->sample_aspect_ratio.num, ref->sample_aspect_ratio.den, ref->width, ref->height, @@ -60,12 +61,13 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end) ref->top_field_first ? 'T' : 'B', /* Top / Bottom */ ref->key_frame, av_get_picture_type_char(ref->pict_type)); - } - if (ref->nb_samples) { + break; + case AVMEDIA_TYPE_AUDIO: ff_tlog(ctx, " cl:%"PRId64"d n:%d r:%d", ref->channel_layout, ref->nb_samples, ref->sample_rate); + break; } ff_tlog(ctx, "]%s", end ? "\n" : ""); @@ -1013,6 +1015,10 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame) av_assert1(frame->width == link->w); av_assert1(frame->height == link->h); } + } else if (link->type == AVMEDIA_TYPE_SUBTITLE) { + if (frame->format != link->format) { + av_log(link->dst, AV_LOG_WARNING, "Subtitle format change from %d to %d\n", link->format, frame->format); + } } else { if (frame->format != link->format) { av_log(link->dst, AV_LOG_ERROR, "Format change is not supported\n"); diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 2e8197c9a6..c436f304bc 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -45,6 +45,7 @@ #include "libavutil/log.h" #include "libavutil/samplefmt.h" #include "libavutil/pixfmt.h" +#include "libavutil/subfmt.h" #include "libavutil/rational.h" #include "libavfilter/version_major.h" @@ -349,6 +350,12 @@ typedef struct AVFilter { * and outputs use the same sample rate and channel count/layout. */ const enum AVSampleFormat *samples_list; + /** + * Analogous to pixels, but delimited by AV_SUBTITLE_FMT_NONE + * and restricted to filters that only have AVMEDIA_TYPE_SUBTITLE + * inputs and outputs. + */ + const enum AVSubtitleType *subs_list; /** * Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list. */ @@ -357,6 +364,10 @@ typedef struct AVFilter { * Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list. */ enum AVSampleFormat sample_fmt; + /** + * Equivalent to { sub_fmt, AV_SUBTITLE_FMT_NONE } as subs_list. + */ + enum AVSubtitleType sub_fmt; } formats; int priv_size; ///< size of private data to allocate for the filter diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index b7dbfc063b..f37be0203b 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -309,6 +309,8 @@ static int filter_link_check_formats(void *log, AVFilterLink *link, AVFilterForm return ret; break; + case AVMEDIA_TYPE_SUBTITLE: + return 0; default: av_assert0(!"reached"); } @@ -439,6 +441,9 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) if (!link) continue; + if (link->type == AVMEDIA_TYPE_SUBTITLE) + continue; + neg = ff_filter_get_negotiation(link); av_assert0(neg); for (neg_step = 1; neg_step < neg->nb_mergers; neg_step++) { diff --git a/libavfilter/formats.c b/libavfilter/formats.c index e8c2888c0c..12585ed428 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/subfmt.h" #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" @@ -491,6 +492,13 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type) return NULL; fmt++; } + } else if (type == AVMEDIA_TYPE_SUBTITLE) { + if (ff_add_format(&ret, AV_SUBTITLE_FMT_BITMAP) < 0) + return NULL; + if (ff_add_format(&ret, AV_SUBTITLE_FMT_ASS) < 0) + return NULL; + if (ff_add_format(&ret, AV_SUBTITLE_FMT_TEXT) < 0) + return NULL; } return ret; @@ -774,6 +782,10 @@ int ff_default_query_formats(AVFilterContext *ctx) type = AVMEDIA_TYPE_AUDIO; formats = ff_make_format_list(f->formats.samples_list); break; + case FF_FILTER_FORMATS_SUBFMTS_LIST: + type = AVMEDIA_TYPE_SUBTITLE; + formats = ff_make_format_list(f->formats.subs_list); + break; case FF_FILTER_FORMATS_SINGLE_PIXFMT: type = AVMEDIA_TYPE_VIDEO; formats = ff_make_formats_list_singleton(f->formats.pix_fmt); @@ -782,6 +794,10 @@ int ff_default_query_formats(AVFilterContext *ctx) type = AVMEDIA_TYPE_AUDIO; formats = ff_make_formats_list_singleton(f->formats.sample_fmt); break; + case FF_FILTER_FORMATS_SINGLE_SUBFMT: + type = AVMEDIA_TYPE_SUBTITLE; + formats = ff_make_formats_list_singleton(f->formats.sub_fmt); + break; default: av_assert2(!"Unreachable"); /* Intended fallthrough */ diff --git a/libavfilter/formats.h b/libavfilter/formats.h index 22224dce2d..6cf952a059 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -183,6 +183,9 @@ av_warn_unused_result int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout); +av_warn_unused_result +int ff_add_subtitle_type(AVFilterFormats **avff, int64_t fmt); + /** * Add *ref as a new reference to f. */ diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 6c8496879a..7972c5c6de 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -148,9 +148,11 @@ static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_act enum FilterFormatsState { /** - * The default value meaning that this filter supports all formats - * and (for audio) sample rates and channel layouts/counts as long - * as these properties agree for all inputs and outputs. + * The default value meaning that this filter supports + * - For video: all formats + * - For audio: all sample rates and channel layouts/counts + * - For subtitles: all subtitle formats + * as long as these properties agree for all inputs and outputs. * This state is only allowed in case all inputs and outputs actually * have the same type. * The union is unused in this state. @@ -161,8 +163,10 @@ enum FilterFormatsState { FF_FILTER_FORMATS_QUERY_FUNC, ///< formats.query active. FF_FILTER_FORMATS_PIXFMT_LIST, ///< formats.pixels_list active. FF_FILTER_FORMATS_SAMPLEFMTS_LIST, ///< formats.samples_list active. + FF_FILTER_FORMATS_SUBFMTS_LIST, ///< formats.subs_list active. FF_FILTER_FORMATS_SINGLE_PIXFMT, ///< formats.pix_fmt active FF_FILTER_FORMATS_SINGLE_SAMPLEFMT, ///< formats.sample_fmt active. + FF_FILTER_FORMATS_SINGLE_SUBFMT, ///< formats.sub_fmt active. }; #define FILTER_QUERY_FUNC(func) \ @@ -174,16 +178,24 @@ enum FilterFormatsState { #define FILTER_SAMPLEFMTS_ARRAY(array) \ .formats.samples_list = array, \ .formats_state = FF_FILTER_FORMATS_SAMPLEFMTS_LIST +#define FILTER_SUBFMTS_ARRAY(array) \ + .formats.subs_list = array, \ + .formats_state = FF_FILTER_FORMATS_SUBFMTS_LIST #define FILTER_PIXFMTS(...) \ FILTER_PIXFMTS_ARRAY(((const enum AVPixelFormat []) { __VA_ARGS__, AV_PIX_FMT_NONE })) #define FILTER_SAMPLEFMTS(...) \ FILTER_SAMPLEFMTS_ARRAY(((const enum AVSampleFormat[]) { __VA_ARGS__, AV_SAMPLE_FMT_NONE })) +#define FILTER_SUBFMTS(...) \ + FILTER_SUBFMTS_ARRAY(((const enum AVSubtitleType[]) { __VA_ARGS__, AV_SUBTITLE_FMT_NONE })) #define FILTER_SINGLE_PIXFMT(pix_fmt_) \ .formats.pix_fmt = pix_fmt_, \ .formats_state = FF_FILTER_FORMATS_SINGLE_PIXFMT #define FILTER_SINGLE_SAMPLEFMT(sample_fmt_) \ .formats.sample_fmt = sample_fmt_, \ .formats_state = FF_FILTER_FORMATS_SINGLE_SAMPLEFMT +#define FILTER_SINGLE_SUBFMT(sub_fmt_) \ + .formats.sub_fmt = sub_fmt_, \ + .formats_state = FF_FILTER_FORMATS_SINGLE_SUBFMT #define FILTER_INOUTPADS(inout, array) \ .inout = array, \