|
avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
|
One video frame. More...
#include <frame.h>
Public Member Functions | |
| VideoFrame ()=default | |
| Create an invalid frame. | |
| VideoFrame (PixelFormat pixelFormat, int width, int height, int align=1) | |
| Allocate an empty frame for the given format and size. | |
| VideoFrame (const uint8_t *data, size_t size, PixelFormat pixelFormat, int width, int height, int align=1) | |
| Copy external image data into a frame. | |
| VideoFrame (const VideoFrame &other) | |
| Copy constructor: references the same frame buffer. | |
| VideoFrame (VideoFrame &&other) | |
| Move constructor. | |
| VideoFrame & | operator= (const VideoFrame &rhs) |
| Copy assignment: references the buffer of the other frame. | |
| VideoFrame & | operator= (VideoFrame &&rhs) |
| Move assignment. | |
| PixelFormat | pixelFormat () const |
| Pixel format of the frame. | |
| int | width () const |
| Frame width. | |
| int | height () const |
| Frame height. | |
| PixelFormat | adjustFromJpegPixelFormat () |
| Convert JPEG pixel format to the compatible non-JPEG one. | |
| PixelFormat | adjustToJpegPixelFormat () |
| Convert non-JPEG pixel format to the compatible JPEG one. | |
| bool | isKeyFrame () const |
| Whether the frame is a key frame. | |
| void | setKeyFrame (bool isKey) |
| Mark the frame as a key frame. | |
| int | quality () const |
| Quality value attached to the frame. | |
| void | setQuality (int quality) |
| Attach a quality value to the frame. | |
| AVPictureType | pictureType () const |
| Picture type assigned by the decoder or expected by the encoder. | |
| void | setPictureType (AVPictureType type=AV_PICTURE_TYPE_NONE) |
| Set the picture type. | |
| Rational | sampleAspectRatio () const |
| Pixel aspect ratio of the frame. | |
| void | setSampleAspectRatio (const Rational &sampleAspectRatio) |
| Set the pixel aspect ratio. | |
| size_t | bufferSize (int align=1, OptionalErrorCode ec=throws()) const |
| Size of the buffer needed to hold the frame in one contiguous block. | |
| bool | copyToBuffer (uint8_t *dst, size_t size, int align=1, OptionalErrorCode ec=throws()) |
| Copy the image into a caller-provided buffer. | |
| bool | copyToBuffer (std::vector< uint8_t > &dst, int align=1, OptionalErrorCode ec=throws()) |
| Copy the image into a vector, resizing it as needed. | |
| VideoFrame | clone (size_t align=1, OptionalErrorCode ec=throws()) const |
| Deep copy of a software frame. | |
| VideoFrame | toSystemMemory (PixelFormat format=AV_PIX_FMT_NONE, OptionalErrorCode ec=throws()) const |
| Transfer a hardware frame into system memory. | |
| VideoFrame | toHwFrame (const hw::FramesContext &frames, OptionalErrorCode ec=throws()) const |
| Upload a software frame into hardware memory. | |
| 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. | |
| hw::FramesContext | hwFramesContext () const noexcept |
| Frames context of this hardware frame, or an invalid context. | |
| hw::DeviceContext | hwDeviceContext () const noexcept |
| Device context used by this hardware frame, or an invalid context. | |
| Public Member Functions inherited from av::Frame< VideoFrame > | |
| FrameCommon () | |
| Create an invalid frame. | |
| FrameCommon (const AVFrame *frame) | |
| Copy the frame metadata into a new wrapper. | |
| FrameCommon (const FrameCommon &other) | |
| Copy constructor: references the same buffer. | |
| FrameCommon (FrameCommon &&other) | |
| Move constructor. | |
| VideoFrame | clone (size_t align=1) const |
| Deep copy of the frame. | |
| Public Member Functions inherited from av::FrameCommon | |
| FrameCommon () | |
| Create an invalid frame. | |
| FrameCommon (const AVFrame *frame) | |
| Copy the frame metadata into a new wrapper. | |
| FrameCommon (const FrameCommon &other) | |
| Copy constructor: references the same buffer. | |
| FrameCommon (FrameCommon &&other) | |
| Move constructor. | |
| bool | isReferenced () const |
| Whether the frame data is reference counted. | |
| int | refCount () const |
| Number of references to the frame buffer. | |
| AVFrame * | makeRef () const |
| Create an independent reference to the frame. | |
| Timestamp | pts () const |
| Presentation timestamp. | |
| attribute_deprecated void | setPts (int64_t pts, Rational ptsTimeBase) |
| Set the timestamp and its time base at once. | |
| void | setPts (const Timestamp &ts) |
| Set the timestamp. | |
| const Rational & | timeBase () const |
| Time base of the frame. | |
| void | setTimeBase (const Rational &value) |
| Set the time base. | |
| int | streamIndex () const |
| Index of the stream the frame belongs to. | |
| void | setStreamIndex (int streamIndex) |
| Set the stream index. | |
| void | setComplete (bool isComplete) |
| Mark the frame as complete or incomplete. | |
| bool | isComplete () const |
| Whether the frame is marked complete. | |
| bool | isValid () const |
| Whether the wrapper holds a frame. | |
| operator bool () const | |
| Whether the wrapper holds a frame. | |
| bool | isHwFrame () const |
| Whether the frame lives in device memory. | |
| uint8_t * | data (size_t plane=0) |
| Pointer to one image or audio plane. | |
| const uint8_t * | data (size_t plane=0) const |
| Pointer to one plane, read-only. | |
| size_t | size (size_t plane) const |
| Size of one plane. | |
| size_t | size () const |
| Total size of all planes. | |
| void | dump () const |
| Print the frame layout through the FFmpeg log system. | |
| void | operator= (const FrameCommon &)=delete |
| Assignment is deleted: derived classes implement it to avoid slicing. | |
| void | swap (FrameCommon &other) |
| Exchange the contents of two frames. | |
| const FrameSideData | sideData (AVFrameSideDataType type) const |
| Get packet side data of the given type. | |
| FrameSideData | sideData (AVFrameSideDataType type) |
| Mutable access to the side data of the given type. | |
| std::size_t | sideDataCount () const noexcept |
| Return count of the side data elements. | |
| FrameSideData | sideDataIndex (std::size_t index) noexcept |
| Get side data element by index. | |
| ArrayView< AVFrameSideData *, FrameSideData, std::size_t > | sideData () noexcept |
| Observe all packet side data via iterators. | |
| ArrayView< const AVFrameSideData *, FrameSideData, std::size_t > | sideData () const noexcept |
| Read-only iteration over all side data entries. | |
| void | sideDataRemove (AVFrameSideDataType type) noexcept |
| Remove and free all side data instances of the given type. | |
| FrameSideData | addSideData (AVFrameSideDataType type, std::span< const uint8_t > data, OptionalErrorCode ec=throws()) |
| Add side data of the given type into packet. | |
| FrameSideData | addSideData (AVFrameSideDataType type, std::span< uint8_t > data, wrap_data, OptionalErrorCode ec=throws()) |
| Add side data of the given type into packet. | |
| FrameSideData | addSideData (AVFrameSideDataType type, std::span< uint8_t > data, wrap_data_static, OptionalErrorCode ec=throws()) |
| Add side data of the given type into packet. | |
| FrameSideData | addSideData (AVFrameSideDataType type, BufferRef buf, OptionalErrorCode ec=throws()) |
| Add side data of the given type into packet. | |
| 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. | |
| Public Member Functions inherited from FFWrapperPtr< AVFrame > | |
| FFWrapperPtr ()=default | |
| Create an empty wrapper; isNull() is true. | |
| const AVFrame * | raw () const |
| Read access to the wrapped object. | |
| void | reset (AVFrame *raw=nullptr) |
| Replace the stored pointer. | |
| bool | isNull () const |
| Whether the wrapper is empty. | |
| void | _log (int level, const char *fmt) const |
| Log through the FFmpeg log system, using this wrapper as the context. | |
Static Public Member Functions | |
| 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, 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. | |
| Static Public Member Functions inherited from av::Frame< VideoFrame > | |
| static VideoFrame | null () |
| An invalid frame of this type. | |
Additional Inherited Members | |
| Protected Member Functions inherited from av::Frame< VideoFrame > | |
| VideoFrame & | assignOperator (const VideoFrame &rhs) |
| Copy the other frame into this one. | |
| VideoFrame & | moveOperator (VideoFrame &&rhs) |
| Move the other frame into this one. | |
| Protected Member Functions inherited from av::FrameCommon | |
| void | copyInfoFrom (const FrameCommon &other) |
| Copy the avcpp bookkeeping (time base, stream index, completeness). | |
| void | clone (FrameCommon &dst, size_t align=1) const |
| Make a deep copy of the frame data into another frame object. | |
| Protected Attributes inherited from av::FrameCommon | |
| Rational | m_timeBase {} |
| Time base of the timestamps in this frame. | |
| int | m_streamIndex {-1} |
| Index of the stream the frame belongs to; -1 when unset. | |
| bool | m_isComplete {false} |
| Completeness flag, set through setComplete(). | |
| Protected Attributes inherited from FFWrapperPtr< AVFrame > | |
| AVFrame * | m_raw |
| The wrapped pointer; owned by the derived class, not by this template. | |
The frame can live in system memory, where data[] is readable, or in device memory, where it is only a descriptor for a hardware surface; isHwFrame() tells the two apart and toSystemMemory() moves between them.
| av::VideoFrame::VideoFrame | ( | PixelFormat | pixelFormat, |
| int | width, | ||
| int | height, | ||
| int | align = 1 ) |
| pixelFormat | pixel format of the frame |
| width | width in pixels |
| height | height in pixels |
| align | alignment in bytes for each plane |
| av::VideoFrame::VideoFrame | ( | const uint8_t * | data, |
| size_t | size, | ||
| PixelFormat | pixelFormat, | ||
| int | width, | ||
| int | height, | ||
| int | align = 1 ) |
| data | buffer holding the image |
| size | size of the buffer in bytes |
| pixelFormat | pixel format of the data |
| width | width in pixels |
| height | height in pixels |
| align | alignment in bytes for each plane |
| av::VideoFrame::VideoFrame | ( | const VideoFrame & | other | ) |
| other | the frame to copy |
| av::VideoFrame::VideoFrame | ( | VideoFrame && | other | ) |
| other | the frame to move from; left invalid |
| PixelFormat av::VideoFrame::adjustFromJpegPixelFormat | ( | ) |
YUV Pixel formats with J in the naming (AV_PIX_FMT_YUVJxxx) mostly deprecated and some components warn about it. Allow to adjust internal pixel format into compatible one.
| PixelFormat av::VideoFrame::adjustToJpegPixelFormat | ( | ) |
YUV Pixel formats with J in the naming (AV_PIX_FMT_YUVJxxx) mostly deprecated and some components warn about it. Allow to adjust internal pixel format into compatible one.
| size_t av::VideoFrame::bufferSize | ( | int | align = 1, |
| OptionalErrorCode | ec = throws() ) const |
| align | alignment in bytes for each plane |
| ec | holder for the error code |
| VideoFrame av::VideoFrame::clone | ( | size_t | align = 1, |
| OptionalErrorCode | ec = throws() ) const |
Hardware frames cannot be copied implicitly: the function reports Errors::HardwareTransferUnsupported. Use toSystemMemory() to transfer a hardware frame into system memory first. An invalid frame produces an invalid copy without an error.
| align | |
| ec |
| bool av::VideoFrame::copyToBuffer | ( | std::vector< uint8_t > & | dst, |
| int | align = 1, | ||
| OptionalErrorCode | ec = throws() ) |
| dst | destination vector; resized to bufferSize() |
| align | alignment in bytes for each plane |
| ec | holder for the error code |
| bool av::VideoFrame::copyToBuffer | ( | uint8_t * | dst, |
| size_t | size, | ||
| int | align = 1, | ||
| OptionalErrorCode | ec = throws() ) |
| dst | destination buffer |
| size | size of the destination in bytes |
| align | alignment in bytes for each plane |
| ec | holder for the error code |
| int av::VideoFrame::height | ( | ) | const |
|
noexcept |
|
noexcept |
| bool av::VideoFrame::isKeyFrame | ( | ) | const |
| VideoFrame av::VideoFrame::mapTo | ( | const hw::FramesContext & | frames, |
| int | flags = AV_HWFRAME_MAP_READ, | ||
| OptionalErrorCode | ec = throws() ) const |
Uses av_hwframe_map(). The operation depends on the backend and may fail with ENOSYS. Use toHwFrame() with a transfer for a portable path.
| frames | |
| flags | |
| ec |
| VideoFrame & av::VideoFrame::operator= | ( | const VideoFrame & | rhs | ) |
| rhs | the frame to assign from |
| VideoFrame & av::VideoFrame::operator= | ( | VideoFrame && | rhs | ) |
| rhs | the frame to move from; left invalid |
| AVPictureType av::VideoFrame::pictureType | ( | ) | const |
| PixelFormat av::VideoFrame::pixelFormat | ( | ) | const |
| int av::VideoFrame::quality | ( | ) | const |
| Rational av::VideoFrame::sampleAspectRatio | ( | ) | const |
| void av::VideoFrame::setKeyFrame | ( | bool | isKey | ) |
| isKey | the new state of the key-frame flag |
| void av::VideoFrame::setPictureType | ( | AVPictureType | type = AV_PICTURE_TYPE_NONE | ) |
| type | the AV_PICTURE_TYPE_* value; the default lets the encoder decide |
| void av::VideoFrame::setQuality | ( | int | quality | ) |
| quality | quality in the FF_LAMBDA_* scale |
| void av::VideoFrame::setSampleAspectRatio | ( | const Rational & | sampleAspectRatio | ) |
| sampleAspectRatio | width divided by height of a single pixel |
| VideoFrame av::VideoFrame::toHwFrame | ( | const hw::FramesContext & | frames, |
| OptionalErrorCode | ec = throws() ) const |
The destination buffer is allocated with av_hwframe_get_buffer() and then filled with av_hwframe_transfer_data(). A hardware frame that already belongs to frames is returned as a reference copy.
| frames | |
| ec |
| VideoFrame av::VideoFrame::toSystemMemory | ( | PixelFormat | format = AV_PIX_FMT_NONE, |
| OptionalErrorCode | ec = throws() ) const |
The function allocates a software frame and copies the hardware surface into it. When format is not AV_PIX_FMT_NONE, the transfer requests that format. The format must be supported by the hardware backend; see FramesContext::transferFormats().
A software frame is returned as a reference copy when no format conversion is requested.
| format | |
| ec |
| int av::VideoFrame::width | ( | ) | const |
|
static |
| data | data pointer to wrap |
| size | whole data buffer size with alignment and real data |
| pixelFormat | pixel format of the data |
| width | image width |
| height | image height |
| align | image data alignemnt |
|
static |
| data | external image data wrapped into std::span |
| pixelFormat | pixel format of the data |
| width | image width |
| height | image height |
| align | image data alignment |
|
static |
| data | external image data wrapped into std::span |
| deleter | user defined deleter |
| opaque | opaque data passed to the deleter, maybe nullptr |
| pixelFormat | pixel format of the data |
| width | image width |
| height | image height |
| align | image data alignment |