20#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-Wconversion"
22#pragma GCC diagnostic ignored "-Wsign-conversion"
23#include <libavformat/avformat.h>
24#include <libavformat/avio.h>
25#include <libavutil/mem.h>
26#pragma GCC diagnostic pop
46 m_context(context.m_context),
47 m_type(context.m_type),
48 m_custom_io(context.m_custom_io)
50 context.m_context =
nullptr;
51 context.m_custom_io =
false;
60 m_context = context.m_context;
61 m_type = context.m_type;
62 m_custom_io = context.m_custom_io;
64 context.m_context =
nullptr;
65 context.m_custom_io =
false;
78 return (
m_context !=
nullptr) ? 0 : AVERROR(ENOMEM);
87 int ret = avformat_alloc_output_context2(&
m_context,
nullptr, format_name, filename);
93 return (
m_context !=
nullptr) ? 0 : AVERROR(ENOMEM);
160FFmpeg_FormatContext::operator AVFormatContext*()
165FFmpeg_FormatContext::operator
const AVFormatContext*()
const
184#if (LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 80, 0))
RAII wrapper for AVFormatContext.
~FFmpeg_FormatContext()
Release the owned format context, if any.
void set_type(TYPE type)
Set the context direction used for later cleanup.
AVFormatContext * m_context
Pointer to underlying AVFormatContext.
bool m_custom_io
true if pb was allocated with avio_alloc_context().
TYPE m_type
Input or output context.
FFmpeg_FormatContext(TYPE type=TYPE::INPUT)
Construct an empty format-context wrapper.
TYPE
Managed AVFormatContext direction.
@ OUTPUT
Output context freed with avformat_free_context().
@ INPUT
Input context closed with avformat_close_input().
int alloc_input_context()
Allocate a new input format context.
bool reset()
Free the owned format context and reset the wrapper to empty.
AVFormatContext * get()
Get the owned FFmpeg format context pointer.
AVFormatContext ** address()
Get a writable pointer-to-pointer for FFmpeg APIs.
AVFormatContext * operator->()
Access members of the underlying mutable format context.
AVFormatContext * release()
Release ownership without freeing the format context.
void set_custom_io(bool custom_io=true)
Mark whether the context owns a custom AVIOContext.
void free_custom_io()
Free the custom AVIOContext attached to the format context.
int alloc_output_context(const char *format_name, const char *filename=nullptr)
Allocate a new output format context.
bool empty() const
Check whether the wrapper currently owns a format context.
FFmpeg AVFormatContext RAII wrapper.