avcpp
2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
|
Go to the documentation of this file.
16 #include <libavfilter/avfilter.h>
17 #include <libavcodec/avcodec.h>
21 #define USE_CODECPAR ((LIBAVCODEC_VERSION_MAJOR) >= 59) // FFmpeg 5.0
24 #define API_NEW_CHANNEL_LAYOUT ((LIBAVUTIL_VERSION_MAJOR > 57) || (LIBAVUTIL_VERSION_MAJOR == 57 && (LIBAVUTIL_VERSION_MINOR >= 24)))
26 #define API_FRAME_NUM ((LIBAVCODEC_VERSION_MAJOR > 60) || (LIBAVCODEC_VERSION_MAJOR == 60 && LIBAVCODEC_VERSION_MINOR >= 2))
28 #define API_AVFORMAT_URL ((LIBAVFORMAT_VERSION_MAJOR > 58) || (LIBAVFORMAT_VERSION_MAJOR == 58 && LIBAVFORMAT_VERSION_MINOR >= 7))
30 #define API_FRAME_KEY ((LIBAVUTIL_VERSION_MAJOR > 58) || (LIBAVUTIL_VERSION_MAJOR == 58 && LIBAVUTIL_VERSION_MINOR >= 29))
32 #define API_AVCODEC_CLOSE (LIBAVCODEC_VERSION_MAJOR < 61)
34 #if defined(__ICL) || defined (__INTEL_COMPILER)
35 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
36 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
37 #elif defined(_MSC_VER)
38 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
39 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
40 #elif defined(__GNUC__) || defined(__clang__)
41 # define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
42 # define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
44 # define FF_DISABLE_DEPRECATION_WARNINGS
45 # define FF_ENABLE_DEPRECATION_WARNINGS
54 constexpr
auto NoPts =
static_cast<int64_t
>(AV_NOPTS_VALUE);
55 constexpr
auto TimeBase =
static_cast<int>(AV_TIME_BASE);
56 constexpr
auto TimeBaseQ = AVRational{1, AV_TIME_BASE};
59 template<
typename R,
typename T>
99 #define setFFmpegLoggingLevel set_logging_level
141 bool operator() (
struct SwsContext* &swsContext);
142 bool operator() (
struct AVCodecContext* &codecContext);
143 bool operator() (
struct AVOutputFormat* &format);
144 bool operator() (
struct AVFormatContext* &formatContext);
147 bool operator() (
struct AVDictionary* &dictionary);
148 bool operator ()(
struct AVFilterInOut* &filterInOut);
152 inline namespace v2 {
163 std::unique_ptr<T, void(*)(
void*)>
malloc(
size_t size)
165 return {
static_cast<T*
>(av_malloc(size)), av_free};
169 std::unique_ptr<T, void(*)(
void*)>
mallocz(
size_t size)
171 return {
static_cast<T*
>(av_mallocz(size)), av_free};
175 std::unique_ptr<T, void(*)(
void*)>
memdup(
const void *p,
size_t size)
177 return {
static_cast<T*
>(av_memdup(p, size)), av_free};
186 AVFilterInOut * operator()(AVFilterInOut * x)
const
210 template<
typename T,
typename V = T>
279 template<
typename Proc>
284 template<
typename Proc>
286 : m_proc(
std::forward<Proc>(proc))
296 std::function<void()> m_proc;
311 if (this->value ==
value)
335 template<
typename T,
typename L,
typename C>
336 T
guessValue(
const T& value,
const L * list, C endListComparator)
342 std::deque<T> values;
343 for (
const L * ptr = list; !endListComparator(*ptr); ++ptr)
350 std::sort(values.begin(), values.end());
354 int end = values.size() - 1;
355 while ((end - begin) > 1)
357 int mid = begin + (end - begin) / 2;
359 if (value <= values[mid])
370 if (value <= values[begin] || (value - values[begin]) < (values[end] - value))
372 return values[begin];
379 template<
typename T,
typename Container>
382 if (!array || nelements == 0)
384 std::copy_n(array, array + nelements, std::back_inserter(container));
387 template<
typename T,
typename Container,
typename Callable>
388 void array_to_container(
const T* array, std::size_t nelements, Container &container, Callable convert)
390 if (!array || nelements == 0)
394 for (
auto i = 0u; i < nelements; ++i) {
395 container.push_back(convert(array[i]));
399 template<
typename T,
typename Container,
typename Compare>
405 while (!isEnd(value = *array++))
406 container.push_back(value);
409 template<
typename T,
typename Container,
typename Compare,
typename Callable>
415 while (!isEnd(value = *array++))
416 container.push_back(convert(value));
bool operator()(struct SwsContext *&swsContext)
Definition: avutils.cpp:203
string error2string(int error)
C++ verstion of the av_err2str()
Definition: avutils.cpp:195
void operator()(void *)
Definition: avutils.h:130
std::unique_ptr< T, void(*)(void *)> malloc(size_t size)
Definition: avutils.h:163
EqualComparator(const T &value)
Definition: avutils.h:305
bool operator()(T *ptr)
Definition: avutils.h:156
void set_logging_level(int32_t level)
This method can be used to turn up or down FFmpeg's logging level.
Definition: avutils.cpp:19
Definition: avutils.h:128
std::unique_ptr< T, void(*)(void *)> memdup(const void *p, size_t size)
Definition: avutils.h:175
constexpr auto TimeBaseQ
Definition: avutils.h:56
constexpr auto NoPts
Definition: avutils.h:54
Definition: avutils.h:153
The ScopeOutAction class - guard-type class that allows points callback that will be called at the sc...
Definition: avutils.h:276
ScopedValue(T &var, const V &inValue, const V &outValue)
Ctor.
Definition: avutils.h:231
Definition: avutils.h:303
const T & value
Definition: avutils.h:317
ScopeOutAction(const Proc &proc)
Definition: avutils.h:280
Definition: avutils.h:139
std::unique_ptr< T, void(*)(void *)> mallocz(size_t size)
Definition: avutils.h:169
void operator=(const noncopyable &)=delete
void array_to_container(const T *array, std::size_t nelements, Container &container)
Definition: avutils.h:380
constexpr auto TimeBase
Definition: avutils.h:55
R lexical_cast(const T &v)
Definition: avutils.h:60
Definition: audioresampler.cpp:8
Definition: averror.h:228
void dumpBinaryBuffer(uint8_t *buffer, int buffer_size, int width)
dump_binary_buffer Dump binary buffer to std out in HEX view
Definition: avutils.cpp:70
bool operator()(const T &value) const
Definition: avutils.h:309
Functor to take next element in list/array.
Definition: avutils.h:211
~ScopedValue()
Definition: avutils.h:238
T guessValue(const T &value, const L *list, C endListComparator)
Select more approptiate value from given value list.
Definition: avutils.h:336
~ScopeOutAction()
Definition: avutils.h:289
ScopeOutAction(Proc &&proc)
Definition: avutils.h:285
ScopedValue(T &var, const V &outValue)
Ctor.
Definition: avutils.h:219