From patchwork Tue Jul 23 14:51:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Oltmanns X-Patchwork-Id: 50713 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:a742:0:b0:482:c625:d099 with SMTP id f2csp2677328vqm; Tue, 23 Jul 2024 07:52:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXMrrhv+HPeAe19fiyD2Xtk+KkLaE/9I48C1TbqZvHyo4//eW2YJFsZ7K/K524/XSfZUJsDH2NhNVLJWLn4lBxGuLC/7qkzYGq6Ww== X-Google-Smtp-Source: AGHT+IEtLkz0WMEnZqFlrvljIFHdIAJkjUSZIyIwyhZnIutaoh9ijh7r7gWbUscuPK4/+zTKuZPo X-Received: by 2002:a50:c041:0:b0:5a2:8bef:c370 with SMTP id 4fb4d7f45d1cf-5aaa3d7a2ecmr100542a12.15.1721746321465; Tue, 23 Jul 2024 07:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721746321; cv=none; d=google.com; s=arc-20160816; b=jczVxm05aNa91QGWyyIVPik5y3wGskGjxBbk2ZBJlOYFg4dDUu3MuINiB4PlDFT9At 85kz23iWXGWh8Py+9Q5wA5IZ2yhWjLFCeYcI08DkVCtFYTkuYKo4Gg7egZWhXMUmyFjv Ba9sU0NkId7Y6GZXKRdwvizSfoAqGgpnvwKq+2YK/1DAEoWIP6thha8IomiDJhpap6Ei apYnZKaPSi+lMovrsCIShaL4E4a91wwGstiDU/9436mEr9ZS04SlxOgddVQjrq6dkY7p cI2U18IzXv4rtBKxqdfPCFuP9m03XYQY7nZiGCzvNyBGopO7c/yplsnSV39lEfmYMznO myvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :ui-outboundreport:content-language:to:user-agent:mime-version:date :message-id:delivered-to; bh=I/g291dk4brUlNpHiZnFH+nGGGgnucGCrDlZOd9JHLI=; fh=fcJVYuKBz42Tmr+GF9+673T/g5dDxXNShPnqZaNJEIc=; b=WAmyZpSBth24LcU38dmVEHTXrGjBAfdZ0h2zf3mSerVjuAgb2FTO+4K/A/yOoPBzO9 rEx0QMzt4ESv3/Ee0B6L28EBnVdLxNkG+s6YMOOZiAshkeyc640KkMYk/1A48acLoPGp 7Xlm7jj8f6Rd5GdPyaS4sVSkRV9R+z+AHyKAp8p6c9ykD7JA/id/BTAsrPaS+Pzj3Cdl CfBdNd09V7di2Rmr04RWUsoRaBHmwju70OgmOjX+O4d1KoEHk5DBp2uKosbVjyDZtoym 8SXrG3LiKwbDM//LrlYUTLtXOeQ3KDZO9mXiMxl/Xm94R4QAj8FEYCUCb2P0MClQNMMk acwg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5a30c2f889asi6081628a12.441.2024.07.23.07.52.00; Tue, 23 Jul 2024 07:52:01 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AB03368D47C; Tue, 23 Jul 2024 17:51:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 53B9168D409 for ; Tue, 23 Jul 2024 17:51:50 +0300 (EEST) X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.11.12] ([91.248.195.76]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MNbox-1sgOpq1n6h-00T94w for ; Tue, 23 Jul 2024 16:51:49 +0200 Message-ID: Date: Tue, 23 Jul 2024 16:51:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org Content-Language: de-DE, en-US X-Provags-ID: V03:K1:MAs+2PoFYszKsgAB7AWwJNK+NFQ0/QMAb6qiZVXaI9RqnlpjP7+ sVz8NC+m7zsI1iOd2OM27LzBiz+TPWo62q2wBAGa7dCIQ5+qYEfwKd0nGYDq1Sgn3HKgbDi v3C/O+gO645wtVGsbI3n/1FhBL5ZSlucA7po+c9VAYgOwFhKV19XPOuH/lNuGU03eUy/TPl x4/RflXGysE+qWwR5Cc9Q== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:etEL92messc=;UD5x3xEjiZD26PdbGA9rMzN/0Cd +3USSB8cAJmn3ocPH2afgRggypriw/U+9D7OT1lwno0amTDkMVibttTD+lumH/Q5t5NG6C2F4 wWwCeuCC8Nswr7XT3mIKb6lxflJ6tHwD/yofQGAuwUbE03G1R+iX/9ut4cym+/f2Ja13Ujmkk msZVm0K4P7qz/DF+jWhQDDC+e1890NL+uUAtYNGF9kMz+l82XNIP0xYznHu4w0iC9jfc+Tvr7 KaXb9hMK5gdOv0eA+D49rknSlqZqt7XkRs4xcgtcBNGI1easJKTwlaM0pl1DGqYdD0kBCY5OD TdYPwareQNGdH4b/V8eIJXtz0bs5PDZqo9D6T3zp8bXwgMj5QGTwP8JYPZbgReApjhaeWWkWn QOH2bYVexqOakzak8NM+MVIUksMB6fLsWnlqTmJOLHi0lF0OEq2n6uTgJ5guU9Yj4sig/o3h+ e8yyIZifiU/WCXyH7ARRZGtTVP0PyKVQtNsi8gYYPH40qjMryZAJR15SxwaSedeIuxNP0+SEq /ZJbeHCnSL5YwQAxkqkH5uzEFJIFL8JMfceT6xM2U2goqqsV/U/l7vwNX0he8XC6UMjk0CPct 5Oyw6eFkbgAyexItHaAhoosnACk3R/dS8RTtePSRQ538mMZB0TuzFryLV1cPc4edDUpjBCNyf fCpqdvl/er5kq4qAOusXKxAWtceV29y9G/oRR6uuMWlAtQnUqgifffWfI8VzmeJqFuq8sjot2 Ig+cCHq68woDpvkmGyA4kqQ6gn1rO9VCzj9i0rokUNmQBRjoXTQo4NT0dkJwS4RZkUYlXLvxo n9yeOR7ahW/glL8ZtYAhT31Q== Subject: [FFmpeg-devel] [PATCH v3 1/2] libavformat/vapoursynth: Update to API version 4, load library at runtime 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: , X-Patchwork-Original-From: Stefan Oltmanns via ffmpeg-devel From: Stefan Oltmanns Reply-To: FFmpeg development discussions and patches Cc: Stefan Oltmanns Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: i2vCCdUddHUh Hello, this is revised patch, this is the first part that just updates to the API v4 of VapourSynth. Changes in API v4: -All functions previously in header are now part of the "vssapi" object -Renames of different types and functions -YCoCg is not treated as different format to YUV anymore -Some pointers to arrays are now arrays inside a struct. Best regards Stefan From 164a440ffbb5951ca38bfff56e7b62bd677d1f52 Mon Sep 17 00:00:00 2001 From: Stefan Oltmanns Date: Tue, 23 Jul 2024 16:15:36 +0200 Subject: [PATCH 1/2] avformat/vapoursynth: Update to API version 4 Signed-off-by: Stefan Oltmanns --- configure | 2 +- libavformat/vapoursynth.c | 84 +++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/configure b/configure index f6f5c29fea..c50b5ad4b4 100755 --- a/configure +++ b/configure @@ -7085,7 +7085,7 @@ enabled rkmpp && { require_pkg_config rkmpp rockchip_mpp rockchip/r { enabled libdrm || die "ERROR: rkmpp requires --enable-libdrm"; } } -enabled vapoursynth && require_pkg_config vapoursynth "vapoursynth-script >= 42" VSScript.h vsscript_init +enabled vapoursynth && require_pkg_config vapoursynth "vapoursynth-script >= 55" VSScript4.h getVSScriptAPI if enabled gcrypt; then diff --git a/libavformat/vapoursynth.c b/libavformat/vapoursynth.c index 8a2519e19a..ce15f68180 100644 --- a/libavformat/vapoursynth.c +++ b/libavformat/vapoursynth.c @@ -25,8 +25,7 @@ #include -#include -#include +#include #include "libavutil/avassert.h" #include "libavutil/avstring.h" @@ -41,6 +40,7 @@ #include "internal.h" struct VSState { + const VSSCRIPTAPI *vssapi; VSScript *vss; }; @@ -49,10 +49,10 @@ typedef struct VSContext { AVBufferRef *vss_state; + const VSSCRIPTAPI *vssapi; const VSAPI *vsapi; - VSCore *vscore; - VSNodeRef *outnode; + VSNode *outnode; int is_cfr; int current_frame; @@ -75,8 +75,7 @@ static void free_vss_state(void *opaque, uint8_t *data) struct VSState *vss = opaque; if (vss->vss) { - vsscript_freeScript(vss->vss); - vsscript_finalize(); + vss->vssapi->freeScript(vss->vss); } } @@ -90,7 +89,6 @@ static av_cold int read_close_vs(AVFormatContext *s) av_buffer_unref(&vs->vss_state); vs->vsapi = NULL; - vs->vscore = NULL; vs->outnode = NULL; return 0; @@ -106,7 +104,7 @@ static av_cold int is_native_endian(enum AVPixelFormat pixfmt) return pd && (!!HAVE_BIGENDIAN == !!(pd->flags & AV_PIX_FMT_FLAG_BE)); } -static av_cold enum AVPixelFormat match_pixfmt(const VSFormat *vsf, int c_order[4]) +static av_cold enum AVPixelFormat match_pixfmt(const VSVideoFormat *vsf, int c_order[4]) { static const int yuv_order[4] = {0, 1, 2, 0}; static const int rgb_order[4] = {1, 2, 0, 0}; @@ -128,13 +126,12 @@ static av_cold enum AVPixelFormat match_pixfmt(const VSFormat *vsf, int c_order[ pd->log2_chroma_h != vsf->subSamplingH) continue; - is_rgb = vsf->colorFamily == cmRGB; + is_rgb = vsf->colorFamily == cfRGB; if (is_rgb != !!(pd->flags & AV_PIX_FMT_FLAG_RGB)) continue; - is_yuv = vsf->colorFamily == cmYUV || - vsf->colorFamily == cmYCoCg || - vsf->colorFamily == cmGray; + is_yuv = vsf->colorFamily == cfYUV || + vsf->colorFamily == cfGray; if (!is_rgb && !is_yuv) continue; @@ -176,15 +173,30 @@ static av_cold int read_header_vs(AVFormatContext *s) int64_t sz = avio_size(pb); char *buf = NULL; char dummy; + char vsfmt[32]; const VSVideoInfo *info; struct VSState *vss_state; int err = 0; + if (!(vs->vssapi = getVSScriptAPI(VSSCRIPT_API_VERSION))) { + av_log(s, AV_LOG_ERROR, "Failed to initialize VSScript (possibly PYTHONPATH not set).\n"); + err = AVERROR_EXTERNAL; + goto done; + } + + if (!(vs->vsapi = vs->vssapi->getVSAPI(VAPOURSYNTH_API_VERSION))) { + av_log(s, AV_LOG_ERROR, "Could not get VSAPI. " + "Check VapourSynth installation.\n"); + err = AVERROR_EXTERNAL; + goto done; + } + vss_state = av_mallocz(sizeof(*vss_state)); if (!vss_state) { err = AVERROR(ENOMEM); goto done; } + vss_state->vssapi = vs->vssapi; vs->vss_state = av_buffer_create(NULL, 0, free_vss_state, vss_state, 0); if (!vs->vss_state) { @@ -193,16 +205,9 @@ static av_cold int read_header_vs(AVFormatContext *s) goto done; } - if (!vsscript_init()) { - av_log(s, AV_LOG_ERROR, "Failed to initialize VSScript (possibly PYTHONPATH not set).\n"); - err = AVERROR_EXTERNAL; - goto done; - } - - if (vsscript_createScript(&vss_state->vss)) { + if (!(vss_state->vss = vs->vssapi->createScript(NULL))) { av_log(s, AV_LOG_ERROR, "Failed to create script instance.\n"); err = AVERROR_EXTERNAL; - vsscript_finalize(); goto done; } @@ -235,17 +240,14 @@ static av_cold int read_header_vs(AVFormatContext *s) } buf[sz] = '\0'; - if (vsscript_evaluateScript(&vss_state->vss, buf, s->url, 0)) { - const char *msg = vsscript_getError(vss_state->vss); + if (vs->vssapi->evaluateBuffer(vss_state->vss, buf, s->url)) { + const char *msg = vs->vssapi->getError(vss_state->vss); av_log(s, AV_LOG_ERROR, "Failed to parse script: %s\n", msg ? msg : "(unknown)"); err = AVERROR_EXTERNAL; goto done; } - vs->vsapi = vsscript_getVSApi(); - vs->vscore = vsscript_getCore(vss_state->vss); - - vs->outnode = vsscript_getOutput(vss_state->vss, 0); + vs->outnode = vs->vssapi->getOutputNode(vss_state->vss, 0); if (!vs->outnode) { av_log(s, AV_LOG_ERROR, "Could not get script output node.\n"); err = AVERROR_EXTERNAL; @@ -260,7 +262,7 @@ static av_cold int read_header_vs(AVFormatContext *s) info = vs->vsapi->getVideoInfo(vs->outnode); - if (!info->format || !info->width || !info->height) { + if (!info->format.colorFamily || !info->width || !info->height) { av_log(s, AV_LOG_ERROR, "Non-constant input format not supported.\n"); err = AVERROR_PATCHWELCOME; goto done; @@ -280,18 +282,22 @@ static av_cold int read_header_vs(AVFormatContext *s) st->codecpar->codec_id = AV_CODEC_ID_WRAPPED_AVFRAME; st->codecpar->width = info->width; st->codecpar->height = info->height; - st->codecpar->format = match_pixfmt(info->format, vs->c_order); + st->codecpar->format = match_pixfmt(&info->format, vs->c_order); if (st->codecpar->format == AV_PIX_FMT_NONE) { - av_log(s, AV_LOG_ERROR, "Unsupported VS pixel format %s\n", info->format->name); + if(vs->vsapi->getVideoFormatName(&info->format, vsfmt)) + av_log(s, AV_LOG_ERROR, "Unsupported VS pixel format %s\n", vsfmt); + else + av_log(s, AV_LOG_ERROR, "Unsupported VS pixel format\n"); err = AVERROR_EXTERNAL; goto done; } - av_log(s, AV_LOG_VERBOSE, "VS format %s -> pixfmt %s\n", info->format->name, - av_get_pix_fmt_name(st->codecpar->format)); - - if (info->format->colorFamily == cmYCoCg) - st->codecpar->color_space = AVCOL_SPC_YCGCO; + if (vs->vsapi->getVideoFormatName(&info->format, vsfmt)) + av_log(s, AV_LOG_VERBOSE, "VS format %s -> pixfmt %s\n", + vsfmt, av_get_pix_fmt_name(st->codecpar->format)); + else + av_log(s, AV_LOG_VERBOSE, "VS format -> pixfmt %s\n", + av_get_pix_fmt_name(st->codecpar->format)); done: av_free(buf); @@ -311,13 +317,13 @@ static int get_vs_prop_int(AVFormatContext *s, const VSMap *map, const char *nam int64_t res; int err = 1; - res = vs->vsapi->propGetInt(map, name, 0, &err); + res = vs->vsapi->mapGetInt(map, name, 0, &err); return err || res < INT_MIN || res > INT_MAX ? def : res; } struct vsframe_ref_data { const VSAPI *vsapi; - const VSFrameRef *frame; + const VSFrame *frame; AVBufferRef *vss_state; }; @@ -339,7 +345,7 @@ static int read_packet_vs(AVFormatContext *s, AVPacket *pkt) AVStream *st = s->streams[0]; AVFrame *frame = NULL; char vserr[80]; - const VSFrameRef *vsframe; + const VSFrame *vsframe; const VSVideoInfo *info = vs->vsapi->getVideoInfo(vs->outnode); const VSMap *props; const AVPixFmtDescriptor *desc; @@ -381,7 +387,7 @@ static int read_packet_vs(AVFormatContext *s, AVPacket *pkt) goto end; } - props = vs->vsapi->getFramePropsRO(vsframe); + props = vs->vsapi->getFramePropertiesRO(vsframe); frame = av_frame_alloc(); if (!frame) { @@ -410,7 +416,7 @@ static int read_packet_vs(AVFormatContext *s, AVPacket *pkt) desc = av_pix_fmt_desc_get(frame->format); - for (i = 0; i < info->format->numPlanes; i++) { + for (i = 0; i < info->format.numPlanes; i++) { int p = vs->c_order[i]; ptrdiff_t plane_h = frame->height; -- 2.34.1