MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ open()

bool MayaFlux::IO::FFmpegMuxContext::open ( const std::string &  filepath,
const std::string &  explicit_format = {} 
)

Allocate an output context and open the avio layer for writing.

Format is inferred from the filepath extension via avformat_alloc_output_context2. Pass explicit_format to override (e.g. "matroska" to force MKV regardless of extension).

Does NOT write any data to disk. Call write_header() after all stream contexts have been opened on this mux context.

Parameters
filepathOutput file path. Extension determines container.
explicit_formatFFmpeg short format name override; empty = infer.
Returns
True on success; false sets the internal error string.

Definition at line 26 of file FFmpegMuxContext.cpp.

28{
29 close();
31
32 const char* fmt = explicit_format.empty() ? nullptr : explicit_format.c_str();
33
34 const auto resolved = resolve_write_path(filepath);
35
36 int ret = avformat_alloc_output_context2(
37 &format_context, nullptr, fmt, resolved.c_str());
38
39 if (ret < 0 || !format_context) {
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;
44 return false;
45 }
46
47 if (!(format_context->oformat->flags & AVFMT_NOFILE)) {
48 ret = avio_open(&format_context->pb, resolved.c_str(), AVIO_FLAG_WRITE);
49 if (ret < 0) {
50 char errbuf[AV_ERROR_MAX_STRING_SIZE];
51 av_strerror(ret, errbuf, sizeof(errbuf));
52 m_last_error = "avio_open failed for \""
53 + resolved + "\": " + errbuf;
54 avformat_free_context(format_context);
55 format_context = nullptr;
56 return false;
57 }
58 }
59
60 return true;
61}
static void init_ffmpeg()
Initialise FFmpeg logging level once per process.
void close()
Write the container trailer, flush avio, and release all resources.
AVFormatContext * format_context
Owned; freed in close().
std::string resolve_write_path(const std::string &filepath)
Anchor a relative output path to Config::SOURCE_DIR.

References close(), format_context, MayaFlux::IO::FFmpegDemuxContext::init_ffmpeg(), m_last_error, and MayaFlux::IO::resolve_write_path().

Referenced by MayaFlux::IO::SoundFileWriter::worker_loop(), and MayaFlux::IO::VideoFileWriter::worker_loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: