StormByte C++ Library: Multimedia module 0.0.9999
StormByte-Multimedia is a StormByte library module for parsing configuration files
Loading...
Searching...
No Matches
encoder.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/buffer/fifo.hxx>
42#include <StormByte/logger/log.hxx>
50
51#include <cstddef>
52#include <cstdint>
53#include <map>
54#include <memory>
55#include <optional>
56#include <string>
57#include <vector>
58
66 class Encoder;
67 class Packet;
68}
69
71 class Encode;
72}
73
81 class Encoder;
82 class Frame;
83 class Muxer;
84
104 friend class Backend::Pipeline::Encoder;
105 friend class Backend::Pipeline::Detail::Worker::Encode;
106 friend class Muxer;
107
108 public:
113
120 Encoder(std::shared_ptr<StormByte::Logger::Log> log,
121 int output_index, const Codec& codec) noexcept;
122
127 Encoder(const Encoder& other) = delete;
128
133 Encoder(Encoder&& other) noexcept = delete;
134
138 ~Encoder() noexcept override;
139
145 Encoder& operator=(const Encoder& other) = delete;
146
152 Encoder& operator=(Encoder&& other) noexcept = delete;
153
157
162
167 explicit operator bool() const noexcept;
168
173 inline int Index() const noexcept {
174 return m_index;
175 }
176
181 std::size_t InputCeiling() const noexcept override;
182
187 inline const Codec& Destination() const noexcept {
188 return *m_codec;
189 }
190
195 bool Opened() const noexcept;
196
201 std::optional<int> AudioChannels() const noexcept;
202
207 std::optional<int> AudioSampleRate() const noexcept;
208
213 std::optional<int> AudioFrameSize() const noexcept;
214
219 std::optional<int> AudioSampleFormat() const noexcept;
220
224
229
234 inline const std::string& EncoderTag() const noexcept {
235 return m_encoderTag;
236 }
237
241
246
251 inline const std::optional<std::string>& Implementation() const noexcept {
252 return m_implementation;
253 }
254
259 void Implementation(std::string name) noexcept;
260
265 inline const Features& Require() const noexcept {
266 return m_require;
267 }
268
273 inline void Require(Features features) noexcept {
274 m_require = features;
275 }
276
281 inline const Features& Capabilities() const noexcept {
282 return m_capabilities;
283 }
284
288
293
298 inline void CRF(int value) noexcept {
299 m_crf = value;
300 }
301
306 inline const std::optional<int>& CRF() const noexcept {
307 return m_crf;
308 }
309
314 inline void BitRate(std::int64_t bits_per_second) noexcept {
315 m_bitRate = bits_per_second;
316 }
317
322 inline const std::optional<std::int64_t>& BitRate() const noexcept {
323 return m_bitRate;
324 }
325
330 inline void MaxBitRate(std::int64_t bits_per_second) noexcept {
331 m_maxBitRate = bits_per_second;
332 }
333
338 inline const std::optional<std::int64_t>& MaxBitRate() const noexcept {
339 return m_maxBitRate;
340 }
341
346 void Preset(std::string name) noexcept;
347
352 inline const std::optional<std::string>& Preset() const noexcept {
353 return m_preset;
354 }
355
360 void Tune(std::string name) noexcept;
361
366 inline const std::optional<std::string>& Tune() const noexcept {
367 return m_tune;
368 }
369
373
378
383 inline const std::map<std::string, std::string>& FineTune() const noexcept {
384 return m_fineTune;
385 }
386
391 inline void FineTune(std::map<std::string, std::string> options) noexcept {
392 m_fineTune = std::move(options);
393 }
394
398
399 private:
404
405 using Step::Log;
406
412 std::string Label() const noexcept override;
413
417
437 Packet::PointerType Wrap(
438 enum StormByte::Multimedia::Type type, int index,
439 StormByte::Buffer::FIFO payload,
440 std::optional<Property::Duration> pts,
441 std::optional<Property::Duration> dts,
442 std::optional<Property::Duration> duration,
443 bool keyFrame,
444 std::vector<SideData> attachments,
445 std::unique_ptr<Backend::Pipeline::Packet> backend) noexcept;
446
452 bool MuxBindStream(void* avStream) noexcept;
453
459 void* FrameHandle(Frame& frame) noexcept;
460
466 const void* FrameHandle(const Frame& frame) noexcept;
467
472 void Emit(Packet::PointerType packet) noexcept;
473
474 int m_index;
475 const Codec* m_codec;
476 std::string m_encoderTag;
477 std::optional<std::string> m_implementation;
478 Features m_require;
479 Features m_capabilities;
480 std::optional<int> m_crf;
481 std::optional<std::int64_t> m_bitRate;
482 std::optional<std::int64_t> m_maxBitRate;
483 std::optional<std::string> m_preset;
484 std::optional<std::string> m_tune;
485 std::map<std::string, std::string> m_fineTune;
486 std::unique_ptr<Backend::Pipeline::Encoder> m_backend;
487 std::optional<std::uint64_t> m_serial;
488 std::uint64_t m_part;
489 Join m_join{*this};
490 };
491}
Immutable codec identity owned by Registry.
Definition codec.hxx:58
Bitmask of Feature flags.
Definition features.hxx:56
Encodes frames of one output track into packets.
Definition encoder.hxx:103
void Tune(std::string name) noexcept
Content tune.
Encoder(Encoder &&other) noexcept=delete
Move constructor.
void Preset(std::string name) noexcept
Encoder preset.
const std::optional< int > & CRF() const noexcept
CRF/CQ, if set.
Definition encoder.hxx:306
void FineTune(std::map< std::string, std::string > options) noexcept
Replaces the vendor dict (before open).
Definition encoder.hxx:391
Encoder(const Encoder &other)=delete
Copy constructor.
friend class Backend::Pipeline::Encoder
Definition encoder.hxx:104
std::optional< int > AudioSampleRate() const noexcept
Encoder sample rate after Open(), audio only.
Encoder(std::shared_ptr< StormByte::Logger::Log > log, int output_index, const Codec &codec) noexcept
Encoder for output track output_index and destination codec.
const Features & Capabilities() const noexcept
Features of the row selected at open.
Definition encoder.hxx:281
const std::optional< std::string > & Tune() const noexcept
Content tune, if set.
Definition encoder.hxx:366
std::optional< int > AudioChannels() const noexcept
Encoder channel count after Open(), audio only.
const std::optional< std::string > & Preset() const noexcept
Preset, if set.
Definition encoder.hxx:352
void CRF(int value) noexcept
Constant quality (CRF/CQ).
Definition encoder.hxx:298
const std::map< std::string, std::string > & FineTune() const noexcept
Vendor leftovers.
Definition encoder.hxx:383
const std::optional< std::int64_t > & MaxBitRate() const noexcept
VBV ceiling, if set.
Definition encoder.hxx:338
const std::string & EncoderTag() const noexcept
Writing-application tag stamped on every encoded stream.
Definition encoder.hxx:234
~Encoder() noexcept override
Destructor.
bool Opened() const noexcept
Whether the backend finished Open().
std::optional< int > AudioFrameSize() const noexcept
Encoder frame_size after Open(), audio only.
std::optional< int > AudioSampleFormat() const noexcept
Encoder sample format after Open(), audio only.
void Implementation(std::string name) noexcept
Pins an FFmpeg encoder name.
const Features & Require() const noexcept
Extra features the caller demands besides Frame HDR.
Definition encoder.hxx:265
const std::optional< std::string > & Implementation() const noexcept
Pinned FFmpeg encoder name, if any.
Definition encoder.hxx:251
void Require(Features features) noexcept
Replaces the extra feature mask (before open).
Definition encoder.hxx:273
void BitRate(std::int64_t bits_per_second) noexcept
Target bitrate in bits per second.
Definition encoder.hxx:314
void MaxBitRate(std::int64_t bits_per_second) noexcept
VBV ceiling in bits per second.
Definition encoder.hxx:330
int Index() const noexcept
Mux destination order key.
Definition encoder.hxx:173
friend class Muxer
Definition encoder.hxx:106
const Codec & Destination() const noexcept
Destination codec.
Definition encoder.hxx:187
const std::optional< std::int64_t > & BitRate() const noexcept
Target bitrate, if set.
Definition encoder.hxx:322
std::size_t InputCeiling() const noexcept override
Ceiling of the encoder input hopper.
One decoded access unit.
Definition frame.hxx:81
Writes interleaved packets to a destination container.
Definition muxer.hxx:155
One compressed access unit.
Definition packet.hxx:80
One side-data blob attached to a Frame or Packet.
Definition side_data.hxx:90
Step(const Step &other)=delete
virtual void Log(StormByte::Logger::Level level, std::string_view message) noexcept
Writes one log line on the scoped module logger.
Hopper and Sink live in StormByte-Buffer.
Multimedia-owned pipeline stages and unit holders.
Definition AVFormatContext.hxx:52
Definition AVFormatContext.hxx:52
Demux / decode / filter / encode / mux types.
@ Encoder
Encoder
Definition typedefs.hxx:112
@ Packet
StormByte::Multimedia::Pipeline::Packet
Definition typedefs.hxx:79
Media property value 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