2 #include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
4 #include <libavformat/avformat.h>
17 static const constexpr
auto nv12_filter_prologue = R
"_(#version 450
19 )_" SCORE_GFX_VIDEO_UNIFORMS R"_(
21 layout(binding=3) uniform sampler2D y_tex;
22 layout(binding=4) uniform sampler2D uv_tex;
24 layout(location = 0) in vec2 v_texcoord;
25 layout(location = 0) out vec4 fragColor;
27 const vec3 R_cf = vec3(1.164383, 0.000000, 1.596027);
28 const vec3 G_cf = vec3(1.164383, -0.391762, -0.812968);
29 const vec3 B_cf = vec3(1.164383, 2.017232, 0.000000);
30 const vec3 offset = vec3(-0.0625, -0.5, -0.5);
34 float y = texture(y_tex, v_texcoord).r;
35 float u = texture(uv_tex, v_texcoord).r;
36 float v = texture(uv_tex, v_texcoord).a;
40 static const constexpr
auto nv12_filter_epilogue = R
"_(
43 fragColor = vec4(0.0, 0.0, 0.0, 1.0);
44 fragColor.r = dot(yuv, R_cf);
45 fragColor.g = dot(yuv, G_cf);
46 fragColor.b = dot(yuv, B_cf);
60 auto& rhi = *r.
state.rhi;
61 const auto w = decoder.width, h = decoder.height;
65 auto tex = rhi.newTexture(QRhiTexture::R8, {w, h}, 1, QRhiTexture::Flag{});
68 auto sampler = rhi.newSampler(
69 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
70 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
72 samplers.push_back({sampler, tex});
78 = rhi.newTexture(QRhiTexture::RGBA8, {w / 4, h / 2}, 1, QRhiTexture::Flag{});
81 auto sampler = rhi.newSampler(
82 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
83 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
85 samplers.push_back({sampler, tex});
88 QString frag = nv12_filter_prologue;
90 frag +=
" vec3 yuv = vec3(y, v, u);\n";
92 frag +=
" vec3 yuv = vec3(y, u, v);\n";
93 frag += nv12_filter_epilogue;
98 void exec(
RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame)
override
100 setYPixels(res, frame.data[0], frame.linesize[0]);
101 setUVPixels(res, frame.data[1], frame.linesize[1]);
105 setYPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
107 const auto w = decoder.width, h = decoder.height;
108 auto y_tex = samplers[0].texture;
111 QRhiTextureUploadDescription desc{entry};
113 res.uploadTexture(y_tex, desc);
117 setUVPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
119 const auto w = decoder.width / 4, h = decoder.height / 2;
120 auto uv_tex = samplers[1].texture;
123 QRhiTextureUploadDescription desc{entry};
125 res.uploadTexture(uv_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 NV12 videos.
Definition: NV12.hpp:16
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition: NV12.hpp:58
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition: NV12.hpp:98