Skip to content
/ mpv Public
forked from mpv-player/mpv

Commit

Permalink
vf_vapoursynth: add parameter to allow passing arbitrary data to script
Browse files Browse the repository at this point in the history
Currently the vapoursynth video filter does not accept any argument for passing arbitrary user data. This limits what the VS script can do.

Ideally, the vapoursynth filter has an user-data parameter that contains string value. mpv passes that value to the VS script just like container_fps and others. Once the VS script gets the data, it can do all sorts of data extraction and transformation.

Another benefit is that instead of mpv always have to catch up to user needs for this filter, with this users can just pass whatever needed themselves, thus becomes more future-proof.

Fixes mpv-player#14214
  • Loading branch information
CrendKing committed Jun 7, 2024
1 parent 112fa54 commit 9833f0f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion DOCS/man/vf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ Available mpv-only filters are:
subtitle colors and video under the influence of the video equalizer
settings.

``vapoursynth=file:buffered-frames:concurrent-frames``
``vapoursynth=file:buffered-frames:concurrent-frames:user-data``
Loads a VapourSynth filter script. This is intended for streamed
processing: mpv actually provides a source filter, instead of using a
native VapourSynth video source. The mpv source will answer frame
Expand Down Expand Up @@ -559,6 +559,10 @@ Available mpv-only filters are:
By default, this uses the special value ``auto``, which sets the option
to the number of detected logical CPU cores.

``user-data``
Optional arbitrary string that is passed to the script. Default to empty
string if not set.

The following ``.vpy`` script variables are defined by mpv:

``video_in``
Expand Down Expand Up @@ -589,6 +593,10 @@ Available mpv-only filters are:
to the height. These values can be 0. Note that this will not respond to
monitor changes and may not work on all platforms.

``user_data``
User data passed from the filter. This variable always exists, and defaults
to empty string.

``vavpp``
VA-API video post processing. Requires the system to support VA-API,
i.e. Linux/BSD only. Works with ``--vo=vaapi`` and ``--vo=gpu`` only.
Expand Down
1 change: 1 addition & 0 deletions ci/build-win32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ meson setup build `
-Ddrm=disabled `
-Dlibarchive=disabled `
-Drubberband=disabled `
-Dvapoursynth=disabled `
-Dwayland=disabled `
-Dx11=disabled
ninja -C build mpv.exe mpv.com libmpv.a
Expand Down
4 changes: 4 additions & 0 deletions video/filter/vf_vapoursynth.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct vapoursynth_opts {
char *file;
int maxbuffer;
int maxrequests;
char *user_data;

const struct script_driver *drv;
};
Expand Down Expand Up @@ -699,6 +700,8 @@ static int reinit_vs(struct priv *p, struct mp_image *input)
p->vsapi->propSetFloat(vars, "container_fps", container_fps, 0);
p->vsapi->propSetFloat(vars, "display_fps", display_fps, 0);
p->vsapi->propSetIntArray(vars, "display_res", display_res, 2);
p->vsapi->propSetData(vars, "user_data", p->opts->user_data,
strlen(p->opts->user_data), 0);

if (p->drv->load(p, vars) < 0)
goto error;
Expand Down Expand Up @@ -830,6 +833,7 @@ static const m_option_t vf_opts_fields[] = {
OPTDEF_INT(4)},
{"concurrent-frames", OPT_CHOICE(maxrequests, {"auto", -1}),
M_RANGE(1, 99), OPTDEF_INT(-1)},
{"user-data", OPT_STRING(user_data), OPTDEF_STR("")},
{0}
};

Expand Down

0 comments on commit 9833f0f

Please sign in to comment.