2#include <Gfx/Graph/decoders/ColorSpace.hpp>
3#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
5#include <libavformat/avformat.h>
17 static const constexpr auto frag = R
"_(#version 450
19)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
21layout(binding=3) uniform sampler2D u_tex;
23layout(location = 0) in vec2 v_texcoord;
24layout(location = 0) out vec4 fragColor;
28vec4 processTexture(vec4 tex) {
29 vec4 processed = convert_to_rgb(tex);
35 // YUYV packs Y0 U Y1 V into RGBA as x=Y0 y=U z=Y1 w=V
36 // Input texture is half the width of the output (one RGBA texel = 2 pixels)
37 float colIndex = floor(v_texcoord.x * mat.texSz.x);
38 float oddCol = mod(colIndex, 2.0);
40 // Offset by half an input pixel to sample the correct texel center
41 vec2 dxInput = 0.5 * vec2(1.0 / mat.texSz.x, 0.0);
43 float oddY = texture(u_tex, v_texcoord - dxInput).z;
44 float evenY = texture(u_tex, v_texcoord + dxInput).x;
45 float y = mix(evenY, oddY, oddCol);
47 vec2 uv = texture(u_tex, v_texcoord).yw;
49 fragColor = processTexture(vec4(y, uv.x, uv.y, 1.));
61 auto& rhi = *r.
state.rhi;
63 const auto w = decoder.width, h = decoder.height;
66 auto tex = rhi.newTexture(QRhiTexture::RGBA8, {w / 2, h}, 1, QRhiTexture::Flag{});
69 auto sampler = rhi.newSampler(
70 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
71 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
73 samplers.push_back({sampler, tex});
77 r.
state, vertexShader(), QString(frag).arg(
"").arg(colorMatrix(decoder)));
80 void exec(
RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame)
override
82 setYPixels(res, frame.data[0], frame.linesize[0]);
86 setYPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
88 const auto w = decoder.width, h = decoder.height;
89 auto y_tex = samplers[0].texture;
94 QRhiTextureUploadDescription desc{entry};
95 res.uploadTexture(y_tex, desc);
106 static const constexpr auto frag = R
"_(#version 450
108)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
110layout(binding=3) uniform sampler2D u_tex;
112layout(location = 0) in vec2 v_texcoord;
113layout(location = 0) out vec4 fragColor;
117vec4 processTexture(vec4 tex) {
118 vec4 processed = convert_to_rgb(tex);
124 // UYVY packs U0 Y0 V0 Y1 into RGBA as x=U0 y=Y0 z=V0 w=Y1
125 // Input texture is half the width of the output (one RGBA texel = 2 pixels)
126 float colIndex = floor(v_texcoord.x * mat.texSz.x);
127 float oddCol = mod(colIndex, 2.0);
129 // Offset by half an input pixel to sample the correct texel center
130 vec2 dxInput = 0.5 * vec2(1.0 / mat.texSz.x, 0.0);
132 float oddY = texture(u_tex, v_texcoord - dxInput).w;
133 float evenY = texture(u_tex, v_texcoord + dxInput).y;
134 float y = mix(evenY, oddY, oddCol);
136 vec2 uv = texture(u_tex, v_texcoord).xz;
138 fragColor = processTexture(vec4(y, uv.x, uv.y, 1.));
150 auto& rhi = *r.
state.rhi;
152 const auto w = decoder.width, h = decoder.height;
155 auto tex = rhi.newTexture(QRhiTexture::RGBA8, {w / 2, h}, 1, QRhiTexture::Flag{});
158 auto sampler = rhi.newSampler(
159 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
160 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
162 samplers.push_back({sampler, tex});
166 r.
state, vertexShader(), QString(frag).arg(
"").arg(colorMatrix(decoder)));
171 auto y_tex = samplers[0].texture;
173 auto pixels = frame.data[0];
174 auto stride = frame.linesize[0];
176 QRhiTextureUploadEntry entry{
179 QRhiTextureUploadDescription desc{entry};
180 res.uploadTexture(y_tex, desc);
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:43
static QRhiTextureSubresourceUploadDescription createTextureUpload(uint8_t *pixels, int w, int h, int bytesPerPixel, int stride)
Utility method to create a QRhiTextureSubresourceUploadDescription.
Definition GPUVideoDecoder.cpp:22
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:94
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:394
Decodes UYVY422 video, mostly used for NDI.
Definition YUYV422.hpp:105
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition YUYV422.hpp:169
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition YUYV422.hpp:148
Decodes YUYV422 video.
Definition YUYV422.hpp:16
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition YUYV422.hpp:59
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition YUYV422.hpp:80