16#if AVCPP_CXX_STANDARD >= 20
17#if __has_include(<span>)
30#include <libavutil/hwcontext.h>
31#include <libavutil/imgutils.h>
32#include <libavutil/attributes.h>
71#if AVCPP_HAS_FRAME_SIDE_DATA
85 std::string_view
name() const noexcept;
91 AVFrameSideDataType
type() const noexcept;
128#if AVCPP_API_HAS_AVSIDEDATADESCRIPTOR
134 std::optional<AVSideDataDescriptor>
descriptor() const noexcept;
156 operator
bool() const noexcept;
309 operator bool()
const;
329 uint8_t *
data(
size_t plane = 0);
337 const uint8_t *
data(
size_t plane = 0)
const;
346 size_t size(
size_t plane)
const;
372#if AVCPP_HAS_FRAME_SIDE_DATA
520 return static_cast<T&
>(*this);
521 T(rhs).swap(
static_cast<T&
>(*
this));
522 return static_cast<T&
>(*this);
534 return static_cast<T&
>(*this);
535 T(std::move(rhs)).swap(
static_cast<T&
>(*
this));
536 return static_cast<T&
>(*this);
565static_assert(std::is_copy_assignable_v<FrameCommon> ==
false);
566static_assert(std::is_copy_constructible_v<FrameCommon> ==
true);
567static_assert(std::is_move_assignable_v<FrameCommon> ==
false);
568static_assert(std::is_move_constructible_v<FrameCommon> ==
true);
813 int flags = AV_HWFRAME_MAP_READ,
845#if AVCPP_CXX_STANDARD >= 20
879static_assert(std::is_copy_assignable_v<VideoFrame> ==
true);
880static_assert(std::is_copy_constructible_v<VideoFrame> ==
true);
881static_assert(std::is_move_assignable_v<VideoFrame> ==
true);
882static_assert(std::is_move_constructible_v<VideoFrame> ==
true);
1021static_assert(std::is_copy_assignable_v<AudioSamples> ==
true);
1022static_assert(std::is_copy_constructible_v<AudioSamples> ==
true);
1023static_assert(std::is_move_assignable_v<AudioSamples> ==
true);
1024static_assert(std::is_move_constructible_v<AudioSamples> ==
true);
FFmpeg version and API compatibility switches.
Reference counted buffers: BufferRef and Buffer over AVBufferRef.
C-array (FFmpeg) wrapper witch can iterate over collection and represents any element via light-weigh...
Definition avutils.h:862
AudioSamples(SampleFormat sampleFormat, int samplesCount, uint64_t channelLayout, int sampleRate, int align=SampleFormat::AlignDefault)
Allocate an empty buffer with the given layout.
uint64_t channelsLayout() const
Channel layout as a bit mask.
SampleFormat sampleFormat() const
Sample format of the buffer.
AudioSamples & operator=(AudioSamples &&rhs)
Move assignment.
std::string channelsLayoutString() const
Human-readable name of the channel layout.
AudioSamples(const AudioSamples &other)
Copy constructor: references the same sample buffer.
AudioSamples(AudioSamples &&other)
Move constructor.
size_t sampleBitDepth(OptionalErrorCode ec=throws()) const
Number of bits per sample.
int channelsCount() const
Number of audio channels.
int sampleRate() const
Sample rate of the buffer.
bool isPlanar() const
Whether the channels are stored in separate planes.
int samplesCount() const
Number of samples per channel.
AudioSamples(const uint8_t *data, size_t size, SampleFormat sampleFormat, int samplesCount, uint64_t channelLayout, int sampleRate, int align=SampleFormat::AlignDefault)
Copy external sample data into a buffer.
AudioSamples()=default
Create an invalid buffer.
AudioSamples & operator=(const AudioSamples &rhs)
Copy assignment: references the buffer of the other samples.
int init(SampleFormat sampleFormat, int samplesCount, uint64_t channelLayout, int sampleRate, int align=SampleFormat::AlignDefault)
Allocate the buffer storage.
Non-owning view for the nested AVBufferRef.
Definition buffer.h:32
Light weight wrapper for the FFmpeg AVBufferRef functionality.
Definition buffer.h:136
Implements interface to access to the AVDictionary entity.
Definition dictionary.h:38
void sideDataRemove(AVFrameSideDataType type) noexcept
Remove and free all side data instances of the given type.
bool m_isComplete
Completeness flag, set through setComplete().
Definition frame.h:496
std::size_t sideDataCount() const noexcept
Return count of the side data elements.
void setPts(const Timestamp &ts)
Set the timestamp.
FrameCommon()
Create an invalid frame.
void copyInfoFrom(const FrameCommon &other)
Copy the avcpp bookkeeping (time base, stream index, completeness).
void setComplete(bool isComplete)
Mark the frame as complete or incomplete.
Rational m_timeBase
Time base of the timestamps in this frame.
Definition frame.h:492
bool isComplete() const
Whether the frame is marked complete.
FrameSideData sideData(AVFrameSideDataType type)
Mutable access to the side data of the given type.
uint8_t * data(size_t plane=0)
Pointer to one image or audio plane.
int refCount() const
Number of references to the frame buffer.
FrameSideData sideDataIndex(std::size_t index) noexcept
Get side data element by index.
FrameSideData allocateSideData(AVFrameSideDataType type, std::size_t size, OptionalErrorCode ec=throws())
Allocate storage for the packet side data of the given type and return reference to it.
FrameCommon(FrameCommon &&other)
Move constructor.
int streamIndex() const
Index of the stream the frame belongs to.
attribute_deprecated void setPts(int64_t pts, Rational ptsTimeBase)
Set the timestamp and its time base at once.
bool isValid() const
Whether the wrapper holds a frame.
const uint8_t * data(size_t plane=0) const
Pointer to one plane, read-only.
bool isHwFrame() const
Whether the frame lives in device memory.
void dump() const
Print the frame layout through the FFmpeg log system.
const Rational & timeBase() const
Time base of the frame.
AVFrame * makeRef() const
Create an independent reference to the frame.
bool isReferenced() const
Whether the frame data is reference counted.
void swap(FrameCommon &other)
Exchange the contents of two frames.
const FrameSideData sideData(AVFrameSideDataType type) const
Get packet side data of the given type.
void setTimeBase(const Rational &value)
Set the time base.
size_t size() const
Total size of all planes.
void setStreamIndex(int streamIndex)
Set the stream index.
FrameCommon(const AVFrame *frame)
Copy the frame metadata into a new wrapper.
void operator=(const FrameCommon &)=delete
Assignment is deleted: derived classes implement it to avoid slicing.
FrameCommon(const FrameCommon &other)
Copy constructor: references the same buffer.
size_t size(size_t plane) const
Size of one plane.
FrameSideData addSideData(AVFrameSideDataType type, std::span< const uint8_t > data, OptionalErrorCode ec=throws())
Add side data of the given type into packet.
int m_streamIndex
Index of the stream the frame belongs to; -1 when unset.
Definition frame.h:494
void clone(FrameCommon &dst, size_t align=1) const
Make a deep copy of the frame data into another frame object.
Timestamp pts() const
Presentation timestamp.
Simple view for the AVFrameSideData elements.
Definition frame.h:76
std::optional< AVSideDataDescriptor > descriptor() const noexcept
Descriptor of this side data type, when the FFmpeg build provides one.
AVFrameSideDataType type() const noexcept
Identifier of the side data type.
Dictionary metadata() const noexcept
metadata
std::string_view name() const noexcept
Name of the side data type, as FFmpeg spells it.
BufferRefView buffer() const noexcept
The buffer that owns the payload.
std::span< const uint8_t > span() const noexcept
Read-only view of the payload.
bool empty() const noexcept
Whether the entry carries no payload.
CRTP base that gives a frame type its copy and move assignment.
Definition frame.h:509
T & moveOperator(T &&rhs)
Move the other frame into this one.
Definition frame.h:532
FrameCommon()
Create an invalid frame.
T clone(size_t align=1) const
Deep copy of the frame.
Definition frame.h:558
T & assignOperator(const T &rhs)
Copy the other frame into this one.
Definition frame.h:518
static T null()
An invalid frame of this type.
Definition frame.h:547
Carries the caller's choice between exceptions and error codes.
Definition averror.h:96
Rational number: a numerator and a denominator.
Definition rational.h:49
The Timestamp class represents timestamp value and it timebase.
Definition timestamp.h:25
VideoFrame()=default
Create an invalid frame.
VideoFrame toHwFrame(const hw::FramesContext &frames, OptionalErrorCode ec=throws()) const
Upload a software frame into hardware memory.
VideoFrame(VideoFrame &&other)
Move constructor.
VideoFrame(const VideoFrame &other)
Copy constructor: references the same frame buffer.
VideoFrame & operator=(VideoFrame &&rhs)
Move assignment.
VideoFrame mapTo(const hw::FramesContext &frames, int flags=AV_HWFRAME_MAP_READ, OptionalErrorCode ec=throws()) const
Map this hardware frame into another hardware frames context.
bool isKeyFrame() const
Whether the frame is a key frame.
PixelFormat adjustFromJpegPixelFormat()
Convert JPEG pixel format to the compatible non-JPEG one.
hw::DeviceContext hwDeviceContext() const noexcept
Device context used by this hardware frame, or an invalid context.
VideoFrame(const uint8_t *data, size_t size, PixelFormat pixelFormat, int width, int height, int align=1)
Copy external image data into a frame.
hw::FramesContext hwFramesContext() const noexcept
Frames context of this hardware frame, or an invalid context.
VideoFrame & operator=(const VideoFrame &rhs)
Copy assignment: references the buffer of the other frame.
void setQuality(int quality)
Attach a quality value to the frame.
static VideoFrame wrap(std::span< const std::byte > data, PixelFormat pixelFormat, int width, int height, int align=1)
Wrap external data into VideoFrame object ready to use with FFmpeg/AvCpp.
static VideoFrame wrap(const void *data, size_t size, PixelFormat pixelFormat, int width, int height, int align=1)
Wrap external data into VideoFrame object ready to use with FFmpeg/AvCpp.
static VideoFrame wrap(std::span< const std::byte > data, void(*deleter)(void *opaque, uint8_t *data), void *opaque, PixelFormat pixelFormat, int width, int height, int align=1)
Wrap external data into VideoFrame object ready to use with FFmpeg/AvCpp.
Rational sampleAspectRatio() const
Pixel aspect ratio of the frame.
bool copyToBuffer(std::vector< uint8_t > &dst, int align=1, OptionalErrorCode ec=throws())
Copy the image into a vector, resizing it as needed.
VideoFrame(PixelFormat pixelFormat, int width, int height, int align=1)
Allocate an empty frame for the given format and size.
void setSampleAspectRatio(const Rational &sampleAspectRatio)
Set the pixel aspect ratio.
PixelFormat adjustToJpegPixelFormat()
Convert non-JPEG pixel format to the compatible JPEG one.
size_t bufferSize(int align=1, OptionalErrorCode ec=throws()) const
Size of the buffer needed to hold the frame in one contiguous block.
VideoFrame toSystemMemory(PixelFormat format=AV_PIX_FMT_NONE, OptionalErrorCode ec=throws()) const
Transfer a hardware frame into system memory.
bool copyToBuffer(uint8_t *dst, size_t size, int align=1, OptionalErrorCode ec=throws())
Copy the image into a caller-provided buffer.
int height() const
Frame height.
int width() const
Frame width.
void setPictureType(AVPictureType type=AV_PICTURE_TYPE_NONE)
Set the picture type.
PixelFormat pixelFormat() const
Pixel format of the frame.
void setKeyFrame(bool isKey)
Mark the frame as a key frame.
VideoFrame clone(size_t align=1, OptionalErrorCode ec=throws()) const
Deep copy of a software frame.
int quality() const
Quality value attached to the frame.
AVPictureType pictureType() const
Picture type assigned by the decoder or expected by the encoder.
Owner of an AVHWFramesContext.
Definition hwcontext.h:242
AVDictionary wrappers: Dictionary and DictionaryArray.
FFmpeg types re-exported for the public API and small value wrappers.
int64_t get_best_effort_timestamp(const AVFrame *frame)
Timestamp FFmpeg considers the best estimate of the presentation time.
void set_channel_layout(AVFrame *frame, uint64_t layout)
Set the channel layout of a frame from a bit mask.
uint64_t get_channel_layout(const AVFrame *frame)
Channel layout of a frame as a bit mask.
Hardware devices, hardware frames and hardware codec configuration.
Root namespace of the library.
Definition audioresampler.h:19
OptionalErrorCode throws()
Helper to construct null OptionalErrorCode object.
Definition averror.h:310
Rational numbers, time bases and arithmetic on them.
Wrap static data, do not owning and free.
Definition frame.h:183
Wrap data and take owning.
Definition frame.h:178
Frame timestamps and their arithmetic.