* [FFmpeg-devel] [PATCH v3 1/2] libavformat/vapoursynth: Update to API version 4, load library at runtime @ 2024-07-23 14:51 Stefan Oltmanns via ffmpeg-devel 2024-07-23 14:59 ` [FFmpeg-devel] [PATCH v3 2/2] " Stefan Oltmanns via ffmpeg-devel 2024-07-28 13:09 ` [FFmpeg-devel] [PATCH v3 1/2] " Ramiro Polla 0 siblings, 2 replies; 8+ messages in thread From: Stefan Oltmanns via ffmpeg-devel @ 2024-07-23 14:51 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Stefan Oltmanns [-- Attachment #1: Type: text/plain, Size: 384 bytes --] 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 [-- Attachment #2: 0001-avformat-vapoursynth-Update-to-API-version-4.patch --] [-- Type: text/x-patch, Size: 9000 bytes --] From 164a440ffbb5951ca38bfff56e7b62bd677d1f52 Mon Sep 17 00:00:00 2001 From: Stefan Oltmanns <stefan-oltmanns@gmx.net> 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 <stefan-oltmanns@gmx.net> --- 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 <limits.h> -#include <VapourSynth.h> -#include <VSScript.h> +#include <VSScript4.h> #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 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 2/2] libavformat/vapoursynth: Update to API version 4, load library at runtime 2024-07-23 14:51 [FFmpeg-devel] [PATCH v3 1/2] libavformat/vapoursynth: Update to API version 4, load library at runtime Stefan Oltmanns via ffmpeg-devel @ 2024-07-23 14:59 ` Stefan Oltmanns via ffmpeg-devel 2024-07-28 13:15 ` Ramiro Polla 2024-07-28 13:09 ` [FFmpeg-devel] [PATCH v3 1/2] " Ramiro Polla 1 sibling, 1 reply; 8+ messages in thread From: Stefan Oltmanns via ffmpeg-devel @ 2024-07-23 14:59 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Stefan Oltmanns [-- Attachment #1: Type: text/plain, Size: 1261 bytes --] This is the second part for loading the library at runtime, changes compared to previous patch revisions: -No atexit anymore -No global states anymore -Moved the registry read for Windows from a separate function inside the function to load the dynamic library and simplified it, reducing the amount windows-specific code. Tested with 2 VapourSynth inputs on these platforms, no problems and clean exit: -Linux x86_64 (Ubuntu 22.04) -Windows 10 x86_64 -macOS 14 aarch64 Best regards Stefan Am 23.07.24 um 16:51 schrieb Stefan Oltmanns via ffmpeg-devel: > 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 > > _______________________________________________ > 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". [-- Attachment #2: 0002-avformat-vapoursynth-load-library-at-runtime.patch --] [-- Type: text/x-patch, Size: 4544 bytes --] From 6a8e8b7d5bfcfb8eb3cb24ea1f7e14ca117882c4 Mon Sep 17 00:00:00 2001 From: Stefan Oltmanns <stefan-oltmanns@gmx.net> Date: Tue, 23 Jul 2024 16:19:46 +0200 Subject: [PATCH 2/2] avformat/vapoursynth: load library at runtime Signed-off-by: Stefan Oltmanns <stefan-oltmanns@gmx.net> --- configure | 2 +- libavformat/vapoursynth.c | 65 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/configure b/configure index c50b5ad4b4..1b6670505a 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 >= 55" VSScript4.h getVSScriptAPI +enabled vapoursynth && require_headers "vapoursynth/VSScript4.h vapoursynth/VapourSynth4.h" if enabled gcrypt; then diff --git a/libavformat/vapoursynth.c b/libavformat/vapoursynth.c index ce15f68180..ad1d6eac61 100644 --- a/libavformat/vapoursynth.c +++ b/libavformat/vapoursynth.c @@ -25,7 +25,7 @@ #include <limits.h> -#include <VSScript4.h> +#include <vapoursynth/VSScript4.h> #include "libavutil/avassert.h" #include "libavutil/avstring.h" @@ -39,11 +39,26 @@ #include "demux.h" #include "internal.h" +/* Platform-specific directives. */ +#ifdef _WIN32 + #include <windows.h> + #include "compat/w32dlfcn.h" + #include "libavutil/wchar_filename.h" + #undef EXTERN_C + #define VSSCRIPT_LIB "VSScript.dll" +#else + #include <dlfcn.h> + #define VSSCRIPT_NAME "libvapoursynth-script" + #define VSSCRIPT_LIB VSSCRIPT_NAME SLIBSUF +#endif + struct VSState { const VSSCRIPTAPI *vssapi; VSScript *vss; }; +typedef const VSSCRIPTAPI *(*VSScriptGetAPIFunc)(int version); + typedef struct VSContext { const AVClass *class; @@ -51,6 +66,7 @@ typedef struct VSContext { const VSSCRIPTAPI *vssapi; const VSAPI *vsapi; + void *vslibrary; VSNode *outnode; int is_cfr; @@ -70,6 +86,40 @@ static const AVOption options[] = { {NULL} }; +static av_cold void* vs_load_library(VSScriptGetAPIFunc *get_vssapi) +{ + void *vslibrary = NULL; +#ifdef _WIN32 + const HKEY hkeys[] = {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE}; + LONG r; + WCHAR vss_path[512]; + DWORD buf_size = sizeof(vss_path) - 2; + char *vss_path_utf8; + int i; + + for (i = 0; i < sizeof(hkeys); i++) { + if ((r = RegGetValueW(hkeys[i], L"SOFTWARE\\VapourSynth", + L"VSScriptDLL", RRF_RT_REG_SZ, NULL, + &vss_path, &buf_size)) == ERROR_SUCCESS) + break; + } + if (r == ERROR_SUCCESS && wchartoutf8(vss_path, &vss_path_utf8) == 0) { + vslibrary = dlopen(vss_path_utf8, RTLD_NOW | RTLD_GLOBAL); + av_free(vss_path_utf8); + } + else +#endif + vslibrary = dlopen(VSSCRIPT_LIB, RTLD_NOW | RTLD_GLOBAL); + + if (vslibrary != NULL) { + if (!(*get_vssapi = (VSScriptGetAPIFunc)dlsym(vslibrary, "getVSScriptAPI"))) { + dlclose(vslibrary); + return NULL; + } + } + return vslibrary; +} + static void free_vss_state(void *opaque, uint8_t *data) { struct VSState *vss = opaque; @@ -91,6 +141,9 @@ static av_cold int read_close_vs(AVFormatContext *s) vs->vsapi = NULL; vs->outnode = NULL; + if (vs->vslibrary) + dlclose(vs->vslibrary); + return 0; } @@ -170,6 +223,7 @@ static av_cold int read_header_vs(AVFormatContext *s) AVStream *st; AVIOContext *pb = s->pb; VSContext *vs = s->priv_data; + VSScriptGetAPIFunc get_vssapi; int64_t sz = avio_size(pb); char *buf = NULL; char dummy; @@ -178,7 +232,14 @@ static av_cold int read_header_vs(AVFormatContext *s) struct VSState *vss_state; int err = 0; - if (!(vs->vssapi = getVSScriptAPI(VSSCRIPT_API_VERSION))) { + if (!(vs->vslibrary = vs_load_library(&get_vssapi))) { + av_log(s, AV_LOG_ERROR, "Could not open " VSSCRIPT_LIB ". " + "Check VapourSynth installation.\n"); + err = AVERROR_EXTERNAL; + goto done; + } + + if (!(vs->vssapi = get_vssapi(VSSCRIPT_API_VERSION))) { av_log(s, AV_LOG_ERROR, "Failed to initialize VSScript (possibly PYTHONPATH not set).\n"); err = AVERROR_EXTERNAL; goto done; -- 2.34.1 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 2/2] libavformat/vapoursynth: Update to API version 4, load library at runtime 2024-07-23 14:59 ` [FFmpeg-devel] [PATCH v3 2/2] " Stefan Oltmanns via ffmpeg-devel @ 2024-07-28 13:15 ` Ramiro Polla 2024-07-29 3:46 ` Stefan Oltmanns via ffmpeg-devel 0 siblings, 1 reply; 8+ messages in thread From: Ramiro Polla @ 2024-07-28 13:15 UTC (permalink / raw) To: ffmpeg-devel On 2024-07-23 16:59, Stefan Oltmanns via ffmpeg-devel wrote: > This is the second part for loading the library at runtime, changes > compared to previous patch revisions: > > -No atexit anymore > -No global states anymore > -Moved the registry read for Windows from a separate function inside the > function to load the dynamic library and simplified it, reducing the > amount windows-specific code. > > Tested with 2 VapourSynth inputs on these platforms, no problems and > clean exit: > > -Linux x86_64 (Ubuntu 22.04) > -Windows 10 x86_64 > -macOS 14 aarch64 > From 6a8e8b7d5bfcfb8eb3cb24ea1f7e14ca117882c4 Mon Sep 17 00:00:00 2001 > From: Stefan Oltmanns <stefan-oltmanns@gmx.net> > Date: Tue, 23 Jul 2024 16:19:46 +0200 > Subject: [PATCH 2/2] avformat/vapoursynth: load library at runtime > > Signed-off-by: Stefan Oltmanns <stefan-oltmanns@gmx.net> > --- > configure | 2 +- > libavformat/vapoursynth.c | 65 +++++++++++++++++++++++++++++++++++++-- > 2 files changed, 64 insertions(+), 3 deletions(-) > > diff --git a/configure b/configure > index c50b5ad4b4..1b6670505a 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 >= 55" VSScript4.h getVSScriptAPI > +enabled vapoursynth && require_headers "vapoursynth/VSScript4.h vapoursynth/VapourSynth4.h" > > > if enabled gcrypt; then > diff --git a/libavformat/vapoursynth.c b/libavformat/vapoursynth.c > index ce15f68180..ad1d6eac61 100644 > --- a/libavformat/vapoursynth.c > +++ b/libavformat/vapoursynth.c > @@ -25,7 +25,7 @@ > > #include <limits.h> > > -#include <VSScript4.h> > +#include <vapoursynth/VSScript4.h> > > #include "libavutil/avassert.h" > #include "libavutil/avstring.h" > @@ -39,11 +39,26 @@ > #include "demux.h" > #include "internal.h" > > +/* Platform-specific directives. */ > +#ifdef _WIN32 > + #include <windows.h> > + #include "compat/w32dlfcn.h" > + #include "libavutil/wchar_filename.h" > + #undef EXTERN_C > + #define VSSCRIPT_LIB "VSScript.dll" > +#else > + #include <dlfcn.h> > + #define VSSCRIPT_NAME "libvapoursynth-script" > + #define VSSCRIPT_LIB VSSCRIPT_NAME SLIBSUF > +#endif > + > struct VSState { > const VSSCRIPTAPI *vssapi; > VSScript *vss; > }; > > +typedef const VSSCRIPTAPI *(*VSScriptGetAPIFunc)(int version); > + > typedef struct VSContext { > const AVClass *class; > > @@ -51,6 +66,7 @@ typedef struct VSContext { > > const VSSCRIPTAPI *vssapi; > const VSAPI *vsapi; > + void *vslibrary; > > VSNode *outnode; > int is_cfr; > @@ -70,6 +86,40 @@ static const AVOption options[] = { > {NULL} > }; > > +static av_cold void* vs_load_library(VSScriptGetAPIFunc *get_vssapi) > +{ > + void *vslibrary = NULL; > +#ifdef _WIN32 > + const HKEY hkeys[] = {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE}; > + LONG r; > + WCHAR vss_path[512]; > + DWORD buf_size = sizeof(vss_path) - 2; > + char *vss_path_utf8; > + int i; > + > + for (i = 0; i < sizeof(hkeys); i++) { FF_ARRAY_ELEMS(hkeys) > + if ((r = RegGetValueW(hkeys[i], L"SOFTWARE\\VapourSynth", > + L"VSScriptDLL", RRF_RT_REG_SZ, NULL, > + &vss_path, &buf_size)) == ERROR_SUCCESS) > + break; > + } > + if (r == ERROR_SUCCESS && wchartoutf8(vss_path, &vss_path_utf8) == 0) { > + vslibrary = dlopen(vss_path_utf8, RTLD_NOW | RTLD_GLOBAL); I think calling win32_dlopen() with a full path will be problematic for systems without KB2533623. win32_dlopen() might need to be fixed in a separate patch. [...] Regards, Ramiro _______________________________________________ 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". ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 2/2] libavformat/vapoursynth: Update to API version 4, load library at runtime 2024-07-28 13:15 ` Ramiro Polla @ 2024-07-29 3:46 ` Stefan Oltmanns via ffmpeg-devel 2024-07-30 14:12 ` Ramiro Polla 0 siblings, 1 reply; 8+ messages in thread From: Stefan Oltmanns via ffmpeg-devel @ 2024-07-29 3:46 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Stefan Oltmanns [-- Attachment #1: Type: text/plain, Size: 1693 bytes --] Am 28.07.24 um 15:15 schrieb Ramiro Polla: >> + void *vslibrary = NULL; >> +#ifdef _WIN32 >> + const HKEY hkeys[] = {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE}; >> + LONG r; >> + WCHAR vss_path[512]; >> + DWORD buf_size = sizeof(vss_path) - 2; >> + char *vss_path_utf8; >> + int i; >> + >> + for (i = 0; i < sizeof(hkeys); i++) { > > FF_ARRAY_ELEMS(hkeys) fixed > >> + if ((r = RegGetValueW(hkeys[i], L"SOFTWARE\\VapourSynth", >> + L"VSScriptDLL", RRF_RT_REG_SZ, NULL, >> + &vss_path, &buf_size)) == ERROR_SUCCESS) >> + break; >> + } >> + if (r == ERROR_SUCCESS && wchartoutf8(vss_path, &vss_path_utf8) >> == 0) { >> + vslibrary = dlopen(vss_path_utf8, RTLD_NOW | RTLD_GLOBAL); > > I think calling win32_dlopen() with a full path will be problematic for > systems without KB2533623. win32_dlopen() might need to be fixed in a > separate patch. > Yes, win32_dlopen would need to check if a full path is already given and if yes skip all the stuff to determine it's own and system32 path, but instead just use the given parameter directly. To check if it's a full path it should be enough to check if it either starts with "\??\" (NT-style path) or if the second character is ":" (win32 style path). But is this really is needed for an operating system that reached support end over 4 years ago and does not have a security patch applied released over 13 years ago? I don't know what ffmpeg's exact policy is in this case, just asking. Best regards Stefan [-- Attachment #2: 0002-avformat-vapoursynth-load-library-at-runtime.patch --] [-- Type: text/x-patch, Size: 4552 bytes --] From dc396711d050c112b2ef6c37fdb67c4ec59c16a1 Mon Sep 17 00:00:00 2001 From: Stefan Oltmanns <stefan-oltmanns@gmx.net> Date: Mon, 29 Jul 2024 05:12:31 +0200 Subject: [PATCH 2/2] avformat/vapoursynth: load library at runtime Signed-off-by: Stefan Oltmanns <stefan-oltmanns@gmx.net> --- configure | 2 +- libavformat/vapoursynth.c | 65 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/configure b/configure index c50b5ad4b4..1b6670505a 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 >= 55" VSScript4.h getVSScriptAPI +enabled vapoursynth && require_headers "vapoursynth/VSScript4.h vapoursynth/VapourSynth4.h" if enabled gcrypt; then diff --git a/libavformat/vapoursynth.c b/libavformat/vapoursynth.c index 26c9986138..0fa5affa63 100644 --- a/libavformat/vapoursynth.c +++ b/libavformat/vapoursynth.c @@ -25,7 +25,7 @@ #include <limits.h> -#include <VSScript4.h> +#include <vapoursynth/VSScript4.h> #include "libavutil/avassert.h" #include "libavutil/avstring.h" @@ -39,11 +39,26 @@ #include "demux.h" #include "internal.h" +/* Platform-specific directives. */ +#ifdef _WIN32 + #include <windows.h> + #include "compat/w32dlfcn.h" + #include "libavutil/wchar_filename.h" + #undef EXTERN_C + #define VSSCRIPT_LIB "VSScript.dll" +#else + #include <dlfcn.h> + #define VSSCRIPT_NAME "libvapoursynth-script" + #define VSSCRIPT_LIB VSSCRIPT_NAME SLIBSUF +#endif + struct VSState { const VSSCRIPTAPI *vssapi; VSScript *vss; }; +typedef const VSSCRIPTAPI *(*VSScriptGetAPIFunc)(int version); + typedef struct VSContext { const AVClass *class; @@ -51,6 +66,7 @@ typedef struct VSContext { const VSSCRIPTAPI *vssapi; const VSAPI *vsapi; + void *vslibrary; VSNode *outnode; int is_cfr; @@ -70,6 +86,40 @@ static const AVOption options[] = { {NULL} }; +static av_cold void* vs_load_library(VSScriptGetAPIFunc *get_vssapi) +{ + void *vslibrary = NULL; +#ifdef _WIN32 + const HKEY hkeys[] = {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE}; + LONG r; + WCHAR vss_path[512]; + DWORD buf_size = sizeof(vss_path) - 2; + char *vss_path_utf8; + int i; + + for (i = 0; i < FF_ARRAY_ELEMS(hkeys); i++) { + if ((r = RegGetValueW(hkeys[i], L"SOFTWARE\\VapourSynth", + L"VSScriptDLL", RRF_RT_REG_SZ, NULL, + &vss_path, &buf_size)) == ERROR_SUCCESS) + break; + } + if (r == ERROR_SUCCESS && wchartoutf8(vss_path, &vss_path_utf8) == 0) { + vslibrary = dlopen(vss_path_utf8, RTLD_NOW | RTLD_GLOBAL); + av_free(vss_path_utf8); + } + else +#endif + vslibrary = dlopen(VSSCRIPT_LIB, RTLD_NOW | RTLD_GLOBAL); + + if (vslibrary != NULL) { + if (!(*get_vssapi = (VSScriptGetAPIFunc)dlsym(vslibrary, "getVSScriptAPI"))) { + dlclose(vslibrary); + return NULL; + } + } + return vslibrary; +} + static void free_vss_state(void *opaque, uint8_t *data) { struct VSState *vss = opaque; @@ -91,6 +141,9 @@ static av_cold int read_close_vs(AVFormatContext *s) vs->vsapi = NULL; vs->outnode = NULL; + if (vs->vslibrary) + dlclose(vs->vslibrary); + return 0; } @@ -170,6 +223,7 @@ static av_cold int read_header_vs(AVFormatContext *s) AVStream *st; AVIOContext *pb = s->pb; VSContext *vs = s->priv_data; + VSScriptGetAPIFunc get_vssapi; int64_t sz = avio_size(pb); char *buf = NULL; char dummy; @@ -178,7 +232,14 @@ static av_cold int read_header_vs(AVFormatContext *s) struct VSState *vss_state; int err = 0; - if (!(vs->vssapi = getVSScriptAPI(VSSCRIPT_API_VERSION))) { + if (!(vs->vslibrary = vs_load_library(&get_vssapi))) { + av_log(s, AV_LOG_ERROR, "Could not open " VSSCRIPT_LIB ". " + "Check VapourSynth installation.\n"); + err = AVERROR_EXTERNAL; + goto done; + } + + if (!(vs->vssapi = get_vssapi(VSSCRIPT_API_VERSION))) { av_log(s, AV_LOG_ERROR, "Failed to initialize VSScript (possibly PYTHONPATH not set).\n"); err = AVERROR_EXTERNAL; goto done; -- 2.34.1 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 2/2] libavformat/vapoursynth: Update to API version 4, load library at runtime 2024-07-29 3:46 ` Stefan Oltmanns via ffmpeg-devel @ 2024-07-30 14:12 ` Ramiro Polla 2024-08-11 10:21 ` Stefan Oltmanns via ffmpeg-devel 0 siblings, 1 reply; 8+ messages in thread From: Ramiro Polla @ 2024-07-30 14:12 UTC (permalink / raw) To: FFmpeg development discussions and patches On Mon, Jul 29, 2024 at 5:56 AM Stefan Oltmanns via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> wrote: > Am 28.07.24 um 15:15 schrieb Ramiro Polla: > > I think calling win32_dlopen() with a full path will be problematic for > > systems without KB2533623. win32_dlopen() might need to be fixed in a > > separate patch. > > Yes, win32_dlopen would need to check if a full path is already given > and if yes skip all the stuff to determine it's own and system32 path, > but instead just use the given parameter directly. To check if it's a > full path it should be enough to check if it either starts with "\??\" > (NT-style path) or if the second character is ":" (win32 style path). > > But is this really is needed for an operating system that reached > support end over 4 years ago and does not have a security patch applied > released over 13 years ago? > I don't know what ffmpeg's exact policy is in this case, just asking. Makes sense. I sent a patchset to clean this, but I haven't been able to test on a real Windows system. I'll test the vapoursynth patches later on Linux. Ramiro _______________________________________________ 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". ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 2/2] libavformat/vapoursynth: Update to API version 4, load library at runtime 2024-07-30 14:12 ` Ramiro Polla @ 2024-08-11 10:21 ` Stefan Oltmanns via ffmpeg-devel 0 siblings, 0 replies; 8+ messages in thread From: Stefan Oltmanns via ffmpeg-devel @ 2024-08-11 10:21 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Stefan Oltmanns Am 30.07.24 um 16:12 schrieb Ramiro Polla: > On Mon, Jul 29, 2024 at 5:56 AM Stefan Oltmanns via ffmpeg-devel > <ffmpeg-devel@ffmpeg.org> wrote: >> Am 28.07.24 um 15:15 schrieb Ramiro Polla: >>> I think calling win32_dlopen() with a full path will be problematic for >>> systems without KB2533623. win32_dlopen() might need to be fixed in a >>> separate patch. >> >> Yes, win32_dlopen would need to check if a full path is already given >> and if yes skip all the stuff to determine it's own and system32 path, >> but instead just use the given parameter directly. To check if it's a >> full path it should be enough to check if it either starts with "\??\" >> (NT-style path) or if the second character is ":" (win32 style path). >> >> But is this really is needed for an operating system that reached >> support end over 4 years ago and does not have a security patch applied >> released over 13 years ago? >> I don't know what ffmpeg's exact policy is in this case, just asking. > > Makes sense. I sent a patchset to clean this, but I haven't been able > to test on a real Windows system. > > I'll test the vapoursynth patches later on Linux. > Any progress on this? Anything I can do? Best regards Stefan _______________________________________________ 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". ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3 1/2] libavformat/vapoursynth: Update to API version 4, load library at runtime 2024-07-23 14:51 [FFmpeg-devel] [PATCH v3 1/2] libavformat/vapoursynth: Update to API version 4, load library at runtime Stefan Oltmanns via ffmpeg-devel 2024-07-23 14:59 ` [FFmpeg-devel] [PATCH v3 2/2] " Stefan Oltmanns via ffmpeg-devel @ 2024-07-28 13:09 ` Ramiro Polla 2024-07-29 3:31 ` [FFmpeg-devel] [PATCH v4 " Stefan Oltmanns via ffmpeg-devel 1 sibling, 1 reply; 8+ messages in thread From: Ramiro Polla @ 2024-07-28 13:09 UTC (permalink / raw) To: ffmpeg-devel On 2024-07-23 16:51, Stefan Oltmanns via ffmpeg-devel wrote: > 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. > From 164a440ffbb5951ca38bfff56e7b62bd677d1f52 Mon Sep 17 00:00:00 2001 > From: Stefan Oltmanns <stefan-oltmanns@gmx.net> > 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 <stefan-oltmanns@gmx.net> > --- > 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 <limits.h> > > -#include <VapourSynth.h> > -#include <VSScript.h> > +#include <VSScript4.h> > > #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)); Could you change this to have a single call go av_log()? Possibly using a %s with a string for the unknown format. Same thing for the other av_log() above. [...] Also could you give us a very minimal test script to test this? Regards, Ramiro _______________________________________________ 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". ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH v4 1/2] libavformat/vapoursynth: Update to API version 4, load library at runtime 2024-07-28 13:09 ` [FFmpeg-devel] [PATCH v3 1/2] " Ramiro Polla @ 2024-07-29 3:31 ` Stefan Oltmanns via ffmpeg-devel 0 siblings, 0 replies; 8+ messages in thread From: Stefan Oltmanns via ffmpeg-devel @ 2024-07-29 3:31 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Stefan Oltmanns [-- Attachment #1: Type: text/plain, Size: 1846 bytes --] Am 28.07.24 um 15:09 schrieb Ramiro Polla: >> 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)); > > Could you change this to have a single call go av_log()? Possibly using > a %s with a string for the unknown format. Same thing for the other > av_log() above. > > [...] It now prints "(unknown)" for a video format that VapourSynth cannot resolve. "(unknown)" is also printed at other places in ffmpeg in similar cases, so it's consistent. > > Also could you give us a very minimal test script to test this? I have attached a minimal test script, it will generate 10 frames each black, red, green, blue in 640x480, RGB24 Best regards Stefan [-- Attachment #2: 0001-avformat-vapoursynth-Update-to-API-version-4.patch --] [-- Type: text/x-patch, Size: 8768 bytes --] From 2279d2e225c665cab68d26652e1cca4fdf04faaa Mon Sep 17 00:00:00 2001 From: Stefan Oltmanns <stefan-oltmanns@gmx.net> Date: Mon, 29 Jul 2024 05:08:57 +0200 Subject: [PATCH 1/2] avformat/vapoursynth: Update to API version 4 Signed-off-by: Stefan Oltmanns <stefan-oltmanns@gmx.net> --- configure | 2 +- libavformat/vapoursynth.c | 77 ++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 39 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..26c9986138 100644 --- a/libavformat/vapoursynth.c +++ b/libavformat/vapoursynth.c @@ -25,8 +25,7 @@ #include <limits.h> -#include <VapourSynth.h> -#include <VSScript.h> +#include <VSScript4.h> #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,19 +282,18 @@ 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); + av_log(s, AV_LOG_ERROR, "Unsupported VS pixel format %s\n", + vs->vsapi->getVideoFormatName(&info->format, vsfmt) ? vsfmt : "(unknown)"); err = AVERROR_EXTERNAL; goto done; } - av_log(s, AV_LOG_VERBOSE, "VS format %s -> pixfmt %s\n", info->format->name, + av_log(s, AV_LOG_VERBOSE, "VS format %s -> pixfmt %s\n", + vs->vsapi->getVideoFormatName(&info->format, vsfmt) ? vsfmt : "(unknown)", av_get_pix_fmt_name(st->codecpar->format)); - if (info->format->colorFamily == cmYCoCg) - st->codecpar->color_space = AVCOL_SPC_YCGCO; - done: av_free(buf); return err; @@ -311,13 +312,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 +340,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 +382,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 +411,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 [-- Attachment #3: test.vpy --] [-- Type: text/plain, Size: 360 bytes --] import vapoursynth as vs core = vs.core a = core.std.BlankClip(width=640,height=480,length=10) b = core.std.BlankClip(width=640,height=480,length=10,color=[255, 0, 0]) c = core.std.BlankClip(width=640,height=480,length=10,color=[ 0, 255, 0]) d = core.std.BlankClip(width=640,height=480,length=10,color=[ 0, 0, 255]) r = a + b + c + d r.set_output(0) [-- Attachment #4: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-08-11 10:21 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-07-23 14:51 [FFmpeg-devel] [PATCH v3 1/2] libavformat/vapoursynth: Update to API version 4, load library at runtime Stefan Oltmanns via ffmpeg-devel 2024-07-23 14:59 ` [FFmpeg-devel] [PATCH v3 2/2] " Stefan Oltmanns via ffmpeg-devel 2024-07-28 13:15 ` Ramiro Polla 2024-07-29 3:46 ` Stefan Oltmanns via ffmpeg-devel 2024-07-30 14:12 ` Ramiro Polla 2024-08-11 10:21 ` Stefan Oltmanns via ffmpeg-devel 2024-07-28 13:09 ` [FFmpeg-devel] [PATCH v3 1/2] " Ramiro Polla 2024-07-29 3:31 ` [FFmpeg-devel] [PATCH v4 " Stefan Oltmanns via ffmpeg-devel
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git