2#include <Gfx/Graph/decoders/ColorSpace.hpp>
3#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
6#include <libavformat/avformat.h>
24 static const constexpr auto frag = R
"_(#version 450
26)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
28layout(binding=3) uniform sampler2D u_tex;
30layout(location = 0) in vec2 v_texcoord;
31layout(location = 0) out vec4 fragColor;
35vec4 processTexture(vec4 tex) {
36 vec4 processed = convert_to_rgb(tex);
43 // Y0 U Y1 V packed as RGBA16, one texel = 2 pixels
44 // Input texture is half the width of the output
45 float colIndex = floor(v_texcoord.x * mat.texSz.x);
46 float oddCol = mod(colIndex, 2.0);
48 // Offset by half an input pixel to sample the correct texel center
49 vec2 dxInput = 0.5 * vec2(1.0 / mat.texSz.x, 0.0);
51 float oddY = texture(u_tex, v_texcoord - dxInput).z;
52 float evenY = texture(u_tex, v_texcoord + dxInput).x;
53 float y = mix(evenY, oddY, oddCol);
55 vec2 uv = texture(u_tex, v_texcoord).yw;
57 fragColor = processTexture(vec4(y, uv.x, uv.y, 1.));
69 auto& rhi = *r.
state.rhi;
70 const auto w = decoder.width, h = decoder.height;
74 = rhi.newTexture(QRhiTexture::RGBA16F, {w / 2, h}, 1, QRhiTexture::Flag{});
77 auto sampler = rhi.newSampler(
78 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
79 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
81 samplers.push_back({sampler, tex});
85 r.
state, vertexShader(),
86 QString(frag).arg(
"").arg(colorMatrix(decoder)));
89 void exec(
RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame)
override
91 const auto w = decoder.width, h = decoder.height;
92 auto pixels = frame.data[0];
93 auto stride = frame.linesize[0];
96 QRhiTextureUploadEntry entry{
98 res.uploadTexture(samplers[0].texture, {entry});
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 Y210 packed 4:2:2 10-bit videos.
Definition Y210.hpp:23
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition Y210.hpp:89
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition Y210.hpp:67