27 const std::string& explicit_format)
32 const char* fmt = explicit_format.empty() ? nullptr : explicit_format.c_str();
36 int ret = avformat_alloc_output_context2(
40 char errbuf[AV_ERROR_MAX_STRING_SIZE];
41 av_strerror(ret, errbuf,
sizeof(errbuf));
42 m_last_error =
"avformat_alloc_output_context2 failed for \""
43 + resolved +
"\": " + errbuf;
48 ret = avio_open(&
format_context->pb, resolved.c_str(), AVIO_FLAG_WRITE);
50 char errbuf[AV_ERROR_MAX_STRING_SIZE];
51 av_strerror(ret, errbuf,
sizeof(errbuf));
53 + resolved +
"\": " + errbuf;
static void init_ffmpeg()
Initialise FFmpeg logging level once per process.
AVStream * add_stream()
Allocate a new AVStream inside this context.
bool open(const std::string &filepath, const std::string &explicit_format={})
Allocate an output context and open the avio layer for writing.
bool write_header()
Write the container header to the output file.
void close()
Write the container trailer, flush avio, and release all resources.
bool write_packet(AVPacket *pkt)
Submit one encoded packet for interleaved writing.
AVFormatContext * format_context
Owned; freed in close().