avcpp
2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
|
Go to the documentation of this file.
15 #include <libavutil/imgutils.h>
16 #include <libavutil/attributes.h>
29 #if LIBAVUTIL_VERSION_MAJOR < 56 // < FFmpeg 4.0
30 return av_frame_get_best_effort_timestamp(frame);
32 return frame->best_effort_timestamp;
38 #if LIBAVUTIL_VERSION_MAJOR < 56 // < FFmpeg 4.0
39 return static_cast<uint64_t
>(av_frame_get_channel_layout(frame));
40 #elif API_NEW_CHANNEL_LAYOUT
41 return frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? frame->ch_layout.u.mask : 0;
43 return frame->channel_layout;
48 #if LIBAVUTIL_VERSION_MAJOR < 56 // < FFmpeg 4.0
49 av_frame_set_channel_layout(frame,
static_cast<int64_t
>(layout));
50 #elif API_NEW_CHANNEL_LAYOUT
51 av_channel_layout_uninit(&frame->ch_layout);
52 av_channel_layout_from_mask(&frame->ch_layout, layout);
54 frame->channel_layout = layout;
60 #if LIBAVUTIL_VERSION_MAJOR < 56 // < FFmpeg 4.0
61 return av_frame_get_channels(frame);
62 #elif API_NEW_CHANNEL_LAYOUT
63 return frame->ch_layout.nb_channels;
65 return frame->channels;
71 #if API_NEW_CHANNEL_LAYOUT
72 return av_channel_layout_check(&frame->ch_layout);
74 return frame->channel_layout;
79 #if LIBAVUTIL_VERSION_MAJOR < 56 // < FFmpeg 4.0
80 return av_frame_get_sample_rate(frame);
82 return frame->sample_rate;
87 #if LIBAVUTIL_VERSION_MAJOR < 56 // < FFmpeg 4.0
88 av_frame_set_sample_rate(frame, sampleRate);
90 frame->sample_rate = sampleRate;
103 return static_cast<T&
>(*this);
104 T(rhs).
swap(
static_cast<T&
>(*
this));
105 return static_cast<T&
>(*this);
110 return static_cast<T&
>(*this);
111 T(std::move(rhs)).
swap(
static_cast<T&
>(*
this));
112 return static_cast<T&
>(*this);
117 m_raw = av_frame_alloc();
118 m_raw->opaque =
this;
122 av_frame_free(&
m_raw);
127 m_raw = av_frame_alloc();
128 m_raw->opaque =
this;
129 av_frame_ref(
m_raw, frame);
141 m_raw = av_frame_alloc();
142 m_raw->opaque =
this;
143 av_frame_move_ref(
m_raw, other.m_raw);
157 #define FRAME_SWAP(x) swap(x, other.x)
177 return av_buffer_get_ref_count(
m_raw->buf[0]);
183 return m_raw ? av_frame_clone(
m_raw) :
nullptr;
191 result.m_raw->width =
m_raw->width;
192 result.m_raw->height =
m_raw->height;
193 result.m_raw->nb_samples =
m_raw->nb_samples;
197 result.copyInfoFrom(
static_cast<const T&
>(*
this));
199 av_frame_get_buffer(result.m_raw, align);
200 av_frame_copy(result.m_raw,
m_raw);
201 av_frame_copy_props(result.m_raw,
m_raw);
231 int64_t rescaledPts =
NoPts;
232 int64_t rescaledBestEffortTs =
NoPts;
241 rescaledPts =
m_raw->pts;
242 rescaledBestEffortTs =
m_raw->best_effort_timestamp;
246 m_raw->pts = rescaledPts;
247 m_raw->best_effort_timestamp = rescaledBestEffortTs;
270 ((
m_raw->format == AV_PIX_FMT_VAAPI) && ((intptr_t)
m_raw->data[3] > 0)))
276 uint8_t *
data(
size_t plane = 0) {
277 if (!
m_raw || plane >=
size_t(AV_NUM_DATA_POINTERS +
m_raw->nb_extended_buf))
279 return m_raw->extended_data[plane];
282 const uint8_t *
data(
size_t plane = 0)
const {
283 if (!
m_raw || plane >=
size_t(AV_NUM_DATA_POINTERS +
m_raw->nb_extended_buf))
285 return m_raw->extended_data[plane];;
288 size_t size(
size_t plane)
const {
289 if (!
m_raw || plane >=
size_t(AV_NUM_DATA_POINTERS +
m_raw->nb_extended_buf))
291 AVBufferRef *buf = plane < AV_NUM_DATA_POINTERS ?
293 m_raw->extended_buf[plane - AV_NUM_DATA_POINTERS];
296 return size_t(buf->size);
304 for (
auto i = 0; i < AV_NUM_DATA_POINTERS &&
m_raw->buf[i]; i++) {
305 total +=
m_raw->buf[i]->size;
308 for (
auto i = 0; i <
m_raw->nb_extended_buf; ++i) {
309 total +=
m_raw->extended_buf[i]->size;
311 }
else if (
m_raw->data[0]) {
313 uint8_t
data[4] = {0};
320 total = av_image_fill_pointers(
reinterpret_cast<uint8_t**
>(&
data),
321 static_cast<AVPixelFormat
>(
m_raw->format),
326 for (
auto i = 0; i <
m_raw->nb_extended_buf + AV_NUM_DATA_POINTERS &&
m_raw->extended_data[i]; ++i) {
328 total +=
m_raw->linesize[0];
339 for (
size_t i = 0; i < AV_NUM_DATA_POINTERS &&
m_raw->buf[i]; i++) {
340 av_hex_dump(stdout,
m_raw->buf[i]->data,
m_raw->buf[i]->size);
342 }
else if (
m_raw->data[0]) {
343 av_hex_dump(stdout,
m_raw->data[0],
size());
attribute_deprecated void setPts(int64_t pts, Rational ptsTimeBase)
Definition: frame.h:210
int sampleRate() const
Definition: frame.cpp:329
const Rational & timeBase() const
Definition: frame.h:222
void setPictureType(AVPictureType type=AV_PICTURE_TYPE_NONE)
Definition: frame.cpp:188
T clone(size_t align=1) const
Definition: frame.h:186
~Frame()
Definition: frame.h:121
Definition: rational.h:24
bool copyToBuffer(uint8_t *dst, size_t size, int align=1, OptionalErrorCode ec=throws())
Definition: frame.cpp:214
static int get_channels(const AVFrame *frame)
Definition: frame.h:59
VideoFrame & operator=(const VideoFrame &rhs)
Definition: frame.cpp:124
Frame()
Definition: frame.h:116
void swap(Frame &other)
Definition: frame.h:155
int samplesCount() const
Definition: frame.cpp:314
int init(SampleFormat sampleFormat, int samplesCount, uint64_t channelLayout, int sampleRate, int align=SampleFormat::AlignDefault)
Definition: frame.cpp:240
T & assignOperator(const T &rhs)
Definition: frame.h:101
bool isNull() const
Definition: ffmpeg.h:77
static bool is_valid_channel_layout(const AVFrame *frame)
Definition: frame.h:69
int refCount() const
Definition: frame.h:175
static void set_channel_layout(AVFrame *frame, uint64_t layout)
Definition: frame.h:47
int height() const
Definition: frame.cpp:144
SampleFormat sampleFormat() const
Definition: frame.cpp:309
size_t bufferSize(int align=1, OptionalErrorCode ec=throws()) const
Definition: frame.cpp:203
static int get_sample_rate(const AVFrame *frame)
Definition: frame.h:78
int64_t rescale(int64_t srcValue, const Rational &dstBase) const noexcept
Definition: rational.cpp:36
Timestamp pts() const
Definition: frame.h:205
void setStreamIndex(int streamIndex)
Definition: frame.h:257
AudioSamples & operator=(const AudioSamples &rhs)
Definition: frame.cpp:299
PixelFormat pixelFormat() const
Definition: frame.cpp:134
bool isValid() const
Definition: frame.h:267
size_t size() const
Definition: frame.h:299
int m_streamIndex
Definition: frame.h:349
int width() const
Definition: frame.cpp:139
bool m_isComplete
Definition: frame.h:350
constexpr auto NoPts
Definition: avutils.h:54
uint8_t * data(size_t plane=0)
Definition: frame.h:276
AVFrame * makeRef() const
Definition: frame.h:182
#define RAW_GET(field, def)
Definition: ffmpeg.h:94
const uint8_t * data(size_t plane=0) const
Definition: frame.h:282
int channelsCount() const
Definition: frame.cpp:319
AVPictureType pictureType() const
Definition: frame.cpp:183
int quality() const
Definition: frame.cpp:173
void setPts(const Timestamp &ts)
Definition: frame.h:215
void dump() const
Definition: frame.h:335
void copyInfoFrom(const T &other)
Definition: frame.h:165
bool isReferenced() const
Definition: frame.h:171
Frame(const AVFrame *frame)
Definition: frame.h:125
int streamIndex() const
Definition: frame.h:253
std::string channelsLayoutString() const
Definition: frame.cpp:346
void setComplete(bool isComplete)
Definition: frame.h:261
bool isComplete() const
Definition: frame.h:265
static void set_sample_rate(AVFrame *frame, int sampleRate)
Definition: frame.h:86
void operator=(const Frame &)=delete
uint64_t channelsLayout() const
Definition: frame.cpp:324
void setTimeBase(const Rational &value)
Definition: frame.h:224
T & moveOperator(T &&rhs)
Definition: frame.h:108
Definition: audioresampler.cpp:8
void setKeyFrame(bool isKey)
Definition: frame.cpp:158
bool isPlanar() const
Definition: frame.cpp:341
AVFrame * m_raw
Definition: ffmpeg.h:91
static int64_t get_best_effort_timestamp(const AVFrame *frame)
Definition: frame.h:28
size_t size(size_t plane) const
Definition: frame.h:288
void channel_layout_copy(AVFrame &dst, const AVFrame &src)
Definition: frame.cpp:362
static uint64_t get_channel_layout(const AVFrame *frame)
Definition: frame.h:37
The Timestamp class represents timestamp value and it timebase.
Definition: timestamp.h:13
Rational m_timeBase
Definition: frame.h:348
bool isKeyFrame() const
Definition: frame.cpp:149
Frame(T &&other)
Definition: frame.h:139
#define RAW_SET(field, val)
Definition: ffmpeg.h:95
void setSampleAspectRatio(const Rational &sampleAspectRatio)
Definition: frame.cpp:198
size_t sampleBitDepth(OptionalErrorCode ec=throws()) const
Definition: frame.cpp:334
const Rational & timebase() const noexcept
Definition: timestamp.cpp:29
Frame(const T &other)
Definition: frame.h:134
Rational sampleAspectRatio() const
Definition: frame.cpp:193
void setQuality(int quality)
Definition: frame.cpp:178
int64_t timestamp() const noexcept
Definition: timestamp.cpp:19