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 AVFilterGraph;
84 class Swr;
85 class Sws;
86
99 friend class AVDecoder;
100 friend class AVEncoder;
101 friend class AVFilterGraph;
102 friend class StormByte::Multimedia::Backend::Pipeline::Frame;
104 friend class Swr;
105 friend class Sws;
106 public:
110 AVFrame() noexcept;
111
118 AVFrame(const AVFrame& other) noexcept;
119
124 AVFrame(AVFrame&& other) noexcept = default;
125
129 ~AVFrame() noexcept override;
130
136 AVFrame& operator=(const AVFrame& other) noexcept;
137
143 AVFrame& operator=(AVFrame&& other) noexcept = default;
144
149 explicit operator bool() const noexcept;
150
157 AVFrame Clone() const noexcept;
158
164 bool Ref(const AVFrame& other) noexcept;
165
171 bool Copy(const AVFrame& other) noexcept;
172
178 bool CopyProps(const AVFrame& other) noexcept;
179
185 bool GetBuffer(int align = 0) noexcept;
186
195 bool AllocVideo(int width, int height, int format, int align = 0) noexcept;
196
205 bool AllocAudio(int nb_samples, int format, const AVChannelLayout& layout, int sample_rate) noexcept;
206
210 void Unref() noexcept;
211
216 int Width() const noexcept;
217
222 void Width(int width) noexcept;
223
228 int Height() const noexcept;
229
234 void Height(int height) noexcept;
235
240 int Format() const noexcept;
241
246 void Format(int format) noexcept;
247
252 bool Hardware() const noexcept;
253
258 static int FormatNone() noexcept;
259
264 static int FormatGray8() noexcept;
265
270 static int FormatRgba() noexcept;
271
276 static int FormatYUV420P() noexcept;
277
284 enum class VideoLayout: std::uint8_t {
285 Unknown,
286 Gray,
287 Yuv420,
288 Yuv422,
289 Yuv444
290 };
291
298 enum class Scaler: std::uint8_t {
299 Zimg,
301 };
302
310 enum class Resample: std::uint8_t {
311 Default,
312 Point,
313 Bilinear,
314 Bicubic,
315 Spline,
316 Lanczos
317 };
318
323 VideoLayout Layout() const noexcept;
324
336 static AVFrame DecodeImage(const std::uint8_t* data, std::size_t size,
337 std::string_view hint = {}) noexcept;
338
343 std::int64_t Pts() const noexcept;
344
349 void Pts(std::int64_t pts) noexcept;
350
355 std::int64_t BestEffortTimestamp() const noexcept;
356
361 void BestEffortTimestamp(std::int64_t ts) noexcept;
362
367 std::int64_t DurationTicks() const noexcept;
368
373 void DurationTicks(std::int64_t duration) noexcept;
374
379 int ColorRange() const noexcept;
380
385 void ColorRange(int range) noexcept;
386
391 int ColorSpace() const noexcept;
392
397 void ColorSpace(int space) noexcept;
398
403 int ColorPrimaries() const noexcept;
404
409 void ColorPrimaries(int primaries) noexcept;
410
415 int ColorTransfer() const noexcept;
416
421 void ColorTransfer(int transfer) noexcept;
422
427 int ChromaLocation() const noexcept;
428
433 void ChromaLocation(int location) noexcept;
434
440
445 void SampleAspectRatio(AVRational sar) noexcept;
446
451 int PictType() const noexcept;
452
457 void PictType(int type) noexcept;
458
463 bool KeyFrame() const noexcept;
464
469 void KeyFrame(bool key) noexcept;
470
475 int RepeatPict() const noexcept;
476
481 void RepeatPict(int repeat) noexcept;
482
487 bool Interlaced() const noexcept;
488
494 void Interlaced(bool interlaced, bool top_first) noexcept;
495
500 bool TopFieldFirst() const noexcept;
501
506 int CropLeft() const noexcept;
507
512 int CropRight() const noexcept;
513
518 int CropTop() const noexcept;
519
524 int CropBottom() const noexcept;
525
533 void Crop(int left, int right, int top, int bottom) noexcept;
534
540 bool ApplyCropping(int flags = 0) noexcept;
541
546 int PlaneCount() const noexcept;
547
553 int PlaneWidth(int plane) const noexcept;
554
560 int PlaneHeight(int plane) const noexcept;
561
566 int BitsPerComponent() const noexcept;
567
572 const char* FormatName() const noexcept;
573
579 const uint8_t* Data(int plane) const noexcept;
580
586 uint8_t* Data(int plane) noexcept;
587
593 int Linesize(int plane) const noexcept;
594
599 int NbSamples() const noexcept;
600
605 void NbSamples(int samples) noexcept;
606
611 int SampleRate() const noexcept;
612
617 void SampleRate(int rate) noexcept;
618
623 int Channels() const noexcept;
624
630
636 bool CopyChannelLayout(const AVChannelLayout& layout) noexcept;
637
642 uint8_t** ExtendedData() noexcept;
643
648 const uint8_t* const* ExtendedData() const noexcept;
649
655 const AVFrameSideData* SideData(int type) const noexcept;
656
662 AVFrameSideData* SideData(int type) noexcept;
663
668 void RemoveSideData(int type) noexcept;
669
674 int SideDataCount() const noexcept;
675
681 const AVFrameSideData* SideDataAt(int index) const noexcept;
682
689 uint8_t* NewSideData(int type, int size) noexcept;
690
695 void CopyPrimaryBuffer(StormByte::Buffer::DataType& out) const noexcept;
696
701 void WriteHdr10(const StormByte::Multimedia::Property::HDR10& hdr10) noexcept;
702
707 void WriteSideData(const std::vector<StormByte::Multimedia::Pipeline::SideData>& attachments) noexcept;
708
720 bool ScaleTo(AVFrame& dst, int dst_w, int dst_h,
721 Resample filter = Resample::Default,
722 Scaler scaler = Scaler::Zimg) const noexcept;
723
728 void Reset(::AVFrame* raw) noexcept;
729
730 private:
734 void Free() noexcept override;
735
736 using AVPointer<::AVFrame>::Get;
737 using AVPointer<::AVFrame>::Detach;
738 };
739
740 extern template class STORMBYTE_MULTIMEDIA_PUBLIC AVPointer<::AVFrame>;
741}
RAII AVChannelLayout (av_channel_layout_copy / uninit).
Definition AVChannelLayout.hxx:66
int Linesize(int plane) const noexcept
Bytes per row for plane, including padding.
int PlaneHeight(int plane) const noexcept
Height of plane accounting for chroma subsampling.
int ColorRange() const noexcept
Color range.
bool Interlaced() const noexcept
Whether the frame is interlaced.
Resample
Resample kernel for ScaleTo.
Definition AVFrame.hxx:310
Scaler
Resampling backend for ScaleTo.
Definition AVFrame.hxx:298
void Unref() noexcept
Unreferences frame buffers (av_frame_unref).
VideoLayout
Planar video family, ignoring bit depth.
Definition AVFrame.hxx:284
friend class AVFilterGraph
Definition AVFrame.hxx:101
bool CopyChannelLayout(const AVChannelLayout &layout) noexcept
Replaces the channel layout.
int RepeatPict() const noexcept
Extra delay in field durations (repeat_pict).
int Width() const noexcept
Frame width in pixels.
int PlaneWidth(int plane) const noexcept
Width of plane accounting for chroma subsampling.
int SampleRate() const noexcept
Audio sample rate in Hz.
AVRational SampleAspectRatio() const noexcept
Sample aspect ratio.
bool AllocAudio(int nb_samples, int format, const AVChannelLayout &layout, int sample_rate) noexcept
Sets audio samples, format and layout, then allocates planes.
AVFrame() noexcept
Allocates an empty frame (av_frame_alloc).
bool Hardware() const noexcept
Whether the pixel format is hardware-backed.
bool AllocVideo(int width, int height, int format, int align=0) noexcept
Sets video geometry and format, then allocates planes.
void CopyPrimaryBuffer(StormByte::Buffer::DataType &out) const noexcept
Packs planar video/audio into out without linesize padding.
static int FormatNone() noexcept
AV_PIX_FMT_NONE as int.
bool ScaleTo(AVFrame &dst, int dst_w, int dst_h, Resample filter=Resample::Default, Scaler scaler=Scaler::Zimg) const noexcept
Scales this frame into dst (allocates dst if empty).
std::int64_t DurationTicks() const noexcept
Duration in stream ticks.
const AVFrameSideData * SideDataAt(int index) const noexcept
Side data at index.
int PlaneCount() const noexcept
Number of video components or audio channels.
int ColorTransfer() const noexcept
Transfer characteristics.
AVChannelLayout ChannelLayout() const noexcept
Channel layout owned by this frame.
int ChromaLocation() const noexcept
Chroma sample location.
VideoLayout Layout() const noexcept
Planar layout of this frame.
int CropTop() const noexcept
Top crop in pixels.
void WriteSideData(const std::vector< StormByte::Multimedia::Pipeline::SideData > &attachments) noexcept
Copies raw SEI/side-data blobs onto the frame.
AVFrame Clone() const noexcept
New frame referencing the same planes (av_frame_ref).
bool KeyFrame() const noexcept
Whether this is a key frame.
friend class Swr
Definition AVFrame.hxx:104
friend class AVEncoder
Definition AVFrame.hxx:100
bool GetBuffer(int align=0) noexcept
Allocates plane buffers (av_frame_get_buffer).
void WriteHdr10(const StormByte::Multimedia::Property::HDR10 &hdr10) noexcept
Writes mastering display and content light from hdr10.
std::int64_t Pts() const noexcept
Presentation timestamp in stream ticks.
int CropLeft() const noexcept
Left crop in pixels.
const char * FormatName() const noexcept
Pixel or sample format name.
int ColorPrimaries() const noexcept
Color primaries.
int BitsPerComponent() const noexcept
Bits per component from the pixel descriptor.
static int FormatGray8() noexcept
AV_PIX_FMT_GRAY8 as int.
bool CopyProps(const AVFrame &other) noexcept
Copies metadata from other (av_frame_copy_props).
int Format() const noexcept
Pixel or sample format.
int CropBottom() const noexcept
Bottom crop in pixels.
int Channels() const noexcept
Audio channel count.
friend class AVDecoder
Definition AVFrame.hxx:99
bool Copy(const AVFrame &other) noexcept
Copies samples/planes from other (av_frame_copy).
friend class Sws
Definition AVFrame.hxx:105
int Height() const noexcept
Frame height in pixels.
std::int64_t BestEffortTimestamp() const noexcept
Best-effort timestamp (best_effort_timestamp).
void Crop(int left, int right, int top, int bottom) noexcept
Sets crop window.
bool TopFieldFirst() const noexcept
Whether the top field is first (interlaced).
int NbSamples() const noexcept
Audio sample count.
void RemoveSideData(int type) noexcept
Removes side data of type.
static int FormatYUV420P() noexcept
AV_PIX_FMT_YUV420P as int.
static AVFrame DecodeImage(const std::uint8_t *data, std::size_t size, std::string_view hint={}) noexcept
Decodes one still image from a compressed buffer.
int SideDataCount() const noexcept
Number of side-data entries.
void Reset(::AVFrame *raw) noexcept
Adopts raw.
uint8_t * NewSideData(int type, int size) noexcept
Allocates side data of type (av_frame_new_side_data).
int PictType() const noexcept
Picture type (I/P/B/…).
const AVFrameSideData * SideData(int type) const noexcept
Looks up side data.
uint8_t ** ExtendedData() noexcept
Planar audio / video data pointers (extended_data).
int CropRight() const noexcept
Right crop in pixels.
bool ApplyCropping(int flags=0) noexcept
Applies the crop window (av_frame_apply_cropping).
static int FormatRgba() noexcept
AV_PIX_FMT_RGBA as int.
const uint8_t * Data(int plane) const noexcept
Const pointer to plane plane.
int ColorSpace() const noexcept
Matrix coefficients.
bool Ref(const AVFrame &other) noexcept
Shares buffers with other (av_frame_ref).
constexpr const std::decay_t< ::AVFrame > * Get() const noexcept
Definition AVPointer.hxx:118
constexpr std::decay_t< ::AVFrame > * Detach() noexcept
Definition AVPointer.hxx:139
Abstract base for every StormByte Multimedia filter.
Definition ffmpeg.hxx:253
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.
Hopper and Sink live in StormByte-Buffer.
Multimedia-owned pipeline stages and unit holders.
Definition AVFormatContext.hxx:52
Private RAII wrappers over libav*.
Demux / decode / filter / encode / mux types.
Media property value types.
Public multimedia types: codecs, containers, streams and files.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47