StormByte C++ Library: Multimedia module 0.0.9999
StormByte-Multimedia is a StormByte library module for parsing configuration files
Loading...
Searching...
No Matches
degrain.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Multimedia.
5 *
6 * StormByte-Multimedia original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Multimedia source in this
20 * file. Third-party components — including FFmpeg and embedded trained data —
21 * remain under their own licenses and are not covered by the commercial grant.
22 *
23 * Neither license grants any patent rights. Any patent licenses required
24 * to use this software or third-party components must be obtained separately
25 * from the patent holders.
26 *
27 * StormByte-Multimedia is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 *
32 * You should have received a copy of the GNU Lesser General Public License
33 * version 3 along with StormByte-Multimedia. If not, see
34 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
35 *
36 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
37 */
38
39#pragma once
40
41#include <StormByte/logger/log.hxx>
46
47#include <cstdint>
48#include <deque>
49#include <memory>
50#include <optional>
51#include <string>
52#include <vector>
53
59
144 public:
151 Degrain(std::shared_ptr<StormByte::Logger::Log> log,
152 std::optional<double> sigmaCap = {}) noexcept;
153
154 Degrain(const Degrain& other) = delete;
155 Degrain(Degrain&& other) noexcept = delete;
156 ~Degrain() noexcept override = default;
157 Degrain& operator=(const Degrain& other) = delete;
158 Degrain& operator=(Degrain&& other) noexcept = delete;
159
164 enum StormByte::Multimedia::Type Media() const noexcept override;
165
169 void Clean() noexcept override;
170
174 void Setup() noexcept override;
175
180 void Measure(const Pipeline::Frame& frame) noexcept override;
181
186 void Process(const Pipeline::Frame& frame) noexcept override;
187
191 void Eof() noexcept override;
192
196 class Filter::Report Report() const noexcept override;
197
198 private:
207 struct Slot {
208 std::unique_ptr<StormByte::Multimedia::FFmpeg::AVFrame> pic;
209 int64_t pts = 0;
210 double mean = 0.0;
211 };
212
220 struct Row {
221 int64_t pts = 0;
222 double mean = 0.0;
223 double p10 = 0.0;
224 double p90 = 0.0;
225 double mid = 0.0;
226 double dark = 0.0;
227 double fLive = 0.0;
228 double fSkin = 0.0;
229 double fFlat = 0.0;
230 double mot = 0.0;
231 double raw = 0.0;
232 bool flash = false;
233 };
234
242 struct Segment {
243 int64_t firstPts = 0;
244 int64_t lastPts = 0;
245 double sigma = 0.0;
246 bool skip = true;
247 };
248
253 void PushFrame(const StormByte::Multimedia::FFmpeg::AVFrame& src) noexcept;
254
259 void ScoreCenter(std::size_t idx) noexcept;
260
264 void FlushRing() noexcept;
265
272 void Decide() noexcept;
273
277 const Segment* Find(int64_t pts) const noexcept;
278
283 std::string Chain() const noexcept;
284
285 std::optional<double> m_capIn;
286 std::deque<Slot> m_ring;
287 std::vector<Row> m_row;
288 std::vector<Segment> m_seg;
289 unsigned m_frames;
290 bool m_voted;
291 double m_sigma;
292 double m_sigmaMin;
293 double m_sigmaP50;
294 double m_sigmaMax;
295 int m_ran;
296 int m_skipped;
297 std::unique_ptr<StormByte::Multimedia::FFmpeg::AVFilterGraph> m_graph;
298 };
299}
RAII owner of a libav AVFrame.
Definition AVFrame.hxx:98
Process that measures the origin before it rewrites.
Definition ffmpeg.hxx:811
void Clean() noexcept override
Drops ring, rows, segments and the avfilter graph.
void Setup() noexcept override
Resets the graph before a pass starts.
class Filter::Report Report() const noexcept override
Stretch map after Decide: status, frames, ran/skip, sigma.
void Measure(const Pipeline::Frame &frame) noexcept override
First pass: push the picture into the ring and score.
void Process(const Pipeline::Frame &frame) noexcept override
Second pass: fftdnoiz at the voted sigma, or no-op.
Degrain(std::shared_ptr< StormByte::Logger::Log > log, std::optional< double > sigmaCap={}) noexcept
Scene-aware grain reduce.
enum StormByte::Multimedia::Type Media() const noexcept override
Media this filter handles.
void Eof() noexcept override
Measure: flush ring and Decide.
One decoded access unit.
Definition frame.hxx:81
Frame and packet steps attached to a job or a raw pipeline.
Private RAII wrappers over libav*.
Video leaves (Process and Analytics).
Definition frames.hxx:59
Demux / decode / filter / encode / mux types.
Public multimedia types: codecs, containers, streams and files.
Type
Kind of media stream or codec.
Definition type.hxx:55
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47