Mpv: inserting a GPU-shader into mpv's encoding pipeline

Created on 28 Nov 2019  路  9Comments  路  Source: mpv-player/mpv

mpv version and platform

mpv 0.30.0-UNKNOWN Copyright 漏 2000-2019 mpv/MPlayer/mplayer2 projects
built on Fri Nov 22 19:58:21 +0630 2019
ffmpeg library versions:
libavutil 56.36.100
libavcodec 58.62.100
libavformat 58.35.100
libswscale 5.6.100
libavfilter 7.66.100
libswresample 3.6.100
ffmpeg version: 4.2.git

Reproduction steps

mpv input.360p.mkv --glsl-shaders=~~/prescalers/FSRCNNX_x16.glsl --vf="scale=w=1280:h=720" --oac=libopus --oacopts=b=32000 --ovc=libx264 --ovcopts="preset=faster:crf=21" --o=output.720p.mkv

Expected behavior

Here the FSRCNNx shader (or any other shader for that matter) is in ~~/prescalers. input.360p.mkv is a 360p input. output.720p.mkv is a 720p output.
My GPU is too slow to use the FSCRNNx shader. So I'm trying to see if it is possible to somehow use mpv's encoding functionality to add the shader to the filter-pipeline. If that can be done, then I can upscale the input video "offline", and watch the upscaled version later

Actual behavior

The above command was an attempt to do this. But the output video doesn't seem to have used the shader at all. Is this even possible? If so, could you please give a sample command

Most helpful comment

@Akemi @wm4 Thanks for this. Works perfectly now with the FSRCNNX.glsl shader.

For anyone who comes to this page by searching, a sample command using this filter would be

mpv input.mkv --vf=gpu="w=1280:h=720" --glsl-shaders=~~/prescalers/FSRCNNX.glsl --oac=libopus --oacopts=b=32000 --ovc=libx264 --ovcopts="preset=faster:crf=21" --o=test.mkv

Here --vf=gpu="w=1280:h=720" enables using the gpu in the encoding pipeline, and the --glsl-shader inserts the FSRCNNx8 shader into the pipeline

All 9 comments

No, this is currently not possible. The user shader arguments are used only with --vo=gpu (encoding implicitly uses vo=lavc).

Although I guess it wouldn't be hard to hook it up as filter by changing the code.

@wm4 thanks.
I had a separate idea to achieve the same thing. But that is not directly related to mpv's encoding functionality, so I've opened a separate issue for it at https://github.com/mpv-player/mpv/issues/7194

@wm4 Would this allow for hdr-compute-peak to be used for encoding as well? Is that not a built-in shader?
EDIT: If so, that is a feature I've wanted for a while.

https://github.com/mpv-player/mpv/commit/90df6c79c9400d3f1c711ef5696324908a5126ce seems to be limited to X11 though? What about systems without it e.g windows.

Actually it works with any system that has EGL that somehow supports rendering with a "default" display. My ifdef is pretty dangerous because it doesn't match with the one in the build scripts, and could make a build fail.

But yeah, this won't work on Windows this way.

Should I open a separate issue for Windows?
Also, do you even have any plans to further expand vf_gpu to work with other systems?

No I don't.

@Akemi @wm4 Thanks for this. Works perfectly now with the FSRCNNX.glsl shader.

For anyone who comes to this page by searching, a sample command using this filter would be

mpv input.mkv --vf=gpu="w=1280:h=720" --glsl-shaders=~~/prescalers/FSRCNNX.glsl --oac=libopus --oacopts=b=32000 --ovc=libx264 --ovcopts="preset=faster:crf=21" --o=test.mkv

Here --vf=gpu="w=1280:h=720" enables using the gpu in the encoding pipeline, and the --glsl-shader inserts the FSRCNNx8 shader into the pipeline

Was this page helpful?
0 / 5 - 0 ratings