2 #include <Gfx/Graph/decoders/ColorSpace.hpp>
3 #include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
6 #include <libavformat/avformat.h>
20 static const constexpr
auto frag = R
"_(#version 450
22 )_" SCORE_GFX_VIDEO_UNIFORMS R"_(
24 layout(binding=3) uniform sampler2D y_tex;
25 layout(binding=4) uniform sampler2D u_tex;
26 layout(binding=5) uniform sampler2D v_tex;
28 layout(location = 0) in vec2 v_texcoord;
29 layout(location = 0) out vec4 fragColor;
33 vec4 processTexture(vec4 tex) {
34 vec4 processed = convert_to_rgb(tex);
41 float y = texture(y_tex, v_texcoord).r;
42 float u = texture(u_tex, v_texcoord).r;
43 float v = texture(v_tex, v_texcoord).r;
45 fragColor = processTexture(vec4(y,u,v, 1.));
57 auto& rhi = *r.
state.rhi;
58 const auto w = decoder.width, h = decoder.height;
59 const auto fmt = QRhiTexture::R8;
63 auto tex = rhi.newTexture(fmt, {w, h}, 1, QRhiTexture::Flag{});
66 auto sampler = rhi.newSampler(
67 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
68 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
70 samplers.push_back({sampler, tex});
75 auto tex = rhi.newTexture(fmt, {w / 2, h / 2}, 1, QRhiTexture::Flag{});
78 auto sampler = rhi.newSampler(
79 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
80 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
82 samplers.push_back({sampler, tex});
87 auto tex = rhi.newTexture(fmt, {w / 2, h / 2}, 1, QRhiTexture::Flag{});
90 auto sampler = rhi.newSampler(
91 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
92 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
94 samplers.push_back({sampler, tex});
98 r.
state, vertexShader(), QString(frag).arg(
"").arg(colorMatrix(decoder)));
103 setYPixels(res, frame.data[0], frame.linesize[0]);
104 setUPixels(res, frame.data[1], frame.linesize[1]);
105 setVPixels(res, frame.data[2], frame.linesize[2]);
109 setYPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
111 const auto w = decoder.width, h = decoder.height;
112 auto y_tex = samplers[0].texture;
115 QRhiTextureUploadDescription desc{entry};
117 res.uploadTexture(y_tex, desc);
121 setUPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
123 const auto w = decoder.width / 2, h = decoder.height / 2;
124 auto u_tex = samplers[1].texture;
127 QRhiTextureUploadDescription desc{entry};
129 res.uploadTexture(u_tex, desc);
133 setVPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
135 const auto w = decoder.width / 2, h = decoder.height / 2;
136 auto v_tex = samplers[2].texture;
139 QRhiTextureUploadDescription desc{entry};
140 res.uploadTexture(v_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:89
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:342
Decodes YUV420 videos.
Definition: YUV420.hpp:19
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition: YUV420.hpp:55
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition: YUV420.hpp:101