avcpp
2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
|
Go to the documentation of this file.
15 #include <libavcodec/avcodec.h>
16 #include <libavformat/version.h>
21 namespace codec_context::audio {
38 using BaseWrapper::BaseWrapper;
55 AVMediaType
codecType(AVMediaType contextType)
const noexcept;
72 [[deprecated(
"Start from FFmpeg 4.0 it is recommended to destroy and recreate codec context insted of close")]]
105 int strict() const noexcept;
108 int64_t
bitRate() const noexcept;
119 int flags() noexcept;
143 std::pair<
int, const
std::error_category*>
144 decodeCommon(AVFrame *outFrame, const class
Packet &inPacket,
size_t offset,
int &frameFinished,
145 int (*decodeProc)(AVCodecContext*, AVFrame*,
int *, const AVPacket *)) noexcept;
147 std::pair<
int, const
std::error_category*>
149 int (*encodeProc)(AVCodecContext*, AVPacket*,const AVFrame*,
int*)) noexcept;
153 std::pair<
int, const
std::error_category*>
155 const class
Packet &inPacket,
158 int (*decodeProc)(AVCodecContext *, AVFrame *,
int *, const AVPacket *));
161 std::pair<
int, const
std::error_category*>
165 int (*encodeProc)(AVCodecContext *, AVPacket *, const AVFrame *,
int *));
197 template<
typename Clazz, Direction _direction, AVMediaType _type>
204 return static_cast<Clazz&
>(*this);
205 Clazz(std::forward<Clazz>(rhs)).
swap(
static_cast<Clazz&
>(*
this));
206 return static_cast<Clazz&
>(*this);
260 template<
typename Clazz, Direction _direction>
265 using Parent::Parent;
266 using Parent::isValid;
267 using Parent::isOpened;
316 return RAW_GET(sample_aspect_ratio, AVRational());
324 m_raw->coded_width = w;
333 m_raw->coded_height = h;
354 if (quality < 0 || quality > FF_LAMBDA_MAX)
355 quality = FF_LAMBDA_MAX;
377 RAW_SET(sample_aspect_ratio, sampleAspectRatio);
381 using Parent::moveOperator;
410 bool autoAllocateFrame =
true);
427 size_t &decodedBytes,
429 bool autoAllocateFrame =
true);
436 size_t *decodedBytes,
437 bool autoAllocateFrame);
480 template<
typename Clazz, Direction _direction>
485 using Parent::Parent;
486 using Parent::isValid;
487 using Parent::isOpened;
514 #if API_NEW_CHANNEL_LAYOUT
515 ChannelLayoutView channelLayout2() const noexcept
518 return ChannelLayoutView{};
519 return ChannelLayoutView{
m_raw->ch_layout};
528 if (sr != sampleRate)
530 fflog(AV_LOG_INFO,
"Guess sample rate %d instead unsupported %d\n", sr, sampleRate);
533 m_raw->sample_rate = sr;
538 if (!
isValid() || channels <= 0)
555 #if API_NEW_CHANNEL_LAYOUT
556 void setChannelLayout(ChannelLayout layout) noexcept
558 if (!
isValid() || !layout.isValid())
560 m_raw->ch_layout = *layout.raw();
566 using Parent::moveOperator;
void setGlobalQuality(int32_t quality)
Definition: codeccontext.h:352
void setGopSize(int32_t size)
Definition: codeccontext.h:360
void clearFlags(int flags) noexcept
Definition: codeccontext.cpp:705
int64_t bitRate() const noexcept
Definition: codeccontext.cpp:667
#define fflog(level, format,...)
Default in-class logger.
Definition: avlog.h:27
void copyContextFrom(const CodecContext2 &other, OptionalErrorCode ec=throws())
Copy codec context from codec context associated with given stream or other codec context.
Definition: codeccontext.cpp:532
Definition: rational.h:24
int32_t gopSize() const
Definition: codeccontext.h:299
Implements interface to access to the AVDictionary entity.
Definition: dictionary.h:30
Clazz & moveOperator(Clazz &&rhs)
Definition: codeccontext.h:201
void setRefCountedFrames(bool refcounted) const noexcept
Definition: codeccontext.cpp:645
AVMediaType codecType() const noexcept
Definition: codeccontext.h:253
Rational timeBase() const noexcept
Definition: codeccontext.cpp:578
void setSampleRate(int sampleRate) noexcept
Definition: codeccontext.h:523
CodecContext2()
Definition: codeccontext.cpp:275
void setWidth(int w)
Definition: codeccontext.h:319
std::pair< int64_t, int64_t > bitRateRange() const noexcept
Definition: codeccontext.cpp:672
SampleFormat sampleFormat() const noexcept
Definition: codeccontext.h:502
int frameSize() const noexcept
Definition: codeccontext.cpp:622
PixelFormat pixelFormat() const
Definition: codeccontext.h:289
CodecContextBase()
Definition: codeccontext.h:215
void setCodec(const class Codec &codec, bool resetDefaults, Direction direction, AVMediaType type, OptionalErrorCode ec=throws())
Definition: codeccontext.cpp:351
Codec codec() const noexcept
Definition: codeccontext.cpp:593
int codedHeight() const
Definition: codeccontext.h:284
void setOption(const std::string &key, const std::string &val, OptionalErrorCode ec=throws())
bool isValidForEncode(Direction direction, AVMediaType type) const noexcept
Definition: codeccontext.cpp:752
void setCodec(const Codec &codec, OptionalErrorCode ec=throws())
Definition: codeccontext.h:243
int height() const
Definition: codeccontext.h:274
bool isValid() const noexcept
Definition: codeccontext.cpp:526
bool isFlags2(int flags) noexcept
Definition: codeccontext.cpp:745
void open(OptionalErrorCode ec=throws())
Definition: codeccontext.cpp:419
Definition: codeccontext.h:198
int flags2() noexcept
Definition: codeccontext.cpp:740
AVMediaType codecType(AVMediaType contextType) const noexcept
Definition: codeccontext.cpp:407
int strict() const noexcept
Definition: codeccontext.cpp:652
uint64_t get_channel_layout_mask(const AVCodecContext *obj)
Definition: codeccontext.cpp:1100
int flags() noexcept
Definition: codeccontext.cpp:711
int get_channels(const AVCodecContext *obj)
Definition: codeccontext.cpp:1084
void setSampleAspectRatio(const Rational &sampleAspectRatio)
Definition: codeccontext.h:375
void setMaxBFrames(int maxBFrames)
Definition: codeccontext.h:370
int codedWidth() const
Definition: codeccontext.h:279
std::pair< int, const std::error_category * > encodeCommon(class Packet &outPacket, const AVFrame *inFrame, int &gotPacket, int(*encodeProc)(AVCodecContext *, AVPacket *, const AVFrame *, int *)) noexcept
Definition: codeccontext.cpp:850
void setBitRate(int64_t bitRate) noexcept
Definition: codeccontext.cpp:680
void setChannels(int channels) noexcept
Definition: codeccontext.h:536
bool isRefCountedFrames() const noexcept
Definition: codeccontext.cpp:636
#define RAW_GET(field, def)
Definition: ffmpeg.h:94
void setStrict(int strict) noexcept
Definition: codeccontext.cpp:657
void set_channel_layout_mask(AVCodecContext *obj, uint64_t mask)
Definition: codeccontext.cpp:1063
Rational sampleAspectRatio() const
Definition: codeccontext.h:314
int width() const
Definition: codeccontext.h:269
void setSampleFormat(SampleFormat sampleFormat) noexcept
Definition: codeccontext.h:543
Definition: avutils.h:303
void clearFlags2(int flags) noexcept
Definition: codeccontext.cpp:734
int channels() const noexcept
Definition: codeccontext.h:495
int32_t globalQuality() const
Definition: codeccontext.h:294
int maxBFrames() const
Definition: codeccontext.h:309
void setCodedWidth(int w)
Definition: codeccontext.h:337
Definition: codeccontext.h:386
void _log(int level, const char *fmt) const
Definition: ffmpeg.h:79
bool checkCodec(const Codec &codec, Direction direction, AVMediaType type, OptionalErrorCode ec)
Definition: codeccontext.cpp:786
~CodecContext2()
Definition: codeccontext.cpp:328
CodecContextBase(CodecContextBase &&other)
Definition: codeccontext.h:235
void setChannelLayout(uint64_t layout) noexcept
Definition: codeccontext.h:548
void addFlags(int flags) noexcept
Definition: codeccontext.cpp:699
void set_channels(AVCodecContext *obj, int channels)
Definition: codeccontext.cpp:1048
CodecContextBase(const class Stream &st, const class Codec &codec=Codec())
Definition: codeccontext.h:221
void operator=(const noncopyable &)=delete
const Stream & stream() const noexcept
Definition: codeccontext.cpp:588
Definition: codeccontext.h:28
Definition: codeccontext.h:442
void close(OptionalErrorCode ec=throws())
Definition: codeccontext.cpp:508
void addFlags2(int flags) noexcept
Definition: codeccontext.cpp:728
The GenericCodecContext class to copy contexts from input streams to output one.
Definition: codeccontext.h:179
uint64_t channelLayout() const noexcept
Definition: codeccontext.h:507
void setFlags(int flags) noexcept
Access to CODEC_FLAG_* flags.
Definition: codeccontext.cpp:694
bool isFlags(int flags) noexcept
Definition: codeccontext.cpp:716
Definition: audioresampler.cpp:8
Definition: codeccontext.h:588
Definition: averror.h:228
int sampleRate() const noexcept
Definition: codeccontext.h:490
void setHeight(int h)
Definition: codeccontext.h:328
void setPixelFormat(PixelFormat pixelFormat)
Definition: codeccontext.h:347
Definition: codeccontext.h:481
int bitRateTolerance() const
Definition: codeccontext.h:304
AVCodecContext * m_raw
Definition: ffmpeg.h:91
Direction
Definition: stream.h:14
void setFlags2(int flags) noexcept
Access to CODEC_FLAG2_* flags.
Definition: codeccontext.cpp:723
OptionalErrorCode throws()
Helper to construct null OptionalErrorCode object.
Definition: averror.h:179
std::pair< int, const std::error_category * > decodeCommon(AVFrame *outFrame, const class Packet &inPacket, size_t offset, int &frameFinished, int(*decodeProc)(AVCodecContext *, AVFrame *, int *, const AVPacket *)) noexcept
Definition: codeccontext.h:571
int64_t frameNumber() const noexcept
Definition: codeccontext.cpp:627
Definition: codeccontext.h:261
void swap(CodecContext2 &other)
Definition: codeccontext.cpp:268
void setCodedHeight(int h)
Definition: codeccontext.h:342
CodecContextBase(const Codec &codec)
Definition: codeccontext.h:227
#define RAW_SET(field, val)
Definition: ffmpeg.h:95
bool isOpened() const noexcept
Definition: codeccontext.cpp:521
void setBitRateTolerance(int bitRateTolerance)
Definition: codeccontext.h:365
T guessValue(const T &value, const L *list, C endListComparator)
Select more approptiate value from given value list.
Definition: avutils.h:336
#define RAW_GET2(cond, field, def)
Definition: ffmpeg.h:97
#define RAW_SET2(cond, field, val)
Definition: ffmpeg.h:98
void setTimeBase(const Rational &value) noexcept
Definition: codeccontext.cpp:583
void setBitRateRange(const std::pair< int64_t, int64_t > &bitRateRange) noexcept
Definition: codeccontext.cpp:685
void setCodec(const Codec &codec, bool resetDefaults, OptionalErrorCode ec=throws())
Definition: codeccontext.h:248