StormByte C++ Library: Multimedia module 0.0.9999
StormByte-Multimedia is a StormByte library module for parsing configuration files
Loading...
Searching...
No Matches
AVFrame.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/typedefs.hxx>
48
49#include <cstddef>
50#include <cstdint>
51#include <string_view>
52#include <vector>
53
63 namespace Filter {
64 class FFmpeg;
65 }
66}
67
73 class Frame;
74}
75
81 class AVDecoder;
82 class AVEncoder;
83 class Swr;
84 class Sws;
85
97 friend class AVDecoder;
98 friend class AVEncoder;
99 friend class Swr;
100 friend class Sws;
101 friend class StormByte::Multimedia::Backend::Pipeline::Frame;
103 public:
107 AVFrame() noexcept;
108
113 AVFrame(AVFrame&& other) noexcept = default;
114
118 ~AVFrame() noexcept override;
119
125 AVFrame& operator=(AVFrame&& other) noexcept = default;
126
131 explicit operator bool() const noexcept;
132
137 AVFrame Clone() const noexcept;
138
144 bool Ref(const AVFrame& other) noexcept;
145
151 bool Copy(const AVFrame& other) noexcept;
152
158 bool CopyProps(const AVFrame& other) noexcept;
159
165 bool GetBuffer(int align = 0) noexcept;
166
171 bool MakeWritable() noexcept;
172
177 bool Writable() const noexcept;
178
187 bool AllocVideo(int width, int height, int format, int align = 0) noexcept;
188
197 bool AllocAudio(int nb_samples, int format, const AVChannelLayout& layout, int sample_rate) noexcept;
198
202 void Unref() noexcept;
203
208 int Width() const noexcept;
209
214 void Width(int width) noexcept;
215
220 int Height() const noexcept;
221
226 void Height(int height) noexcept;
227
232 int Format() const noexcept;
233
238 void Format(int format) noexcept;
239
244 bool Hardware() const noexcept;
245
250 static int FormatNone() noexcept;
251
256 static int FormatGray8() noexcept;
257
262 static int FormatRgba() noexcept;
263
270 enum class VideoLayout: std::uint8_t {
271 Unknown,
272 Gray,
273 Yuv420,
274 Yuv422,
275 Yuv444
276 };
277
282 VideoLayout Layout() const noexcept;
283
295 static AVFrame DecodeImage(const std::uint8_t* data, std::size_t size,
296 std::string_view hint = {}) noexcept;
297
302 std::int64_t Pts() const noexcept;
303
308 void Pts(std::int64_t pts) noexcept;
309
314 std::int64_t BestEffortTimestamp() const noexcept;
315
320 void BestEffortTimestamp(std::int64_t ts) noexcept;
321
326 std::int64_t DurationTicks() const noexcept;
327
332 void DurationTicks(std::int64_t duration) noexcept;
333
338 int ColorRange() const noexcept;
339
344 void ColorRange(int range) noexcept;
345
350 int ColorSpace() const noexcept;
351
356 void ColorSpace(int space) noexcept;
357
362 int ColorPrimaries() const noexcept;
363
368 void ColorPrimaries(int primaries) noexcept;
369
374 int ColorTransfer() const noexcept;
375
380 void ColorTransfer(int transfer) noexcept;
381
386 int ChromaLocation() const noexcept;
387
392 void ChromaLocation(int location) noexcept;
393
398 AVRational SampleAspectRatio() const noexcept;
399
404 void SampleAspectRatio(AVRational sar) noexcept;
405
410 int PictType() const noexcept;
411
416 void PictType(int type) noexcept;
417
422 bool KeyFrame() const noexcept;
423
428 void KeyFrame(bool key) noexcept;
429
434 int RepeatPict() const noexcept;
435
440 void RepeatPict(int repeat) noexcept;
441
446 bool Interlaced() const noexcept;
447
453 void Interlaced(bool interlaced, bool top_first) noexcept;
454
459 bool TopFieldFirst() const noexcept;
460
465 int CropLeft() const noexcept;
466
471 int CropRight() const noexcept;
472
477 int CropTop() const noexcept;
478
483 int CropBottom() const noexcept;
484
492 void Crop(int left, int right, int top, int bottom) noexcept;
493
499 bool ApplyCropping(int flags = 0) noexcept;
500
505 int PlaneCount() const noexcept;
506
512 int PlaneWidth(int plane) const noexcept;
513
519 int PlaneHeight(int plane) const noexcept;
520
525 int BitsPerComponent() const noexcept;
526
531 const char* FormatName() const noexcept;
532
538 const uint8_t* Data(int plane) const noexcept;
539
545 uint8_t* Data(int plane) noexcept;
546
552 int Linesize(int plane) const noexcept;
553
558 int NbSamples() const noexcept;
559
564 void NbSamples(int samples) noexcept;
565
570 int SampleRate() const noexcept;
571
576 void SampleRate(int rate) noexcept;
577
582 int Channels() const noexcept;
583
588 AVChannelLayout ChannelLayout() const noexcept;
589
595 bool CopyChannelLayout(const AVChannelLayout& layout) noexcept;
596
601 uint8_t** ExtendedData() noexcept;
602
607 const uint8_t* const* ExtendedData() const noexcept;
608
614 const AVFrameSideData* SideData(int type) const noexcept;
615
621 AVFrameSideData* SideData(int type) noexcept;
622
627 void RemoveSideData(int type) noexcept;
628
633 int SideDataCount() const noexcept;
634
640 const AVFrameSideData* SideDataAt(int index) const noexcept;
641
648 uint8_t* NewSideData(int type, int size) noexcept;
649
654 void CopyPrimaryBuffer(StormByte::Buffer::DataType& out) const noexcept;
655
660 void WriteHdr10(const StormByte::Multimedia::Property::HDR10& hdr10) noexcept;
661
666 void WriteSideData(const std::vector<StormByte::Multimedia::Pipeline::SideData>& attachments) noexcept;
667
676 bool ScaleTo(AVFrame& dst, int dst_w, int dst_h, int flags = 0) const noexcept;
677
682 void Reset(::AVFrame* raw) noexcept;
683
684 private:
689 AVFrame(const AVFrame& other) noexcept;
690
696 AVFrame& operator=(const AVFrame& other) noexcept;
697
701 void Free() noexcept override;
702
703 using AVPointer<::AVFrame>::Get;
704 using AVPointer<::AVFrame>::Detach;
705 };
706
707 extern template class STORMBYTE_MULTIMEDIA_PUBLIC AVPointer<::AVFrame>;
708}
RAII AVChannelLayout (av_channel_layout_copy / uninit).
Definition AVChannelLayout.hxx:65
RAII decoder context with optional BSF pipeline.
Definition AVDecoder.hxx:61
RAII encoder context with optional BSF pipeline.
Definition AVEncoder.hxx:68
RAII owner of a libav AVFrame.
Definition AVFrame.hxx:96
VideoLayout
Planar video family, ignoring bit depth.
Definition AVFrame.hxx:270
AVFrame() noexcept
Allocates an empty frame (av_frame_alloc).
VideoLayout Layout() const noexcept
Planar layout of this frame.
std::int64_t Pts() const noexcept
Presentation timestamp in stream ticks.
Move-only RAII base for FFmpeg C pointers.
Definition AVPointer.hxx:59
RAII SwrContext for audio convert / resample.
Definition Swr.hxx:59
RAII SwsContext for video scale / convert.
Definition Sws.hxx:56
Abstract base for every StormByte Multimedia filter.
Definition ffmpeg.hxx:226
Pair {num, den} matching libavutil AVRational.
Definition av_rational.hxx:62
Incomplete FFmpeg types for RAII headers.
Frame and packet steps attached to a job or a raw pipeline.
Multimedia-owned pipeline stages and unit holders.
Private RAII wrappers over libav*.
Demux / decode / filter / encode / mux types.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47